diff options
Diffstat (limited to 'src/client/shader.cpp')
-rw-r--r-- | src/client/shader.cpp | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/src/client/shader.cpp b/src/client/shader.cpp index 58946b90f..355366bd3 100644 --- a/src/client/shader.cpp +++ b/src/client/shader.cpp @@ -225,6 +225,16 @@ class MainShaderConstantSetter : public IShaderConstantSetter { CachedVertexShaderSetting<float, 16> m_world_view_proj; CachedVertexShaderSetting<float, 16> m_world; + + // Shadow-related + CachedPixelShaderSetting<float, 16> m_shadow_view_proj; + CachedPixelShaderSetting<float, 3> m_light_direction; + CachedPixelShaderSetting<float> m_texture_res; + CachedPixelShaderSetting<float> m_shadow_strength; + CachedPixelShaderSetting<float> m_time_of_day; + CachedPixelShaderSetting<float> m_shadowfar; + CachedPixelShaderSetting<s32> m_shadow_texture; + #if ENABLE_GLES // Modelview matrix CachedVertexShaderSetting<float, 16> m_world_view; @@ -243,6 +253,13 @@ public: , m_texture("mTexture") , m_normal("mNormal") #endif + , m_shadow_view_proj("m_ShadowViewProj") + , m_light_direction("v_LightDirection") + , m_texture_res("f_textureresolution") + , m_shadow_strength("f_shadow_strength") + , m_time_of_day("f_timeofday") + , m_shadowfar("f_shadowfar") + , m_shadow_texture("ShadowMapSampler") {} ~MainShaderConstantSetter() = default; @@ -280,6 +297,36 @@ public: }; m_normal.set(m, services); #endif + + // Set uniforms for Shadow shader + if (ShadowRenderer *shadow = RenderingEngine::get_shadow_renderer()) { + const auto &light = shadow->getDirectionalLight(); + + core::matrix4 shadowViewProj = light.getProjectionMatrix(); + shadowViewProj *= light.getViewMatrix(); + m_shadow_view_proj.set(shadowViewProj.pointer(), services); + + float v_LightDirection[3]; + light.getDirection().getAs3Values(v_LightDirection); + m_light_direction.set(v_LightDirection, services); + + float TextureResolution = light.getMapResolution(); + m_texture_res.set(&TextureResolution, services); + + float ShadowStrength = shadow->getShadowStrength(); + m_shadow_strength.set(&ShadowStrength, services); + + float timeOfDay = shadow->getTimeOfDay(); + m_time_of_day.set(&timeOfDay, services); + + float shadowFar = shadow->getMaxShadowFar(); + m_shadowfar.set(&shadowFar, services); + + // I dont like using this hardcoded value. maybe something like + // MAX_TEXTURE - 1 or somthing like that?? + s32 TextureLayerID = 3; + m_shadow_texture.set(&TextureLayerID, services); + } } }; @@ -682,6 +729,23 @@ ShaderInfo ShaderSource::generateShader(const std::string &name, shaders_header << "#define FOG_START " << core::clamp(g_settings->getFloat("fog_start"), 0.0f, 0.99f) << "\n"; + if (g_settings->getBool("enable_dynamic_shadows")) { + shaders_header << "#define ENABLE_DYNAMIC_SHADOWS 1\n"; + if (g_settings->getBool("shadow_map_color")) + shaders_header << "#define COLORED_SHADOWS 1\n"; + + if (g_settings->getBool("shadow_poisson_filter")) + shaders_header << "#define POISSON_FILTER 1\n"; + + s32 shadow_filter = g_settings->getS32("shadow_filters"); + shaders_header << "#define SHADOW_FILTER " << shadow_filter << "\n"; + + float shadow_soft_radius = g_settings->getS32("shadow_soft_radius"); + if (shadow_soft_radius < 1.0f) + shadow_soft_radius = 1.0f; + shaders_header << "#define SOFTSHADOWRADIUS " << shadow_soft_radius << "\n"; + } + std::string common_header = shaders_header.str(); std::string vertex_shader = m_sourcecache.getOrLoad(name, "opengl_vertex.glsl"); |