diff options
author | Juan Linietsky <reduzio@gmail.com> | 2017-10-22 13:52:31 -0300 |
---|---|---|
committer | Juan Linietsky <reduzio@gmail.com> | 2017-10-22 13:52:48 -0300 |
commit | b4f0f59d9fd59c37c931f61ba4e1fe2bf1ac7291 (patch) | |
tree | 47204aee03707a6dfc667dee59f45e32a7acde8d /drivers/gles3/shaders | |
parent | 58b849800e57812dfee0b3ed3f4bd507d4f9c224 (diff) |
Many fixes to SSAO, should be good now.
Diffstat (limited to 'drivers/gles3/shaders')
-rw-r--r-- | drivers/gles3/shaders/ssao.glsl | 24 | ||||
-rw-r--r-- | drivers/gles3/shaders/ssao_blur.glsl | 20 |
2 files changed, 33 insertions, 11 deletions
diff --git a/drivers/gles3/shaders/ssao.glsl b/drivers/gles3/shaders/ssao.glsl index c668e63745..219f0957e0 100644 --- a/drivers/gles3/shaders/ssao.glsl +++ b/drivers/gles3/shaders/ssao.glsl @@ -13,8 +13,24 @@ void main() { #define TWO_PI 6.283185307179586476925286766559 +#ifdef SSAO_QUALITY_HIGH + +#define NUM_SAMPLES (80) + +#endif + +#ifdef SSAO_QUALITY_LOW + #define NUM_SAMPLES (15) +#endif + +#if !defined(SSAO_QUALITY_LOW) && !defined(SSAO_QUALITY_HIGH) + +#define NUM_SAMPLES (40) + +#endif + // If using depth mip levels, the log of the maximum pixel offset before we need to switch to a lower // miplevel to maintain reasonable spatial locality in the cache // If this number is too small (< 3), too many taps will land in the same pixel, and we'll get bad variance that manifests as flashing. @@ -212,12 +228,12 @@ void main() { //visibility=-C.z/camera_z_far; //return; - - //vec3 n_C = texelFetch(source_normal,ssC,0).rgb * 2.0 - 1.0; - +#if 0 + vec3 n_C = texelFetch(source_normal,ssC,0).rgb * 2.0 - 1.0; +#else vec3 n_C = reconstructCSFaceNormal(C); n_C = -n_C; - +#endif // Hash function used in the HPG12 AlchemyAO paper float randomPatternRotationAngle = mod(float((3 * ssC.x ^ ssC.y + ssC.x * ssC.y) * 10), TWO_PI); diff --git a/drivers/gles3/shaders/ssao_blur.glsl b/drivers/gles3/shaders/ssao_blur.glsl index c7c978dc37..472dc21acf 100644 --- a/drivers/gles3/shaders/ssao_blur.glsl +++ b/drivers/gles3/shaders/ssao_blur.glsl @@ -15,6 +15,7 @@ void main() { uniform sampler2D source_ssao; //texunit:0 uniform sampler2D source_depth; //texunit:1 +uniform sampler2D source_normal; //texunit:3 layout(location = 0) out float visibility; @@ -24,7 +25,7 @@ layout(location = 0) out float visibility; // Tunable Parameters: /** Increase to make depth edges crisper. Decrease to reduce flicker. */ -#define EDGE_SHARPNESS (4.0) +uniform float edge_sharpness; /** Step in 2-pixel intervals since we already blurred against neighbors in the first AO pass. This constant can be increased while R decreases to improve @@ -34,7 +35,8 @@ layout(location = 0) out float visibility; unobjectionable after shading was applied but eliminated most temporal incoherence from using small numbers of sample taps. */ -#define SCALE (3) + +uniform int filter_scale; /** Filter radius in pixels. This will be multiplied by SCALE. */ #define R (4) @@ -63,13 +65,14 @@ void main() { ivec2 ssC = ivec2(gl_FragCoord.xy); float depth = texelFetch(source_depth, ssC, 0).r; + //vec3 normal = texelFetch(source_normal,ssC,0).rgb * 2.0 - 1.0; depth = depth * 2.0 - 1.0; depth = 2.0 * camera_z_near * camera_z_far / (camera_z_far + camera_z_near - depth * (camera_z_far - camera_z_near)); float depth_divide = 1.0 / camera_z_far; - depth*=depth_divide; +// depth*=depth_divide; /* if (depth > camera_z_far*0.999) { @@ -92,20 +95,23 @@ void main() { // so the IF statement has no runtime cost if (r != 0) { - ivec2 ppos = ssC + axis * (r * SCALE); + ivec2 ppos = ssC + axis * (r * filter_scale); float value = texelFetch(source_ssao, clamp(ppos,ivec2(0),clamp_limit), 0).r; - float temp_depth = texelFetch(source_depth, clamp(ssC,ivec2(0),clamp_limit), 0).r; + ivec2 rpos = clamp(ppos,ivec2(0),clamp_limit); + float temp_depth = texelFetch(source_depth, rpos, 0).r; + //vec3 temp_normal = texelFetch(source_normal, rpos, 0).rgb * 2.0 - 1.0; temp_depth = temp_depth * 2.0 - 1.0; temp_depth = 2.0 * camera_z_near * camera_z_far / (camera_z_far + camera_z_near - temp_depth * (camera_z_far - camera_z_near)); - temp_depth *= depth_divide; +// temp_depth *= depth_divide; // spatial domain: offset gaussian tap float weight = 0.3 + gaussian[abs(r)]; + //weight *= max(0.0,dot(temp_normal,normal)); // range domain (the "bilateral" weight). As depth difference increases, decrease weight. weight *= max(0.0, 1.0 - - (EDGE_SHARPNESS * 2000.0) * abs(temp_depth - depth) + - edge_sharpness * abs(temp_depth - depth) ); sum += value * weight; |