]> git.tdb.fi Git - libs/gl.git/commitdiff
Fix use of camera matrices in the ambient occlusion effect
authorMikko Rasa <tdb@tdb.fi>
Sat, 8 May 2021 15:10:53 +0000 (18:10 +0300)
committerMikko Rasa <tdb@tdb.fi>
Sun, 9 May 2021 07:53:57 +0000 (10:53 +0300)
builtin_data/_ambientocclusion.glsl
source/effects/ambientocclusion.cpp

index dca636bb646092da6cd0a823f5fe3783186c851f..81aac182acb4683412d429d7d33b58938bdd1722 100644 (file)
@@ -1,6 +1,12 @@
 const int max_samples = 32;
 
-uniform mat4 projection_matrix;
+uniform CameraTransform
+{
+       mat4 eye_world_matrix;
+       mat4 world_eye_matrix;
+       mat4 clip_eye_matrix;
+       mat4 eye_clip_matrix;
+};
 
 uniform sampler2D source;
 uniform sampler2D depth;
@@ -8,7 +14,6 @@ uniform sampler2D occlusion;
 uniform sampler2D rotate;
 uniform AmbientOcclusionParams
 {
-       mat4 inverse_projection;
        float darkness;
        vec3 sample_points[max_samples];
        int n_samples;
@@ -21,12 +26,12 @@ vec3 project(vec3 position)
 {
        if(position.z>=0.0)
                return vec3(0.0, 0.0, -1.0);
-       vec4 pp = projection_matrix*vec4(position, 1.0);
+       vec4 pp = clip_eye_matrix*vec4(position, 1.0);
        return pp.xyz/pp.w;
 }
 
 vec3 unproject(vec3 position)
 {
-       vec4 upp = inverse_projection*vec4(position, 1.0);
+       vec4 upp = eye_clip_matrix*vec4(position, 1.0);
        return upp.xyz/upp.w;
 }
index d23469edf8aeeac20a0a62cf285e47dde551f019..a10fa838e7b3b1d0f2da41c1f4f3b029a97df92e 100644 (file)
@@ -35,8 +35,6 @@ AmbientOcclusion::AmbientOcclusion(unsigned w, unsigned h, float):
        }
        rotate_lookup.image(0, data);
 
-       shdata.uniform("inverse_projection", Matrix());
-
        set_n_samples(16);
        set_occlusion_radius(0.5f);
        set_darkness(1.0f);
@@ -84,9 +82,6 @@ void AmbientOcclusion::set_edge_depth_threshold(float edt)
 
 void AmbientOcclusion::render(Renderer &renderer, const Texture2D &color, const Texture2D &depth)
 {
-       if(renderer.get_camera())
-               shdata.uniform("inverse_projection", invert(renderer.get_camera()->get_projection_matrix()));
-
        Renderer::Push push(renderer);
        renderer.set_texture("source", &color, &nearest_sampler);
        renderer.set_texture("depth", &depth, &nearest_sampler);