Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
authorClément Fukhaut <turjuque@gmail.com>2016-06-05 20:13:21 +0300
committerClément Fukhaut <turjuque@gmail.com>2016-06-05 20:13:21 +0300
commitd85b6b86cfb6ae124ca92f13661ce4e412fc1e09 (patch)
tree5832c270e5586840d9e7b4dd7100a6e2a3375357 /source
parentdb461850d7fc03dbd72252c501f602c953c51d97 (diff)
Fixed Planar reflection
Added Thickness parameter to SSR
Diffstat (limited to 'source')
-rw-r--r--source/blender/gpu/intern/gpu_material.c9
-rw-r--r--source/blender/gpu/intern/gpu_pbr.c1
-rw-r--r--source/blender/gpu/shaders/gpu_shader_material_utils.glsl16
-rw-r--r--source/blender/makesdna/DNA_gpu_types.h2
-rw-r--r--source/blender/makesrna/intern/rna_space.c5
5 files changed, 22 insertions, 11 deletions
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);