[Bf-blender-cvs] [e6bba9fa3a] clay-engine: Edge AO improvement when geometry is over the background.
Clément Foucault
noreply at git.blender.org
Wed Jan 18 18:57:36 CET 2017
Commit: e6bba9fa3a9c0368a550c6cc6413d756fe8a149b
Author: Clément Foucault
Date: Tue Jan 17 12:59:39 2017 +0100
Branches: clay-engine
https://developer.blender.org/rBe6bba9fa3a9c0368a550c6cc6413d756fe8a149b
Edge AO improvement when geometry is over the background.
===================================================================
M source/blender/draw/engines/clay/clay.c
M source/blender/draw/engines/clay/shaders/ssao_alchemy.glsl
===================================================================
diff --git a/source/blender/draw/engines/clay/clay.c b/source/blender/draw/engines/clay/clay.c
index 8aaafb635d..7cfe156339 100644
--- a/source/blender/draw/engines/clay/clay.c
+++ b/source/blender/draw/engines/clay/clay.c
@@ -53,10 +53,8 @@ typedef struct CLAY_BatchStorage {
static struct CLAY_data {
/* Depth Pre Pass */
struct GPUShader *depth_sh;
- struct DRWInterface *depth_itf;
/* Shading Pass */
struct GPUShader *clay_sh[8];
- struct DRWInterface *clay_itf;
/* Matcap textures */
struct GPUTexture *matcap_array;
diff --git a/source/blender/draw/engines/clay/shaders/ssao_alchemy.glsl b/source/blender/draw/engines/clay/shaders/ssao_alchemy.glsl
index f1ca611428..0f216bf5a3 100644
--- a/source/blender/draw/engines/clay/shaders/ssao_alchemy.glsl
+++ b/source/blender/draw/engines/clay/shaders/ssao_alchemy.glsl
@@ -21,6 +21,7 @@ void ssao_factors(in float depth, in vec3 normal, in vec3 position, in vec2 scre
int num_samples = int(ssao_samples_num);
for (x = 0; x < num_samples; x++) {
+ /* TODO : optimisation replace by constant */
vec2 dir_sample = texture1D(ssao_samples, (float(x) + 0.5) / ssao_samples_num).rg;
/* rotate with random direction to get jittered result */
@@ -32,24 +33,30 @@ void ssao_factors(in float depth, in vec3 normal, in vec3 position, in vec2 scre
continue;
float depth_new = texture2D(depthtex, uvcoords).r;
+
/* Handle Background case */
- if (depth_new != 1.0) {
- vec3 pos_new = get_view_space_from_depth(uvcoords, viewvecs[0].xyz, viewvecs[1].xyz, depth_new);
- vec3 dir = pos_new - position;
- float len = length(dir);
- float f_cavities = dot(dir, normal);
- float f_edge = dot(dir, -normal);
- float f_bias = 0.05 * len + 0.0001;
-
- float attenuation = 1.0 / (len * (1.0 + len * len * ssao_attenuation));
-
- /* use minor bias here to avoid self shadowing */
- if (f_cavities > f_bias)
- cavities += f_cavities * attenuation;
-
- if (f_edge > f_bias)
- edges += f_edge * attenuation;
- }
+ bool is_background = (depth_new == 1.0);
+
+ /* This trick provide good edge effect even if no neighboor is found. */
+ vec3 pos_new = get_view_space_from_depth(uvcoords, viewvecs[0].xyz, viewvecs[1].xyz, (is_background) ? depth : depth_new);
+
+ if (is_background)
+ pos_new.z -= ssao_distance;
+
+ vec3 dir = pos_new - position;
+ float len = length(dir);
+ float f_cavities = dot(dir, normal);
+ float f_edge = -f_cavities;
+ float f_bias = 0.05 * len + 0.0001;
+
+ float attenuation = 1.0 / (len * (1.0 + len * len * ssao_attenuation));
+
+ /* use minor bias here to avoid self shadowing */
+ if (f_cavities > -f_bias)
+ cavities += f_cavities * attenuation;
+
+ if (f_edge > f_bias)
+ edges += f_edge * attenuation;
}
cavities /= ssao_samples_num;
More information about the Bf-blender-cvs
mailing list