12 uniform
float R2_depth_coefficient;
14 uniform mat4x4 R2_ssao_transform_projection;
15 uniform sampler2D R2_ssao_noise;
16 uniform vec2 R2_ssao_noise_uv_scale;
17 uniform vec3 R2_ssao_kernel[128];
18 uniform
int R2_ssao_kernel_size;
19 uniform
float R2_ssao_sample_radius;
20 uniform
float R2_ssao_power;
22 layout(location = 0) out
float R2_out_occlusion;
29 vec2 screen_uv = R2_uv;
33 texture (R2_gbuffer.
depth, screen_uv).x;
34 float eye_z_positive =
44 vec2 normal_compressed =
45 texture (R2_gbuffer.
normal, screen_uv).xy;
51 screen_uv * R2_ssao_noise_uv_scale;
54 (texture(R2_ssao_noise, noise_uv).rgb * 2.0) - 1.0;
57 vec3 tangent = normalize (noise_sample - normal * dot (noise_sample, normal));
58 vec3 bitangent = cross (normal, tangent);
59 mat3x3 m_hemi = mat3x3 (tangent, bitangent, normal);
62 float occlusion = 0.0;
63 for (
int index = 0; index < R2_ssao_kernel_size; ++index) {
65 vec3 sample_eye = ((m_hemi * R2_ssao_kernel[index]) * R2_ssao_sample_radius) + eye_position.xyz;
68 vec4 sample_hom = vec4 (sample_eye, 1.0);
69 vec4 sample_clip = R2_ssao_transform_projection * sample_hom;
72 vec2 sample_ndc = sample_clip.xy / sample_clip.w;
73 vec2 sample_uv = (sample_ndc * 0.5) + 0.5;
76 float sample_surface_depth_log =
77 texture (R2_gbuffer.
depth, sample_uv).r;
80 float sample_surface_eye_z_positive =
82 float sample_surface_eye_z =
83 -sample_surface_eye_z_positive;
86 float sample_range_check =
87 abs (eye_position.z - sample_surface_eye_z) < R2_ssao_sample_radius ? 1.0 : 0.0;
95 occlusion += (sample_surface_eye_z >= sample_eye.z ? 1.0 : 0.0) * sample_range_check;
99 occlusion = 1.0 - (occlusion / R2_ssao_kernel_size);
103 occlusion = pow (occlusion, R2_ssao_power);
105 R2_out_occlusion = occlusion;
Functions for transforming normal vectors.
Viewport types and functions.
float R2_logDepthDecode(const float z, const float depth_coefficient)
vec3 R2_normalsDecompress(const vec2 n)
The type of view rays used to reconstruct positions during deferred rendering.
Logarithmic depth functions.
vec4 R2_positionReconstructFromEyeZ(const float eye_z, const vec2 uv, const R2_view_rays_t view_rays)
layout(location=0) out vec4 R2_out
RGBA color.
Functions for performing position reconstruction during deferred rendering.