[Bf-blender-cvs] [21f43fb] viewport_experiments: SSAO

Antony Riakiotakis noreply at git.blender.org
Mon Sep 15 16:55:20 CEST 2014


Commit: 21f43fb13c4a87f41eeb030e047188a877cf303c
Author: Antony Riakiotakis
Date:   Mon Sep 15 16:55:05 2014 +0200
Branches: viewport_experiments
https://developer.blender.org/rB21f43fb13c4a87f41eeb030e047188a877cf303c

SSAO

* Expose attenuation value - allows to change influence of far objects
* Change influence of far objects to quadratic, eliminates some extreme
fringing from far occluding surfaces.

===================================================================

M	release/scripts/startup/bl_ui/space_view3d.py
M	source/blender/editors/space_view3d/view3d_draw.c
M	source/blender/gpu/shaders/gpu_shader_fx_frag.glsl
M	source/blender/makesdna/DNA_view3d_types.h
M	source/blender/makesrna/intern/rna_space.c

===================================================================

diff --git a/release/scripts/startup/bl_ui/space_view3d.py b/release/scripts/startup/bl_ui/space_view3d.py
index e515240..417fcb3 100644
--- a/release/scripts/startup/bl_ui/space_view3d.py
+++ b/release/scripts/startup/bl_ui/space_view3d.py
@@ -2880,6 +2880,7 @@ class VIEW3D_PT_view3d_shading(Panel):
                 subcol = col.column(align=True)
                 subcol.prop(view, "ssao_scale")
                 subcol.prop(view, "ssao_darkening")
+                subcol.prop(view, "ssao_distance_atten")
 
 
 class VIEW3D_PT_view3d_motion_tracking(Panel):
diff --git a/source/blender/editors/space_view3d/view3d_draw.c b/source/blender/editors/space_view3d/view3d_draw.c
index b79afea..144b191 100644
--- a/source/blender/editors/space_view3d/view3d_draw.c
+++ b/source/blender/editors/space_view3d/view3d_draw.c
@@ -3497,7 +3497,7 @@ static void view3d_main_area_draw_objects(const bContext *C, Scene *scene, View3
 			float fac = v3d->dof_fstop * v3d->dof_aperture;
 			float dof_params[2] = {v3d->dof_aperture * fabs(fac / (v3d->dof_focal_distance - fac)), 
 								   v3d->dof_focal_distance};
-			float ssao_params[2] = {v3d->ssao_scale, v3d->ssao_darkening};
+			float ssao_params[4] = {v3d->ssao_scale, v3d->ssao_darkening, v3d->ssao_distance_atten, 0.0};
 
 			dof_uniform = GPU_shader_get_uniform(fx_shader, "dof_params");
 			ssao_uniform = GPU_shader_get_uniform(fx_shader, "ssao_params");
@@ -3510,7 +3510,7 @@ static void view3d_main_area_draw_objects(const bContext *C, Scene *scene, View3
 
 			GPU_shader_uniform_vector(fx_shader, screendim_uniform, 2, 1, screendim);
 			GPU_shader_uniform_vector(fx_shader, dof_uniform, 2, 1, dof_params);
-			GPU_shader_uniform_vector(fx_shader, ssao_uniform, 2, 1, ssao_params);
+			GPU_shader_uniform_vector(fx_shader, ssao_uniform, 4, 1, ssao_params);
 
 			GPU_texture_bind(color_buffer, 0);
 			GPU_shader_uniform_texture(fx_shader, blurred_uniform, color_buffer);
diff --git a/source/blender/gpu/shaders/gpu_shader_fx_frag.glsl b/source/blender/gpu/shaders/gpu_shader_fx_frag.glsl
index 7e95106..ed0ad05 100644
--- a/source/blender/gpu/shaders/gpu_shader_fx_frag.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_fx_frag.glsl
@@ -15,7 +15,7 @@ uniform vec2 dof_params;
 
 /* ssao_params.x : pixel scale for the ssao radious */
 /* ssao_params.y : factor for the ssao darkening */
-uniform vec2 ssao_params;
+uniform vec4 ssao_params;
 
 #define NUM_SAMPLES 8
 
@@ -66,7 +66,7 @@ float calculate_ssao_factor(in vec3 normal, in vec4 position)
             vec4 pos_new = calculate_view_space_position(framecoords.xy + (vec2(x,y) - vec2(4.0)) * offset);
             vec3 dir = vec3(pos_new.xyz) - vec3(position.xyz);
             float len = length(dir);
-            factor += max(dot(dir, normal) * (1.0/(1.0 + len)), 0.0);
+            factor += max(dot(dir, normal) * (1.0/(1.0 + len * len * ssao_params.z)), 0.0);
         }
     }
 
diff --git a/source/blender/makesdna/DNA_view3d_types.h b/source/blender/makesdna/DNA_view3d_types.h
index cef93dd..9887dee 100644
--- a/source/blender/makesdna/DNA_view3d_types.h
+++ b/source/blender/makesdna/DNA_view3d_types.h
@@ -222,7 +222,7 @@ typedef struct View3D {
 	float dof_fstop;
 	float ssao_darkening;
 	float ssao_scale;
-	float pad4;
+	float ssao_distance_atten;
 	
 	void *properties_storage;		/* Nkey panel stores stuff here (runtime only!) */
 	struct Material *defmaterial;	/* used by matcap now */
diff --git a/source/blender/makesrna/intern/rna_space.c b/source/blender/makesrna/intern/rna_space.c
index 414f437..ee19872 100644
--- a/source/blender/makesrna/intern/rna_space.c
+++ b/source/blender/makesrna/intern/rna_space.c
@@ -2205,6 +2205,11 @@ static void rna_def_space_view3d(BlenderRNA *brna)
 	RNA_def_property_range(prop, 0.0f, 100000.0f);
 	RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
 	
+	prop = RNA_def_property(srna, "ssao_distance_atten", PROP_FLOAT, PROP_NONE);
+	RNA_def_property_ui_text(prop, "Attenuation", "Attenuate the SSAO distance");
+	RNA_def_property_range(prop, 0.0f, 100000.0f);
+	RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
+	
 	prop = RNA_def_property(srna, "ssao", PROP_BOOLEAN, PROP_NONE);
 	RNA_def_property_boolean_sdna(prop, NULL, "shader_fx", V3D_FX_SSAO);
 	RNA_def_property_ui_text(prop, "SSAO", "Use screen space ambient occlusion of field on viewport");




More information about the Bf-blender-cvs mailing list