[Bf-blender-cvs] [05d73ec06f1] blender2.8: Eevee: Planar Reflection: only support mirror reflection if not using SSR.

Clément Foucault noreply at git.blender.org
Thu Jul 27 14:59:16 CEST 2017


Commit: 05d73ec06f19013b3cdd4b05870baa45b59b961f
Author: Clément Foucault
Date:   Thu Jul 27 11:21:11 2017 +0200
Branches: blender2.8
https://developer.blender.org/rB05d73ec06f19013b3cdd4b05870baa45b59b961f

Eevee: Planar Reflection: only support mirror reflection if not using SSR.

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

M	source/blender/draw/engines/eevee/eevee_lightprobes.c
M	source/blender/draw/engines/eevee/shaders/bsdf_common_lib.glsl
M	source/blender/draw/engines/eevee/shaders/effect_ssr_frag.glsl
M	source/blender/draw/engines/eevee/shaders/lightprobe_lib.glsl
M	source/blender/draw/engines/eevee/shaders/lightprobe_planar_display_frag.glsl
M	source/blender/draw/engines/eevee/shaders/lit_surface_frag.glsl

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

diff --git a/source/blender/draw/engines/eevee/eevee_lightprobes.c b/source/blender/draw/engines/eevee/eevee_lightprobes.c
index e31c97f0b7d..7f593c2cc61 100644
--- a/source/blender/draw/engines/eevee/eevee_lightprobes.c
+++ b/source/blender/draw/engines/eevee/eevee_lightprobes.c
@@ -1340,7 +1340,7 @@ update_planar:
 	}
 
 	/* If there is at least one planar probe */
