]> git.tdb.fi Git - libs/gl.git/blobdiff - source/effects/shadowmap.cpp
Apply shadow depth bias in a different way
[libs/gl.git] / source / effects / shadowmap.cpp
index 4cc0475d3e6ad79fae9d207755161ffba3826503..465243973f3c87a702b23727c5bdea3a5a3266d5 100644 (file)
@@ -30,6 +30,7 @@ ShadowMap::ShadowMap(unsigned w, unsigned h, Renderable &r, const Lighting *l):
                shdata.uniform(base+".darkness", 1.0f);
                shdata.uniform(base+".matrix_index", 0);
                shdata.uniform(base+".region", Vector4(0.0f, 0.0f, 1.0f, 1.0f));
+               shdata.uniform(base+".bias", 0.0f);
        }
 
        Matrix dummy_matrix;
@@ -160,6 +161,13 @@ void ShadowMap::setup_frame(Renderer &renderer)
        for(const ShadowedLight &l: lights)
                l.shadow_caster->setup_frame(renderer);
 
+       for(const ShadowedLight &l: lights)
+       {
+               string base = format("shadows[%d]", l.index);
+               if(l.type==DIRECTIONAL)
+                       shdata.uniform(base+".bias", depth_bias/l.region.width);
+       }
+
        vector<Matrix> shadow_matrices;
        shadow_matrices.reserve(views.size());
        for(ShadowView &v: views)
@@ -174,7 +182,7 @@ void ShadowMap::setup_frame(Renderer &renderer)
                        v.camera.set_depth_clip(-radius, radius);
                }
 
-               Matrix to_texcoord = Matrix().translate(Vector3(0.5f, 0.5f, 0.5f-depth_bias/light.region.width)).scale(0.5f);
+               Matrix to_texcoord = Matrix().translate(Vector3(0.5f, 0.5f, 0.5f)).scale(0.5f);
                shadow_matrices.push_back(to_texcoord*v.camera.get_projection_matrix()*v.camera.get_view_matrix());
        }