diff options
Diffstat (limited to 'drivers/gles2/shaders/ssao_blur.glsl')
-rw-r--r-- | drivers/gles2/shaders/ssao_blur.glsl | 51 |
1 files changed, 21 insertions, 30 deletions
diff --git a/drivers/gles2/shaders/ssao_blur.glsl b/drivers/gles2/shaders/ssao_blur.glsl index 472dc21acf..82b735a2b4 100644 --- a/drivers/gles2/shaders/ssao_blur.glsl +++ b/drivers/gles2/shaders/ssao_blur.glsl @@ -1,26 +1,21 @@ [vertex] - -layout(location=0) in highp vec4 vertex_attrib; - +layout(location = 0) in highp vec4 vertex_attrib; void main() { gl_Position = vertex_attrib; - gl_Position.z=1.0; + gl_Position.z = 1.0; } [fragment] - uniform sampler2D source_ssao; //texunit:0 uniform sampler2D source_depth; //texunit:1 uniform sampler2D source_normal; //texunit:3 - layout(location = 0) out float visibility; - ////////////////////////////////////////////////////////////////////////////////////////////// // Tunable Parameters: @@ -28,32 +23,30 @@ layout(location = 0) out float visibility; 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 - performance at the expense of some dithering artifacts. + first AO pass. This constant can be increased while R decreases to improve + performance at the expense of some dithering artifacts. - Morgan found that a scale of 3 left a 1-pixel checkerboard grid that was - unobjectionable after shading was applied but eliminated most temporal incoherence - from using small numbers of sample taps. - */ + Morgan found that a scale of 3 left a 1-pixel checkerboard grid that was + unobjectionable after shading was applied but eliminated most temporal incoherence + from using small numbers of sample taps. + */ uniform int filter_scale; /** Filter radius in pixels. This will be multiplied by SCALE. */ -#define R (4) - +#define R (4) ////////////////////////////////////////////////////////////////////////////////////////////// - // Gaussian coefficients const float gaussian[R + 1] = -// float[](0.356642, 0.239400, 0.072410, 0.009869); -// float[](0.398943, 0.241971, 0.053991, 0.004432, 0.000134); // stddev = 1.0 - float[](0.153170, 0.144893, 0.122649, 0.092902, 0.062970); // stddev = 2.0 -// float[](0.111220, 0.107798, 0.098151, 0.083953, 0.067458, 0.050920, 0.036108); // stddev = 3.0 + //float[](0.356642, 0.239400, 0.072410, 0.009869); + //float[](0.398943, 0.241971, 0.053991, 0.004432, 0.000134); // stddev = 1.0 + float[](0.153170, 0.144893, 0.122649, 0.092902, 0.062970); // stddev = 2.0 + //float[](0.111220, 0.107798, 0.098151, 0.083953, 0.067458, 0.050920, 0.036108); // stddev = 3.0 /** (1, 0) or (0, 1)*/ -uniform ivec2 axis; +uniform ivec2 axis; uniform float camera_z_far; uniform float camera_z_near; @@ -72,11 +65,11 @@ void main() { float depth_divide = 1.0 / camera_z_far; -// depth*=depth_divide; + //depth *= depth_divide; /* - if (depth > camera_z_far*0.999) { - discard;//skybox + if (depth > camera_z_far * 0.999) { + discard; //skybox } */ @@ -96,23 +89,21 @@ void main() { if (r != 0) { ivec2 ppos = ssC + axis * (r * filter_scale); - float value = texelFetch(source_ssao, clamp(ppos,ivec2(0),clamp_limit), 0).r; - ivec2 rpos = clamp(ppos,ivec2(0),clamp_limit); + float value = texelFetch(source_ssao, clamp(ppos, 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 * abs(temp_depth - depth) - ); + weight *= max(0.0, 1.0 - edge_sharpness * abs(temp_depth - depth)); sum += value * weight; totalWeight += weight; |