1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-06-27 16:36:03 +00:00

Support skybox textures with alpha channel

This commit is contained in:
MirceaKitsune 2025-04-22 23:37:37 +03:00
parent 0cf1c47f6c
commit 6f17876e86
6 changed files with 22 additions and 19 deletions

View file

@ -8790,8 +8790,8 @@ child will follow movement and rotation of that bone.
Some top and bottom textures expect to be aligned with the north face and will need to be rotated Some top and bottom textures expect to be aligned with the north face and will need to be rotated
by -90 and 90 degrees, respectively, to fit the eastward orientation. by -90 and 90 degrees, respectively, to fit the eastward orientation.
* `clouds`: Boolean for whether clouds appear. (default: `true`) * `clouds`: Boolean for whether clouds appear. (default: `true`)
* `sky_color`: A table used in `"regular"` type only, containing the * `sky_color`: A table used in `"regular"` and `"skybox"` types only. If used with the later,
following values (alpha is ignored): the `textures` should have an alpha channel. Contains the following values (alpha is ignored):
* `day_sky`: ColorSpec, for the top half of the sky during the day. * `day_sky`: ColorSpec, for the top half of the sky during the day.
(default: `#61b5f5`) (default: `#61b5f5`)
* `day_horizon`: ColorSpec, for the bottom half of the sky during the day. * `day_horizon`: ColorSpec, for the bottom half of the sky during the day.

View file

