[Bf-blender-cvs] [33722d4] viewport_experiments: Greatly improved normal calculation using view space position derivatives.
Antony Riakiotakis
noreply at git.blender.org
Fri Sep 12 19:57:11 CEST 2014
Commit: 33722d4011256fc79afa7928dd735ffed5fc492f
Author: Antony Riakiotakis
Date: Fri Sep 12 19:56:56 2014 +0200
Branches: viewport_experiments
https://developer.blender.org/rB33722d4011256fc79afa7928dd735ffed5fc492f
Greatly improved normal calculation using view space position
derivatives.
===================================================================
M release/scripts/startup/bl_ui/space_view3d.py
M source/blender/gpu/shaders/gpu_shader_fx_frag.glsl
===================================================================
diff --git a/release/scripts/startup/bl_ui/space_view3d.py b/release/scripts/startup/bl_ui/space_view3d.py
index b192d24..dce5749 100644
--- a/release/scripts/startup/bl_ui/space_view3d.py
+++ b/release/scripts/startup/bl_ui/space_view3d.py
@@ -2869,8 +2869,7 @@ class VIEW3D_PT_view3d_shading(Panel):
if view.viewport_shade not in {'BOUNDBOX', 'WIREFRAME'}:
if obj and obj.mode == 'EDIT':
col.prop(view, "show_occlude_wire")
- #hide ssao for now, will expose again when it's ready
- #col.prop(view, "ssao")
+ col.prop(view, "ssao")
col.prop(view, "depth_of_field")
if view.depth_of_field:
subcol = col.column(align=True)
diff --git a/source/blender/gpu/shaders/gpu_shader_fx_frag.glsl b/source/blender/gpu/shaders/gpu_shader_fx_frag.glsl
index 965b5d7..198eb45 100644
--- a/source/blender/gpu/shaders/gpu_shader_fx_frag.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_fx_frag.glsl
@@ -15,48 +15,46 @@ uniform vec2 dof_params;
#define NUM_SAMPLES 5
-void calculate_ss_normal (in float depth, out vec4 color)
+vec3 calculate_ss_normal(in vec4 viewposition)
{
- vec2 offset_co = vec2(1.0/screendim.x, 1.0/screendim.y);
- float depthx = texture2D(depthbuffer, framecoords.xy + vec2(offset_co.x, 0.0)).r;
- float depthy = texture2D(depthbuffer, framecoords.xy + vec2(0.0, offset_co.y)).r;
+ vec3 normal = cross(normalize(dFdx(viewposition.xyz)),
+ normalize(dFdy(viewposition.xyz)));
+ normalize(normal);
+ normal = normal * 0.5 + vec3(0.5);
+ return normal;
+}
- // This is essentially a cross product multiplied screendim.x * screendim.y
- // If we were to use normal multiplication then we could easily get out of half-float range
- vec3 normal = vec3(screendim.y*(depthx - depth), screendim.x*(depthy - depth), 1.0);
- normalize(normal);
- normal = normal * 0.5 + vec3(0.5);
- color = vec4(normal, 1.0);
+float calculate_dof_coc(in vec4 viewposition, inout vec3 normal)
+{
+ float dist = length(viewposition);
+ float coc = dof_params.x * abs(1.0 - dof_params.y / dist);
+
+ coc = clamp(coc, 0.0, 1.0);
+
+ return coc;
}
void main()
{
- float depth = texture2D(depthbuffer, framecoords.xy).r;
+ vec3 normal;
+ float depth = texture2D(depthbuffer, framecoords.xy).r;
- //First we need to calculate the view space distance from the shader inputs
- //This will unfortunately depend on the precision of the depth buffer which is not linear
- vec2 norm_scr = framecoords.xy * 2.0 - 1.0;
- vec4 viewposition = vec4(norm_scr.x, norm_scr.y, depth, 1.0);
-
- // convert to view space now
- viewposition = gl_ProjectionMatrixInverse * viewposition;
- viewposition = viewposition / viewposition.w;
-
- //vec3 normal = cross(dFdx(viewposition.xyz), dFdy(viewposition.xyz));
- //normalize(normal);
- //normal.z = -normal.z;
- //normal = normal * 0.5 + vec3(0.5);
-
- //calculate circle of confusion
- float dist = length(viewposition);
- float coc = dof_params.x * abs(1.0 - dof_params.y / dist);
-
- coc = clamp(coc, 0.0, 1.0);
-
- // blend between blurred-non blurred images based on coc
- vec4 color = coc * vec4(1.0, 0.0, 0.0, 1.0) * texture2D(blurredcolorbuffer, framecoords.xy) +
- (1.0 - coc) * vec4(0.0, 1.0, 0.0, 1.0) * texture2D(colorbuffer, framecoords.xy);
-
- gl_FragColor = vec4(color.xyz, 1.0);
+ //First we need to calculate the view space distance from the shader inputs
+ //This will unfortunately depend on the precision of the depth buffer which is not linear
+ vec2 norm_scr = framecoords.xy * 2.0 - 1.0;
+ vec4 viewposition = vec4(norm_scr.x, norm_scr.y, depth, 1.0);
+
+ // convert to view space now
+ viewposition = gl_ProjectionMatrixInverse * viewposition;
+ viewposition = viewposition / viewposition.w;
+
+ normal = calculate_ss_normal(viewposition);
+ vec3 color = normal;
+
+ // blend between blurred-non blurred images based on coc
+ //vec4 color = coc * texture2D(blurredcolorbuffer, framecoords.xy) +
+ // (1.0 - coc) * texture2D(colorbuffer, framecoords.xy);
+
+ gl_FragColor = vec4(color.xyz, 1.0);
}
More information about the Bf-blender-cvs
mailing list