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
by -90 and 90 degrees, respectively, to fit the eastward orientation.
* `clouds`: Boolean for whether clouds appear. (default: `true`)
* `sky_color`: A table used in `"regular"` type only, containing the
following values (alpha is ignored):
* `sky_color`: A table used in `"regular"` and `"skybox"` types only. If used with the later,
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.
(default: `#61b5f5`)
* `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" &&
event->set_sky->textures.size() == 6) {
// Disable the dyanmic mesh skybox:
sky->setVisible(false);
// Set fog colors:
sky->setFallbackBgColor(event->set_sky->bgcolor);
// Set sunrise and sunset fog tinting:
// Shows the mesh skybox
sky->setVisible(true);
// Update mesh based skybox colours if applicable.
sky->setSkyColors(event->set_sky->sky_color);
sky->setHorizonTint(
event->set_sky->fog_sun_tint,
event->set_sky->fog_moon_tint,

View file

@ -158,6 +158,7 @@ void Sky::render()
const f32 t = 1.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};
video::S3DVertex vertices[4];
@ -171,7 +172,7 @@ void Sky::render()
return;
// Draw the six sided skybox,
if (m_sky_params.textures.size() == 6) {
if (has_tex) {
for (u32 j = 5; j < 11; j++) {
video::SColor c(255, 255, 255, 255);
driver->setMaterial(m_materials[j]);
@ -205,7 +206,8 @@ void Sky::render()
}
// 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]);
for (u32 j = 0; j < 4; j++) {
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)
draw_moon(driver, mooncolor, mooncolor2, wicked_time_of_day);
// Draw far cloudy fog thing below all horizons in front of sun, moon
// and stars.
if (m_visible) {
// Draw far cloudy fog thing below all horizons in front of sun, moon and stars.
// Disabled when using a textured skybox to prevent clipping
if (m_visible && !has_tex) {
driver->setMaterial(m_materials[1]);
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);
m_materials[material_id+5] = baseMaterial();
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)

View file

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