]> git.tdb.fi Git - libs/gl.git/blobdiff - shaderlib/ambientocclusion.glsl
Guard against sample points behind the camera in ambient occlusion
[libs/gl.git] / shaderlib / ambientocclusion.glsl
index 0ca81a40b6cb21ed5fd8af08ce1852f25e94a46d..89d13357b67404dd5f06c180541d5723f372a34b 100644 (file)
@@ -1,9 +1,31 @@
+const int max_samples = 32;
+
+uniform mat4 projection_matrix;
+
 uniform sampler2D depth;
 uniform sampler2D occlusion;
 uniform sampler2D rotate;
 uniform AmbientOcclusionParams
 {
 uniform sampler2D depth;
 uniform sampler2D occlusion;
 uniform sampler2D rotate;
 uniform AmbientOcclusionParams
 {
-       vec2 screen_size;
-       vec2 depth_ratio;
+       mat4 inverse_projection;
        float darkness;
        float darkness;
+       vec3 sample_points[max_samples];
+       int n_samples;
+       float occlusion_radius;
+       float edge_depth_threshold;
 };
 };
+
+#pragma MSP stage(fragment)
+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);
+       return pp.xyz/pp.w;
+}
+
+vec3 unproject(vec3 position)
+{
+       vec4 upp = inverse_projection*vec4(position, 1.0);
+       return upp.xyz/upp.w;
+}