mirror of
https://github.com/luanti-org/luanti.git
synced 2025-10-05 19:31:04 +00:00
Allow fog color to be overriden properly (#14296)
This commit is contained in:
parent
a29d3cf074
commit
9e3a11534f
11 changed files with 96 additions and 84 deletions
|
@ -165,9 +165,11 @@ void Clouds::render()
|
|||
driver->getFog(fog_color, fog_type, fog_start, fog_end, fog_density,
|
||||
fog_pixelfog, fog_rangefog);
|
||||
|
||||
// Set our own fog
|
||||
driver->setFog(fog_color, fog_type, cloud_full_radius * 0.5,
|
||||
// Set our own fog, unless it was already disabled
|
||||
if (fog_start < FOG_RANGE_ALL) {
|
||||
driver->setFog(fog_color, fog_type, cloud_full_radius * 0.5,
|
||||
cloud_full_radius*1.2, fog_density, fog_pixelfog, fog_rangefog);
|
||||
}
|
||||
|
||||
// Read noise
|
||||
|
||||
|
|
|
@ -374,7 +374,7 @@ class GameGlobalShaderConstantSetter : public IShaderConstantSetter
|
|||
bool *m_force_fog_off;
|
||||
f32 *m_fog_range;
|
||||
bool m_fog_enabled;
|
||||
CachedPixelShaderSetting<float, 4> m_sky_bg_color{"skyBgColor"};
|
||||
CachedPixelShaderSetting<float, 4> m_fog_color{"fogColor"};
|
||||
CachedPixelShaderSetting<float> m_fog_distance{"fogDistance"};
|
||||
CachedPixelShaderSetting<float>
|
||||
m_fog_shading_parameter{"fogShadingParameter"};
|
||||
|
@ -475,20 +475,13 @@ public:
|
|||
|
||||
void onSetConstants(video::IMaterialRendererServices *services) override
|
||||
{
|
||||
// Background color
|
||||
video::SColor bgcolor = m_sky->getBgColor();
|
||||
video::SColorf bgcolorf(bgcolor);
|
||||
float bgcolorfa[4] = {
|
||||
bgcolorf.r,
|
||||
bgcolorf.g,
|
||||
bgcolorf.b,
|
||||
bgcolorf.a,
|
||||
video::SColorf fogcolorf(m_sky->getFogColor());
|
||||
float fogcolorfa[4] = {
|
||||
fogcolorf.r, fogcolorf.g, fogcolorf.b, fogcolorf.a,
|
||||
};
|
||||
m_sky_bg_color.set(bgcolorfa, services);
|
||||
m_fog_color.set(fogcolorfa, services);
|
||||
|
||||
// Fog distance
|
||||
float fog_distance = 10000 * BS;
|
||||
|
||||
if (m_fog_enabled && !*m_force_fog_off)
|
||||
fog_distance = *m_fog_range;
|
||||
|
||||
|
@ -983,7 +976,6 @@ private:
|
|||
bool *kill;
|
||||
std::string *error_message;
|
||||
bool *reconnect_requested;
|
||||
scene::ISceneNode *skybox;
|
||||
PausedNodesList paused_animated_nodes;
|
||||
|
||||
bool simple_singleplayer_mode;
|
||||
|
@ -1522,7 +1514,6 @@ bool Game::createClient(const GameStartData &start_data)
|
|||
*/
|
||||
sky = new Sky(-1, m_rendering_engine, texture_src, shader_src);
|
||||
scsf->setSky(sky);
|
||||
skybox = NULL; // This is used/set later on in the main run loop
|
||||
|
||||
/* Pre-calculated values
|
||||
*/
|
||||
|
@ -3045,10 +3036,6 @@ void Game::handleClientEvent_SetSky(ClientEvent *event, CameraOrientation *cam)
|
|||
// Whether clouds are visible in front of a custom skybox.
|
||||
sky->setCloudsEnabled(event->set_sky->clouds);
|
||||
|
||||
if (skybox) {
|
||||
skybox->remove();
|
||||
skybox = NULL;
|
||||
}
|
||||
// Clear the old textures out in case we switch rendering type.
|
||||
sky->clearSkyboxTextures();
|
||||
// Handle according to type
|
||||
|
@ -3108,6 +3095,8 @@ void Game::handleClientEvent_SetSky(ClientEvent *event, CameraOrientation *cam)
|
|||
else
|
||||
sky->setFogStart(rangelim(g_settings->getFloat("fog_start"), 0.0f, 0.99f));
|
||||
|
||||
sky->setFogColor(event->set_sky->fog_color);
|
||||
|
||||
delete event->set_sky;
|
||||
}
|
||||
|
||||
|
@ -4055,7 +4044,7 @@ void Game::updateFrame(ProfilerGraph *graph, RunStats *stats, f32 dtime,
|
|||
draw_control->wanted_range = MYMIN(draw_control->wanted_range, sky->getFogDistance());
|
||||
}
|
||||
if (draw_control->range_all && sky->getFogDistance() < 0) {
|
||||
runData.fog_range = 100000 * BS;
|
||||
runData.fog_range = FOG_RANGE_ALL;
|
||||
} else {
|
||||
runData.fog_range = draw_control->wanted_range * BS;
|
||||
}
|
||||
|
@ -4297,7 +4286,7 @@ void Game::updateShadows()
|
|||
|
||||
void Game::drawScene(ProfilerGraph *graph, RunStats *stats)
|
||||
{
|
||||
const video::SColor bg_color = this->sky->getBgColor();
|
||||
const video::SColor fog_color = this->sky->getFogColor();
|
||||
const video::SColor sky_color = this->sky->getSkyColor();
|
||||
|
||||
/*
|
||||
|
@ -4305,21 +4294,21 @@ void Game::drawScene(ProfilerGraph *graph, RunStats *stats)
|
|||
*/
|
||||
if (this->m_cache_enable_fog) {
|
||||
this->driver->setFog(
|
||||
bg_color,
|
||||
fog_color,
|
||||
video::EFT_FOG_LINEAR,
|
||||
this->runData.fog_range * this->sky->getFogStart(),
|
||||
this->runData.fog_range * 1.0f,
|
||||
0.01f,
|
||||
0.f, // unused
|
||||
false, // pixel fog
|
||||
true // range fog
|
||||
);
|
||||
} else {
|
||||
this->driver->setFog(
|
||||
bg_color,
|
||||
fog_color,
|
||||
video::EFT_FOG_LINEAR,
|
||||
100000 * BS,
|
||||
110000 * BS,
|
||||
0.01f,
|
||||
FOG_RANGE_ALL,
|
||||
FOG_RANGE_ALL + 100 * BS,
|
||||
0.f, // unused
|
||||
false, // pixel fog
|
||||
false // range fog
|
||||
);
|
||||
|
|
|
@ -43,6 +43,9 @@ class Minimap;
|
|||
|
||||
class RenderingCore;
|
||||
|
||||
// Instead of a mechanism to disable fog we just set it to be really far away
|
||||
#define FOG_RANGE_ALL (100000 * BS)
|
||||
|
||||
class RenderingEngine
|
||||
{
|
||||
public:
|
||||
|
|
|
@ -54,12 +54,12 @@ public:
|
|||
|
||||
float getBrightness() { return m_brightness; }
|
||||
|
||||
const video::SColor &getBgColor() const
|
||||
video::SColor getBgColor() const
|
||||
{
|
||||
return m_visible ? m_bgcolor : m_fallback_bg_color;
|
||||
}
|
||||
|
||||
const video::SColor &getSkyColor() const
|
||||
video::SColor getSkyColor() const
|
||||
{
|
||||
return m_visible ? m_skycolor : m_fallback_bg_color;
|
||||
}
|
||||
|
@ -90,6 +90,7 @@ public:
|
|||
const video::SColorf &getCloudColor() const { return m_cloudcolor_f; }
|
||||
|
||||
void setVisible(bool visible) { m_visible = visible; }
|
||||
|
||||
// Set only from set_sky API
|
||||
void setCloudsEnabled(bool clouds_enabled) { m_clouds_enabled = clouds_enabled; }
|
||||
void setFallbackBgColor(video::SColor fallback_bg_color)
|
||||
|
@ -111,17 +112,23 @@ public:
|
|||
const std::string &use_sun_tint);
|
||||
void setInClouds(bool clouds) { m_in_clouds = clouds; }
|
||||
void clearSkyboxTextures() { m_sky_params.textures.clear(); }
|
||||
void addTextureToSkybox(const std::string &texture, int material_id,
|
||||
void addTextureToSkybox(const std::string &texture, int material_id,
|
||||
ITextureSource *tsrc);
|
||||
const video::SColorf &getCurrentStarColor() const { return m_star_color; }
|
||||
|
||||
// Note: the Sky class doesn't use these values. It just stores them.
|
||||
void setFogDistance(s16 fog_distance) { m_sky_params.fog_distance = fog_distance; }
|
||||
s16 getFogDistance() const { return m_sky_params.fog_distance; }
|
||||
|
||||
void setFogStart(float fog_start) { m_sky_params.fog_start = fog_start; }
|
||||
float getFogStart() const { return m_sky_params.fog_start; }
|
||||
|
||||
void setVolumetricLightStrength(float volumetric_light_strength) { m_sky_params.volumetric_light_strength = volumetric_light_strength; }
|
||||
float getVolumetricLightStrength() const { return m_sky_params.volumetric_light_strength; }
|
||||
void setFogColor(video::SColor v) { m_sky_params.fog_color = v; }
|
||||
video::SColor getFogColor() const {
|
||||
if (m_sky_params.fog_color.getAlpha() > 0)
|
||||
return m_sky_params.fog_color;
|
||||
return getBgColor();
|
||||
}
|
||||
|
||||
private:
|
||||
aabb3f m_box;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue