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;
uniform sampler2D rotate;
uniform AmbientOcclusionParams
{
- mat4 inverse_projection;
float darkness;
vec3 sample_points[max_samples];
int n_samples;
{
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;
}
}
rotate_lookup.image(0, data);
- shdata.uniform("inverse_projection", Matrix());
-
set_n_samples(16);
set_occlusion_radius(0.5f);
set_darkness(1.0f);
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);