@ -2866,11 +2866,10 @@ void Game::handleClientEvent_SetSky(ClientEvent *event, CameraOrientation *cam)
); );
} else if (event->set_sky->type == "skybox" && } else if (event->set_sky->type == "skybox" &&
event->set_sky->textures.size() == 6) { event->set_sky->textures.size() == 6) {
// Disable the dyanmic mesh skybox: // Shows the mesh skybox
sky->setVisible(false); sky->setVisible(true);
// Set fog colors: // Update mesh based skybox colours if applicable.
sky->setFallbackBgColor(event->set_sky->bgcolor); sky->setSkyColors(event->set_sky->sky_color);
// Set sunrise and sunset fog tinting:
sky->setHorizonTint( sky->setHorizonTint(
event->set_sky->fog_sun_tint, event->set_sky->fog_sun_tint,
event->set_sky->fog_moon_tint, event->set_sky->fog_moon_tint,

View file

@ -158,6 +158,7 @@ void Sky::render()
const f32 t = 1.0f; const f32 t = 1.0f;
const f32 o = 0.0f; const f32 o = 0.0f;
const bool has_tex = m_sky_params.textures.size() == 6;
static const u16 indices[6] = {0, 1, 2, 0, 2, 3}; static const u16 indices[6] = {0, 1, 2, 0, 2, 3};
video::S3DVertex vertices[4]; video::S3DVertex vertices[4];
@ -171,7 +172,7 @@ void Sky::render()
return; return;
// Draw the six sided skybox, // Draw the six sided skybox,
if (m_sky_params.textures.size() == 6) { if (has_tex) {
for (u32 j = 5; j < 11; j++) { for (u32 j = 5; j < 11; j++) {
video::SColor c(255, 255, 255, 255); video::SColor c(255, 255, 255, 255);
driver->setMaterial(m_materials[j]); driver->setMaterial(m_materials[j]);
@ -205,7 +206,8 @@ void Sky::render()
} }
// Draw far cloudy fog thing blended with skycolor // Draw far cloudy fog thing blended with skycolor
if (m_visible) { // Disabled when using a textured skybox to prevent clipping
if (m_visible && !has_tex) {
driver->setMaterial(m_materials[1]); driver->setMaterial(m_materials[1]);
for (u32 j = 0; j < 4; j++) { for (u32 j = 0; j < 4; j++) {
vertices[0] = video::S3DVertex(-1, -0.02, -1, 0, 0, 1, m_bgcolor, t, t); vertices[0] = video::S3DVertex(-1, -0.02, -1, 0, 0, 1, m_bgcolor, t, t);
@ -268,9 +270,9 @@ void Sky::render()
if (m_moon_params.visible) if (m_moon_params.visible)
draw_moon(driver, mooncolor, mooncolor2, wicked_time_of_day); draw_moon(driver, mooncolor, mooncolor2, wicked_time_of_day);
// Draw far cloudy fog thing below all horizons in front of sun, moon // Draw far cloudy fog thing below all horizons in front of sun, moon and stars.
// and stars. // Disabled when using a textured skybox to prevent clipping
if (m_visible) { if (m_visible && !has_tex) {
driver->setMaterial(m_materials[1]); driver->setMaterial(m_materials[1]);
for (u32 j = 0; j < 4; j++) { for (u32 j = 0; j < 4; j++) {
@ -881,7 +883,7 @@ void Sky::addTextureToSkybox(const std::string &texture, int material_id,
video::ITexture *result = tsrc->getTextureForMesh(texture); video::ITexture *result = tsrc->getTextureForMesh(texture);
m_materials[material_id+5] = baseMaterial(); m_materials[material_id+5] = baseMaterial();
m_materials[material_id+5].setTexture(0, result); m_materials[material_id+5].setTexture(0, result);
m_materials[material_id+5].MaterialType = video::EMT_SOLID; m_materials[material_id+5].MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL;
} }
float getWickedTimeOfDay(float time_of_day) float getWickedTimeOfDay(float time_of_day)

View file

@ -1302,8 +1302,8 @@ void Client::handleCommand_HudSetSky(NetworkPacket* pkt)
MoonParams moon = SkyboxDefaults::getMoonDefaults(); MoonParams moon = SkyboxDefaults::getMoonDefaults();
StarParams stars = SkyboxDefaults::getStarDefaults(); StarParams stars = SkyboxDefaults::getStarDefaults();
// Fix for "regular" skies, as color isn't kept: // Fix for "regular" and "skybox" skies, as color isn't kept:
if (skybox.type == "regular") { if (skybox.type == "regular" || skybox.type == "skybox") {
skybox.sky_color = SkyboxDefaults::getSkyColorDefaults(); skybox.sky_color = SkyboxDefaults::getSkyColorDefaults();
skybox.fog_tint_type = "default"; skybox.fog_tint_type = "default";
skybox.fog_moon_tint = video::SColor(255, 255, 255, 255); skybox.fog_moon_tint = video::SColor(255, 255, 255, 255);
@ -1351,7 +1351,8 @@ void Client::handleCommand_HudSetSky(NetworkPacket* pkt)
*pkt >> texture; *pkt >> texture;
skybox.textures.emplace_back(texture); skybox.textures.emplace_back(texture);
} }
} else if (skybox.type == "regular") { }
if (skybox.type == "regular" || skybox.type == "skybox") {
auto &c = skybox.sky_color; auto &c = skybox.sky_color;
*pkt >> c.day_sky >> c.day_horizon >> c.dawn_sky >> c.dawn_horizon *pkt >> c.day_sky >> c.day_horizon >> c.dawn_sky >> c.dawn_horizon
>> c.night_sky >> c.night_horizon >> c.indoors; >> c.night_sky >> c.night_horizon >> c.indoors;

View file

@ -2140,7 +2140,7 @@ int ObjectRef::l_set_sky(lua_State *L)
// Preserve old behavior of the sun, moon and stars // Preserve old behavior of the sun, moon and stars
// when using the old set_sky call. // when using the old set_sky call.
if (sky_params.type == "regular") { if (sky_params.type == "regular" || sky_params.type == "skybox") {
sun_params.visible = true; sun_params.visible = true;
sun_params.sunrise_visible = true; sun_params.sunrise_visible = true;
moon_params.visible = true; moon_params.visible = true;
@ -2181,7 +2181,7 @@ int ObjectRef::l_set_sky(lua_State *L)
static void push_sky_color(lua_State *L, const SkyboxParams &params) static void push_sky_color(lua_State *L, const SkyboxParams &params)
{ {
lua_newtable(L); lua_newtable(L);
if (params.type == "regular") { if (params.type == "regular" || params.type == "skybox") {
push_ARGB8(L, params.sky_color.day_sky); push_ARGB8(L, params.sky_color.day_sky);
lua_setfield(L, -2, "day_sky"); lua_setfield(L, -2, "day_sky");
push_ARGB8(L, params.sky_color.day_horizon); push_ARGB8(L, params.sky_color.day_horizon);

View file

@ -1867,7 +1867,8 @@ void Server::SendSetSky(session_t peer_id, const SkyboxParams &params)
pkt << (u16) params.textures.size(); pkt << (u16) params.textures.size();
for (const std::string &texture : params.textures) for (const std::string &texture : params.textures)
pkt << texture; pkt << texture;
} else if (params.type == "regular") { }
if (params.type == "regular" || params.type == "skybox") {
auto &c = params.sky_color; auto &c = params.sky_color;
pkt << c.day_sky << c.day_horizon << c.dawn_sky << c.dawn_horizon pkt << c.day_sky << c.day_horizon << c.dawn_sky << c.dawn_horizon
<< c.night_sky << c.night_horizon << c.indoors; << c.night_sky << c.night_horizon << c.indoors;