-	if (pinfo->num_planar > 0) {
+	if (pinfo->num_planar > 0 && (vedata->stl->effects->enabled_effects & EFFECT_SSR) != 0) {
 		const int max_lod = 9;
 		DRW_stats_group_start("Planar Probe Downsample");
 		DRW_framebuffer_recursive_downsample(vedata->fbl->downsample_fb, txl->planar_pool, max_lod, &downsample_planar, vedata);
diff --git a/source/blender/draw/engines/eevee/shaders/bsdf_common_lib.glsl b/source/blender/draw/engines/eevee/shaders/bsdf_common_lib.glsl
index 99e2132277d..17430007502 100644
--- a/source/blender/draw/engines/eevee/shaders/bsdf_common_lib.glsl
+++ b/source/blender/draw/engines/eevee/shaders/bsdf_common_lib.glsl
@@ -9,6 +9,7 @@
 #define LUT_SIZE 64
 
 uniform mat4 ProjectionMatrix;
+uniform mat4 ViewProjectionMatrix;
 uniform mat4 ViewMatrixInverse;
 uniform vec4 viewvecs[2];
 #ifndef SHADOW_SHADER
diff --git a/source/blender/draw/engines/eevee/shaders/effect_ssr_frag.glsl b/source/blender/draw/engines/eevee/shaders/effect_ssr_frag.glsl
index 901d1fa4aea..3a8430f14e6 100644
--- a/source/blender/draw/engines/eevee/shaders/effect_ssr_frag.glsl
+++ b/source/blender/draw/engines/eevee/shaders/effect_ssr_frag.glsl
@@ -35,8 +35,6 @@ uniform sampler2D specroughBuffer;
 
 uniform int planar_count;
 
-uniform mat4 ViewProjectionMatrix;
-
 layout(location = 0) out vec4 hitData0;
 layout(location = 1) out vec4 hitData1;
 layout(location = 2) out vec4 hitData2;
@@ -149,7 +147,7 @@ void main()
 	for (int i = 0; i < MAX_PLANAR && i < planar_count; ++i) {
 		PlanarData pd = planars_data[i];
 
-		float fade = probe_attenuation_planar(pd, worldPosition, wN);
+		float fade = probe_attenuation_planar(pd, worldPosition, wN, 0.0);
 
 		if (fade > 0.5) {
 			/* Find view vector / reflection plane intersection. */
@@ -191,7 +189,6 @@ uniform int planar_count;
 uniform float borderFadeFactor;
 uniform float fireflyFactor;
 
-uniform mat4 ViewProjectionMatrix;
 uniform mat4 PastViewProjectionMatrix;
 
 out vec4 fragColor;
@@ -380,7 +377,7 @@ void main()
 	for (int i = 0; i < MAX_PLANAR && i < planar_count; ++i) {
 		pd = planars_data[i];
 
-		float fade = probe_attenuation_planar(pd, worldPosition, N);
+		float fade = probe_attenuation_planar(pd, worldPosition, N, 0.0);
 
 		if (fade > 0.5) {
 			planar_index = float(i);
diff --git a/source/blender/draw/engines/eevee/shaders/lightprobe_lib.glsl b/source/blender/draw/engines/eevee/shaders/lightprobe_lib.glsl
index 154d48eb247..93adc9483ad 100644
--- a/source/blender/draw/engines/eevee/shaders/lightprobe_lib.glsl
+++ b/source/blender/draw/engines/eevee/shaders/lightprobe_lib.glsl
@@ -100,7 +100,7 @@ float probe_attenuation_cube(CubeData pd, vec3 W)
 	return fac;
 }
 
-float probe_attenuation_planar(PlanarData pd, vec3 W, vec3 N)
+float probe_attenuation_planar(PlanarData pd, vec3 W, vec3 N, float roughness)
 {
 	/* Normal Facing */
 	float fac = saturate(dot(pd.pl_normal, N) * pd.pl_facing_scale + pd.pl_facing_bias);
@@ -114,6 +114,9 @@ float probe_attenuation_planar(PlanarData pd, vec3 W, vec3 N)
 	dist_to_clip.y = dot(pd.pl_clip_pos_y, W);
 	fac *= step(2.0, dot(step(pd.pl_clip_edges, dist_to_clip.xxyy), vec2(-1.0, 1.0).xyxy)); /* compare and add all tests */
 
+	/* Decrease influence for high roughness */
+	fac *= saturate(1.0 - roughness * 10.0);
+
 	return fac;
 }
 
@@ -182,24 +185,12 @@ vec3 probe_evaluate_planar(
 	vec3 ref_pos = point_on_plane + proj_ref;
 
 	/* Reproject to find texture coords. */
-	vec4 refco = pd.reflectionmat * vec4(ref_pos, 1.0);
+	vec4 refco = ViewProjectionMatrix * vec4(ref_pos, 1.0);
 	refco.xy /= refco.w;
 
-	/* Distance to roughness */
-	float linear_roughness = sqrt(roughness);
-	float distance_roughness = min(linear_roughness, ref_depth * linear_roughness);
-	linear_roughness = mix(distance_roughness, linear_roughness, linear_roughness);
-
-	/* Decrease influence for high roughness */
-	fade *= saturate((1.0 - linear_roughness) * 5.0 - 2.0);
-
-	float lod = linear_roughness * 2.5 * lodPlanarMax;
-	vec3 sample = textureLod(probePlanars, vec3(refco.xy, id), lod).rgb;
-
-	/* Use a second sample randomly rotated to blur out the lowres aspect */
-	vec2 rot_sample = (1.0 / vec2(textureSize(probePlanars, 0).xy)) * vec2(cos(rand * M_2PI), sin(rand * M_2PI)) * lod;
-	sample += textureLod(probePlanars, vec3(refco.xy + rot_sample, id), lod).rgb;
-	sample *= 0.5;
+	/* TODO: If we support non-ssr planar reflection, we should blur them with gaussian
+	 * and chose the right mip depending on the cone footprint after projection */
+	vec3 sample = textureLod(probePlanars, vec3(refco.xy * 0.5 + 0.5, id), 0.0).rgb;
 
 	return sample;
 }
diff --git a/source/blender/draw/engines/eevee/shaders/lightprobe_planar_display_frag.glsl b/source/blender/draw/engines/eevee/shaders/lightprobe_planar_display_frag.glsl
index c5e57cee718..676f7e49ebf 100644
--- a/source/blender/draw/engines/eevee/shaders/lightprobe_planar_display_frag.glsl
+++ b/source/blender/draw/engines/eevee/shaders/lightprobe_planar_display_frag.glsl
@@ -19,7 +19,7 @@ void main()
 		discard;
 	}
 
-	vec4 refco = pd.reflectionmat * vec4(worldPosition, 1.0);
+	vec4 refco = ViewProjectionMatrix * vec4(worldPosition, 1.0);
 	refco.xy /= refco.w;
-	FragColor = vec4(textureLod(probePlanars, vec3(refco.xy, float(probeIdx)), 0.0).rgb, 1.0);
+	FragColor = vec4(textureLod(probePlanars, vec3(refco.xy * 0.5 + 0.5, float(probeIdx)), 0.0).rgb, 1.0);
 }
diff --git a/source/blender/draw/engines/eevee/shaders/lit_surface_frag.glsl b/source/blender/draw/engines/eevee/shaders/lit_surface_frag.glsl
index 4a1778091f6..c5d44ba684a 100644
--- a/source/blender/draw/engines/eevee/shaders/lit_surface_frag.glsl
+++ b/source/blender/draw/engines/eevee/shaders/lit_surface_frag.glsl
@@ -96,7 +96,7 @@ vec3 eevee_surface_lit(vec3 N, vec3 albedo, vec3 f0, float roughness, float ao,
 		for (int i = 0; i < MAX_PLANAR && i < planar_count && spec_accum.a < 0.999; ++i) {
 			PlanarData pd = planars_data[i];
 
-			float fade = probe_attenuation_planar(pd, worldPosition, N);
+			float fade = probe_attenuation_planar(pd, worldPosition, N, roughness);
 
 			if (fade > 0.0) {
 				vec3 spec = probe_evaluate_planar(float(i), pd, worldPosition, N, V, rand.r, roughness, fade);
@@ -235,7 +235,7 @@ vec3 eevee_surface_clearcoat_lit(
 		PlanarData pd = planars_data[i];
 
 		/* Fade on geometric normal. */
-		float fade = probe_attenuation_planar(pd, worldPosition, worldNormal);
+		float fade = probe_attenuation_planar(pd, worldPosition, worldNormal, roughness);
 
 		if (fade > 0.0) {
 			if (!ssrToggle || ssr_id != outputSsrId) {
@@ -459,7 +459,7 @@ vec3 eevee_surface_glossy_lit(vec3 N, vec3 f0, float roughness, float ao, int ss
 		for (int i = 0; i < MAX_PLANAR && i < planar_count && spec_accum.a < 0.999; ++i) {
 			PlanarData pd = planars_data[i];
 
-			float fade = probe_attenuation_planar(pd, worldPosition, N);
+			float fade = probe_attenuation_planar(pd, worldPosition, N, roughness);
 
 			if (fade > 0.0) {
 				vec3 spec = probe_evaluate_planar(float(i), pd, worldPosition, N, V, rand.r, roughness, fade);




More information about the Bf-blender-cvs mailing list