From d85b6b86cfb6ae124ca92f13661ce4e412fc1e09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Fukhaut?= Date: Sun, 5 Jun 2016 19:13:21 +0200 Subject: Fixed Planar reflection Added Thickness parameter to SSR --- source/blender/gpu/intern/gpu_material.c | 9 ++++++--- source/blender/gpu/intern/gpu_pbr.c | 1 + .../blender/gpu/shaders/gpu_shader_material_utils.glsl | 16 ++++++++-------- source/blender/makesdna/DNA_gpu_types.h | 2 ++ source/blender/makesrna/intern/rna_space.c | 5 +++++ 5 files changed, 22 insertions(+), 11 deletions(-) (limited to 'source') diff --git a/source/blender/gpu/intern/gpu_material.c b/source/blender/gpu/intern/gpu_material.c index 9dee35fa7ec..8ac4769a920 100644 --- a/source/blender/gpu/intern/gpu_material.c +++ b/source/blender/gpu/intern/gpu_material.c @@ -695,12 +695,14 @@ void GPU_material_bind_uniforms_pbr(GPUMaterial *material, GPUProbe *probe, GPUP /* SSR Parameters */ /* x : steps : Maximum number of iteration when raymarching * y : offset : Step between samples. - * z : attenuation : fallof exponent */ + * z : attenuation : fallof exponent + * w : thickness : pixel thickness */ float ssrparams[3]; ssrparams[0] = (float)pbr_settings->ssr->steps; ssrparams[1] = pbr_settings->ssr->distance_max / (float)pbr_settings->ssr->steps; ssrparams[2] = pbr_settings->ssr->attenuation; - GPU_shader_uniform_vector(shader, material->ssrparamsloc, 3, 1, ssrparams); + ssrparams[3] = pbr_settings->ssr->thickness; + GPU_shader_uniform_vector(shader, material->ssrparamsloc, 4, 1, ssrparams); } if (pbr_settings->pbr_flag & GPU_PBR_FLAG_SSAO) { @@ -708,7 +710,8 @@ void GPU_material_bind_uniforms_pbr(GPUMaterial *material, GPUProbe *probe, GPUP /* SSAO Parameters */ /* x : sample : Number of samples * y : steps : Steps for the raymarching - * z : distance : Max distance */ + * z : distance : Max distance + * w : factor : Blend intensity */ float ssaoparams[4]; ssaoparams[0] = pbr_settings->ssao->samples; ssaoparams[1] = pbr_settings->ssao->steps; diff --git a/source/blender/gpu/intern/gpu_pbr.c b/source/blender/gpu/intern/gpu_pbr.c index 17d2d4da99b..8e79e4d6b46 100644 --- a/source/blender/gpu/intern/gpu_pbr.c +++ b/source/blender/gpu/intern/gpu_pbr.c @@ -286,6 +286,7 @@ static void gpu_pbr_init_ssr_settings(GPUSSRSettings *ssr_settings) { ssr_settings->distance_max = 10.0f; ssr_settings->attenuation = 6.0f; + ssr_settings->thickness = 0.2f; ssr_settings->steps = 32; } diff --git a/source/blender/gpu/shaders/gpu_shader_material_utils.glsl b/source/blender/gpu/shaders/gpu_shader_material_utils.glsl index cf879018f23..3f56d6549d6 100644 --- a/source/blender/gpu/shaders/gpu_shader_material_utils.glsl +++ b/source/blender/gpu/shaders/gpu_shader_material_utils.glsl @@ -40,7 +40,7 @@ uniform vec3 unfsh7; uniform vec3 unfsh8; uniform vec3 unfprobepos; uniform vec3 unfplanarvec; -uniform vec3 unfssrparam; +uniform vec4 unfssrparam; uniform vec4 unfssaoparam; uniform vec4 unfclip; uniform mat4 unfprobecorrectionmat; @@ -716,15 +716,15 @@ float distance_based_roughness(float dist_intersection_to_shaded, float dist_int } #endif -vec2 get_distorded_refl_uv(sampler2D planarprobe) +vec2 get_distorded_refl_uv(sampler2D planarprobe, vec2 Xi) { vec2 distortion = vec2(dot(viewnor, vec3(1.0, 0.0, 0.0)) - planarfac.x, dot(viewnor, vec3(0.0, 1.0, 0.0)) - planarfac.y); - distortion += Ht.xy; + distortion += Xi; /* modulate intensity by distance to the viewer and by distance to the reflected object */ float dist_view_to_shaded = planarfac.z; - float dist_intersection_to_reflectioncam = texture2D(planarprobe, refpos.xy + Ht.xy / dist_view_to_shaded).a; + float dist_intersection_to_reflectioncam = texture2D(planarprobe, refpos.xy + Xi / dist_view_to_shaded).a; float dist_intersection_to_shaded = dist_intersection_to_reflectioncam - dist_view_to_shaded; /* depth in alpha */ /* test in case of background */ @@ -760,7 +760,7 @@ vec4 sample_probe_pdf(sampler2D planarprobe, vec3 cubevec, float roughness, floa #ifdef PLANAR_PROBE vec4 sample_plane = vec4(0.0); - vec2 co = get_distorded_refl_uv(planarprobe); + vec2 co = get_distorded_refl_uv(planarprobe, Ht.xy); if (co.x > 0.0 && co.x < 1.0 && co.y > 0.0 && co.y < 1.0) sample_plane = texture2DLod(planarprobe, co, lod); else @@ -792,7 +792,7 @@ vec4 sample_probe(sampler2D planarprobe, vec3 cubevec) #ifdef PLANAR_PROBE /* Planar */ - vec2 co = get_distorded_refl_uv(planarprobe); + vec2 co = get_distorded_refl_uv(planarprobe, vec2(0.0)); if (co.x > 0.0 && co.x < 1.0 && co.y > 0.0 && co.y < 1.0) sample = texture2D(planarprobe, co); #endif @@ -956,9 +956,9 @@ bool raycast(vec3 ray_origin, vec3 ray_dir, float jitter, out float hitstep, out #ifdef USE_BACKFACE float backface = backface_depth(ivec2(hitpixel), 0); #else - float backface = frontface - 0.2; /* Todo find a good thickness */ + float backface = frontface - unfssrparam.w; #endif - hit = (zmax > backface); + hit = (zmin > backface); } } diff --git a/source/blender/makesdna/DNA_gpu_types.h b/source/blender/makesdna/DNA_gpu_types.h index d4a1f96b222..5b327b78b40 100644 --- a/source/blender/makesdna/DNA_gpu_types.h +++ b/source/blender/makesdna/DNA_gpu_types.h @@ -75,6 +75,8 @@ typedef enum eGPUFXFlags { typedef struct GPUSSRSettings { float distance_max; float attenuation; + float thickness; + float pad2; int steps; int pad; } GPUSSRSettings; diff --git a/source/blender/makesrna/intern/rna_space.c b/source/blender/makesrna/intern/rna_space.c index 4be077a8863..eea5e0384f3 100644 --- a/source/blender/makesrna/intern/rna_space.c +++ b/source/blender/makesrna/intern/rna_space.c @@ -2364,6 +2364,11 @@ static void rna_def_gpu_pbr_ssr(BlenderRNA *brna) RNA_def_property_range(prop, 1.0f, 20.0f); RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL); + prop = RNA_def_property(srna, "thickness", PROP_FLOAT, PROP_NONE); + RNA_def_property_ui_text(prop, "Thickness", "Pixel thickness. How thick is a pixel when searching for intersections"); + RNA_def_property_range(prop, 0.00001f, 100000.0f); + RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL); + prop = RNA_def_property(srna, "steps", PROP_INT, PROP_NONE); RNA_def_property_ui_text(prop, "Steps", "Number of pixels to travel for searching intersections"); RNA_def_property_range(prop, 1, 256); -- cgit v1.2.3