X-Git-Url: http://git.tdb.fi/?p=libs%2Fgl.git;a=blobdiff_plain;f=shaderlib%2Fambientocclusion.glsl;h=89d13357b67404dd5f06c180541d5723f372a34b;hp=0ca81a40b6cb21ed5fd8af08ce1852f25e94a46d;hb=ed5d922fd58c5cb1fc7502c93983d37fc871ddf5;hpb=e55f79ccb21e8c1be3d86f127e3ec1583e58ce92 diff --git a/shaderlib/ambientocclusion.glsl b/shaderlib/ambientocclusion.glsl index 0ca81a40..89d13357 100644 --- a/shaderlib/ambientocclusion.glsl +++ b/shaderlib/ambientocclusion.glsl @@ -1,9 +1,31 @@ +const int max_samples = 32; + +uniform mat4 projection_matrix; + uniform sampler2D depth; uniform sampler2D occlusion; uniform sampler2D rotate; uniform AmbientOcclusionParams { - vec2 screen_size; - vec2 depth_ratio; + mat4 inverse_projection; 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; +}