[Bf-blender-cvs] [ace38bd] viewport_experiments: Fix SSAO not being constant in camera view.
Antony Riakiotakis
noreply at git.blender.org
Fri Nov 14 19:55:39 CET 2014
Commit: ace38bdc82c8d50e929a6e4bf0288832d1b208f8
Author: Antony Riakiotakis
Date: Fri Nov 14 19:55:30 2014 +0100
Branches: viewport_experiments
https://developer.blender.org/rBace38bdc82c8d50e929a6e4bf0288832d1b208f8
Fix SSAO not being constant in camera view.
===================================================================
M source/blender/gpu/shaders/gpu_shader_fx_ssao_frag.glsl
===================================================================
diff --git a/source/blender/gpu/shaders/gpu_shader_fx_ssao_frag.glsl b/source/blender/gpu/shaders/gpu_shader_fx_ssao_frag.glsl
index 08f1afe..f4ae813 100644
--- a/source/blender/gpu/shaders/gpu_shader_fx_ssao_frag.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_fx_ssao_frag.glsl
@@ -34,13 +34,17 @@ float calculate_ssao_factor(float depth)
vec3 normal = calculate_view_space_normal(position);
// find the offset in screen space by multiplying a point in camera space at the depth of the point by the projection matrix.
- vec4 offset = gl_ProjectionMatrix * vec4(ssao_params.x, ssao_params.x, position.z, 1.0);
+ vec2 offset;
+ float homcoord = gl_ProjectionMatrix[2][3] * position.z + gl_ProjectionMatrix[3][3];
+ offset.x = gl_ProjectionMatrix[0][0] * ssao_params.x / homcoord;
+ offset.y = gl_ProjectionMatrix[1][1] * ssao_params.x / homcoord;
+ /* convert from -1.0...1.0 range to 0.0..1.0 for easy use with texture coordinates */
+ offset *= 0.5;
+
float factor = 0.0;
int x, y;
int radial_samples = int(ssao_sample_params.y);
int azimuth_samples = int(ssao_sample_params.x);
- /* convert from -1.0...1.0 range to 0.0..1.0 for easy use with texture coordinates */
- offset = (offset / offset.w) * 0.5;
for (x = 0; x < azimuth_samples; x++) {
vec2 dir_sample = sample_directions[x];
@@ -49,7 +53,7 @@ float calculate_ssao_factor(float depth)
vec2 dir_jittered = vec2(dot(dir_sample, rotX), dot(dir_sample, rotY));
for (y = 0; y < radial_samples; y++) {
- vec2 uvcoords = uvcoordsvar.xy + dir_jittered * offset.xy * float(y + 1) / ssao_sample_params.y;
+ vec2 uvcoords = uvcoordsvar.xy + dir_jittered * offset * float(y + 1) / ssao_sample_params.y;
float depth_new = texture2D(depthbuffer, uvcoords).r;
if (depth_new != 1.0) {
More information about the Bf-blender-cvs
mailing list