[Bf-blender-cvs] [33cee26] viewport_experiments: Custom color for SSAO
Antony Riakiotakis
noreply at git.blender.org
Thu Sep 18 21:41:09 CEST 2014
Commit: 33cee269dac7dc7dd059cdd11d2560f71bab823a
Author: Antony Riakiotakis
Date: Thu Sep 18 21:40:45 2014 +0200
Branches: viewport_experiments
https://developer.blender.org/rB33cee269dac7dc7dd059cdd11d2560f71bab823a
Custom color for SSAO
===================================================================
M release/scripts/startup/bl_ui/space_view3d.py
M source/blender/gpu/intern/gpu_compositing.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 417fcb3..0cbdb4d 100644
--- a/release/scripts/startup/bl_ui/space_view3d.py
+++ b/release/scripts/startup/bl_ui/space_view3d.py
@@ -2881,6 +2881,7 @@ class VIEW3D_PT_view3d_shading(Panel):
subcol.prop(view, "ssao_scale")
subcol.prop(view, "ssao_darkening")
subcol.prop(view, "ssao_distance_atten")
+ subcol.prop(view, "ssao_color")
class VIEW3D_PT_view3d_motion_tracking(Panel):
diff --git a/source/blender/gpu/intern/gpu_compositing.c b/source/blender/gpu/intern/gpu_compositing.c
index 4f03bd8..1aa1b5a 100644
--- a/source/blender/gpu/intern/gpu_compositing.c
+++ b/source/blender/gpu/intern/gpu_compositing.c
@@ -188,7 +188,8 @@ bool GPU_fx_do_composite_pass(GPUFX *fx, struct View3D *v3d) {
/* set up the shader */
fx_shader = GPU_shader_get_builtin_fx_shader(GPU_SHADER_FX_DEPTH_OF_FIELD);
if (fx_shader) {
- int screendim_uniform, color_uniform, depth_uniform, dof_uniform, blurred_uniform, ssao_uniform;
+ int screendim_uniform, color_uniform, depth_uniform, dof_uniform, blurred_uniform;
+ int ssao_uniform, ssao_color_uniform;
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};
@@ -197,6 +198,7 @@ bool GPU_fx_do_composite_pass(GPUFX *fx, struct View3D *v3d) {
dof_uniform = GPU_shader_get_uniform(fx_shader, "dof_params");
ssao_uniform = GPU_shader_get_uniform(fx_shader, "ssao_params");
+ ssao_color_uniform = GPU_shader_get_uniform(fx_shader, "ssao_color");
blurred_uniform = GPU_shader_get_uniform(fx_shader, "blurredcolorbuffer");
screendim_uniform = GPU_shader_get_uniform(fx_shader, "screendim");
color_uniform = GPU_shader_get_uniform(fx_shader, "colorbuffer");
@@ -207,6 +209,7 @@ bool GPU_fx_do_composite_pass(GPUFX *fx, struct View3D *v3d) {
GPU_shader_uniform_vector(fx_shader, screendim_uniform, 2, 1, screen_dim);
GPU_shader_uniform_vector(fx_shader, dof_uniform, 2, 1, dof_params);
GPU_shader_uniform_vector(fx_shader, ssao_uniform, 4, 1, ssao_params);
+ GPU_shader_uniform_vector(fx_shader, ssao_color_uniform, 4, 1, v3d->ssao_color);
GPU_texture_bind(fx->color_buffer, numslots++);
GPU_shader_uniform_texture(fx_shader, blurred_uniform, fx->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 5b6d5d3..590ec57 100644
--- a/source/blender/gpu/shaders/gpu_shader_fx_frag.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_fx_frag.glsl
@@ -16,6 +16,7 @@ uniform vec2 dof_params;
/* ssao_params.x : pixel scale for the ssao radious */
/* ssao_params.y : factor for the ssao darkening */
uniform vec4 ssao_params;
+uniform vec4 ssao_color;
#define NUM_SAMPLES 8
@@ -82,7 +83,7 @@ float calculate_ssao_factor(float depth)
factor /= NUM_SAMPLES * NUM_SAMPLES;
- return max(0.0, 1.0 - factor * ssao_params.y);
+ return max(0.0, factor * ssao_params.y);
}
void main()
@@ -95,7 +96,6 @@ void main()
//vec4 color = coc * texture2D(blurredcolorbuffer, framecoords.xy) +
// (1.0 - coc) * texture2D(colorbuffer, framecoords.xy);
- vec4 color = texture2D(colorbuffer, framecoords.xy) *
- calculate_ssao_factor(depth);
+ vec4 color = mix(texture2D(colorbuffer, framecoords.xy), ssao_color, calculate_ssao_factor(depth));
gl_FragColor = vec4(color.xyz, 1.0);
}
diff --git a/source/blender/makesdna/DNA_view3d_types.h b/source/blender/makesdna/DNA_view3d_types.h
index 91a51fb..dba2636 100644
--- a/source/blender/makesdna/DNA_view3d_types.h
+++ b/source/blender/makesdna/DNA_view3d_types.h
@@ -228,6 +228,7 @@ typedef struct View3D {
float ssao_darkening;
float ssao_scale;
float ssao_distance_atten;
+ float ssao_color[4];
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 ee19872..3c0f9af 100644
--- a/source/blender/makesrna/intern/rna_space.c
+++ b/source/blender/makesrna/intern/rna_space.c
@@ -2214,6 +2214,11 @@ static void rna_def_space_view3d(BlenderRNA *brna)
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");
RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
+
+ prop = RNA_def_property(srna, "ssao_color", PROP_FLOAT, PROP_COLOR_GAMMA);
+ RNA_def_property_ui_text(prop, "SSAO Color", "Color for screen space ambient occlusion effect");
+ RNA_def_property_range(prop, 0.0f, 1.0f);
+ RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
/* region */
More information about the Bf-blender-cvs
mailing list