Skip to content

Commit

Permalink
fix missing cloud fog
Browse files Browse the repository at this point in the history
  • Loading branch information
sfan5 committed Feb 21, 2024
1 parent 968238b commit 49a384f
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 4 deletions.
13 changes: 12 additions & 1 deletion client/shaders/cloud_shader/opengl_fragment.glsl
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
uniform vec4 fogColor;
uniform float fogDistance;
uniform float fogShadingParameter;
varying vec3 eyeVec;

varying lowp vec4 varColor;

void main(void)
{
gl_FragColor = varColor;
vec4 col = varColor;

float clarity = clamp(fogShadingParameter
- fogShadingParameter * length(eyeVec) / fogDistance, 0.0, 1.0);
col.rgb = mix(fogColor.rgb, col.rgb, clarity);

gl_FragColor = col;
}
5 changes: 4 additions & 1 deletion client/shaders/cloud_shader/opengl_vertex.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ uniform vec4 emissiveColor;

varying lowp vec4 varColor;

varying vec3 eyeVec;

void main(void)
{
gl_Position = mWorldViewProj * inVertexPosition;
Expand All @@ -13,6 +15,7 @@ void main(void)
#endif

color *= emissiveColor;

varColor = color;

eyeVec = -(mWorldView * inVertexPosition).xyz;
}
1 change: 0 additions & 1 deletion src/client/clouds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ void Clouds::updateMesh()
);

// Only update mesh if it has moved enough, this saves lots of GPU buffer uploads.
// In practice the fog hides the delay in updating.
constexpr float max_d = 5 * BS;

if (!m_mesh_valid) {
Expand Down
3 changes: 3 additions & 0 deletions src/gui/guiEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,9 @@ GUIEngine::~GUIEngine()
/******************************************************************************/
void GUIEngine::cloudInit()
{
m_shader_source->addShaderConstantSetterFactory(
new FogShaderConstantSetterFactory());

m_cloud.clouds = make_irr<Clouds>(m_smgr, m_shader_source.get(), -1, rand());
m_cloud.clouds->setHeight(100.0f);
m_cloud.clouds->update(v3f(0, 0, 0), video::SColor(255,240,240,255));
Expand Down
3 changes: 2 additions & 1 deletion src/gui/guiEngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ struct image_definition {
class GUIEngine;
class RenderingEngine;
class MainMenuScripting;
class IWritableShaderSource;
struct MainMenuData;

/******************************************************************************/
Expand Down Expand Up @@ -188,7 +189,7 @@ class GUIEngine {
/** texture source */
std::unique_ptr<ISimpleTextureSource> m_texture_source;
/** shader source */
std::unique_ptr<IShaderSource> m_shader_source;
std::unique_ptr<IWritableShaderSource> m_shader_source;
/** sound manager */
std::unique_ptr<ISoundManager> m_sound_manager;

Expand Down

0 comments on commit 49a384f

Please sign in to comment.