]> git.tdb.fi Git - libs/gl.git/blobdiff - builtin_data/_ambientocclusion.glsl
Check the flat qualifier from the correct member
[libs/gl.git] / builtin_data / _ambientocclusion.glsl
index dca636bb646092da6cd0a823f5fe3783186c851f..0fca6bb2a4b34c72d5e3efda18ff55e35a08496f 100644 (file)
@@ -1,14 +1,19 @@
-const int max_samples = 32;
+const int max_samples = 128;
 
-uniform mat4 projection_matrix;
+layout(set=0) uniform CameraTransform
+{
+       mat4 eye_world_matrix;
+       mat4 world_eye_matrix;
+       mat4 clip_eye_matrix;
+       mat4 eye_clip_matrix;
+};
 
-uniform sampler2D source;
-uniform sampler2D depth;
-uniform sampler2D occlusion;
-uniform sampler2D rotate;
-uniform AmbientOcclusionParams
+layout(set=2) uniform sampler2D source;
+layout(set=2) uniform sampler2D depth;
+layout(set=2) uniform sampler2D occlusion;
+layout(set=2) uniform sampler2D rotate;
+layout(set=2) uniform AmbientOcclusionParams
 {
-       mat4 inverse_projection;
        float darkness;
        vec3 sample_points[max_samples];
        int n_samples;
@@ -21,12 +26,24 @@ 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;
 }
+
+vec3 get_fragment_position(vec2 tc)
+{
+       return unproject(vec3(tc*2.0-1.0, texture(depth, tc).r));
+}
+
+vec3 get_slope(vec3 a, vec3 x, vec3 b)
+{
+       float dz1 = abs(x.z-a.z);
+       float dz2 = abs(b.z-x.z);
+       return (dz1>2.0*dz2 ? b-x : dz2>2.0*dz1 ? x-a : b-a);
+}