From e6bb00e2d6b817b81a555b6cbebe3ba4ec28cf80 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Sat, 8 May 2021 18:10:53 +0300 Subject: [PATCH] Fix use of camera matrices in the ambient occlusion effect --- builtin_data/_ambientocclusion.glsl | 13 +++++++++---- source/effects/ambientocclusion.cpp | 5 ----- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/builtin_data/_ambientocclusion.glsl b/builtin_data/_ambientocclusion.glsl index dca636bb..81aac182 100644 --- a/builtin_data/_ambientocclusion.glsl +++ b/builtin_data/_ambientocclusion.glsl @@ -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; } diff --git a/source/effects/ambientocclusion.cpp b/source/effects/ambientocclusion.cpp index d23469ed..a10fa838 100644 --- a/source/effects/ambientocclusion.cpp +++ b/source/effects/ambientocclusion.cpp @@ -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); -- 2.45.2