[Bf-blender-cvs] [5f569378d2d] blender2.8: Eevee: SSR: Derive the brdf bias from the trace quality.

Clément Foucault noreply at git.blender.org
Tue Jan 16 18:22:39 CET 2018


Commit: 5f569378d2d8c3a9f923afb5b94e68862926922d
Author: Clément Foucault
Date:   Tue Jan 16 14:03:31 2018 +0100
Branches: blender2.8
https://developer.blender.org/rB5f569378d2d8c3a9f923afb5b94e68862926922d

Eevee: SSR: Derive the brdf bias from the trace quality.

Also change the range of the trace quality so that the trace actually covers the screen most of the time.

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

M	source/blender/draw/engines/eevee/eevee_private.h
M	source/blender/draw/engines/eevee/eevee_screen_raytrace.c
M	source/blender/draw/engines/eevee/shaders/effect_ssr_frag.glsl

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

diff --git a/source/blender/draw/engines/eevee/eevee_private.h b/source/blender/draw/engines/eevee/eevee_private.h
index e0468687c6e..85878a6acc3 100644
--- a/source/blender/draw/engines/eevee/eevee_private.h
+++ b/source/blender/draw/engines/eevee/eevee_private.h
@@ -499,6 +499,7 @@ typedef struct EEVEE_EffectsInfo {
 	bool ssr_use_normalization;
 	int ssr_neighbor_ofs;
 	int ssr_halfres_ofs[2];
+	float ssr_brdf_bias;
 	float ssr_firefly_fac;
 	float ssr_border_fac;
 	float ssr_max_roughness;
diff --git a/source/blender/draw/engines/eevee/eevee_screen_raytrace.c b/source/blender/draw/engines/eevee/eevee_screen_raytrace.c
index d704668ea79..62f75800e14 100644
--- a/source/blender/draw/engines/eevee/eevee_screen_raytrace.c
+++ b/source/blender/draw/engines/eevee/eevee_screen_raytrace.c
@@ -126,11 +126,12 @@ int EEVEE_screen_raytrace_init(EEVEE_ViewLayerData *UNUSED(sldata), EEVEE_Data *
 		bool prev_trace_full = effects->reflection_trace_full;
 		effects->reflection_trace_full = !BKE_collection_engine_property_value_get_bool(props, "ssr_halfres");
 		effects->ssr_use_normalization = BKE_collection_engine_property_value_get_bool(props, "ssr_normalize_weight");
-		effects->ssr_quality = 1.0f - BKE_collection_engine_property_value_get_float(props, "ssr_quality");
+		effects->ssr_quality = 1.0f - 0.95f * BKE_collection_engine_property_value_get_float(props, "ssr_quality");
 		effects->ssr_thickness = BKE_collection_engine_property_value_get_float(props, "ssr_thickness");
 		effects->ssr_border_fac = BKE_collection_engine_property_value_get_float(props, "ssr_border_fade");
 		effects->ssr_firefly_fac = BKE_collection_engine_property_value_get_float(props, "ssr_firefly_fac");
 		effects->ssr_max_roughness = BKE_collection_engine_property_value_get_float(props, "ssr_max_roughness");
+		effects->ssr_brdf_bias = 0.1f + effects->ssr_quality * 0.6f; /* Range [0.1, 0.7]. */
 
 		if (effects->ssr_firefly_fac < 1e-8f) {
 			effects->ssr_firefly_fac = FLT_MAX;
@@ -221,6 +222,7 @@ void EEVEE_screen_raytrace_cache_init(EEVEE_ViewLayerData *sldata, EEVEE_Data *v
 		DRW_shgroup_uniform_vec4(grp, "ssrParameters", &effects->ssr_quality, 1);
 		DRW_shgroup_uniform_int(grp, "planar_count", &sldata->probes->num_planar, 1);
 		DRW_shgroup_uniform_float(grp, "maxRoughness", &effects->ssr_max_roughness, 1);
+		DRW_shgroup_uniform_float(grp, "brdfBias", &effects->ssr_brdf_bias, 1);
 		DRW_shgroup_uniform_buffer(grp, "planarDepth", &vedata->txl->planar_depth);
 		DRW_shgroup_uniform_block(grp, "planar_block", sldata->planar_ubo);
 		if (!effects->reflection_trace_full) {
@@ -245,6 +247,7 @@ void EEVEE_screen_raytrace_cache_init(EEVEE_ViewLayerData *sldata, EEVEE_Data *v
 		DRW_shgroup_uniform_float(grp, "lodCubeMax", &sldata->probes->lod_cube_max, 1);
 		DRW_shgroup_uniform_float(grp, "lodPlanarMax", &sldata->probes->lod_planar_max, 1);
 		DRW_shgroup_uniform_float(grp, "fireflyFactor", &effects->ssr_firefly_fac, 1);
+		DRW_shgroup_uniform_float(grp, "brdfBias", &effects->ssr_brdf_bias, 1);
 		DRW_shgroup_uniform_block(grp, "probe_block", sldata->probe_ubo);
 		DRW_shgroup_uniform_block(grp, "planar_block", sldata->planar_ubo);
 		DRW_shgroup_uniform_buffer(grp, "probeCubes", &sldata->probe_pool);
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 d615baba161..02911c5793c 100644
--- a/source/blender/draw/engines/eevee/shaders/effect_ssr_frag.glsl
+++ b/source/blender/draw/engines/eevee/shaders/effect_ssr_frag.glsl
@@ -7,9 +7,9 @@
 uniform sampler2DArray utilTex;
 #endif /* UTIL_TEX */
 
-#define BRDF_BIAS 0.7
 #define MAX_MIP 9.0
 
+uniform float brdfBias;
 uniform float fireflyFactor;
 uniform float maxRoughness;
 uniform ivec2 halfresOffset;
@@ -42,13 +42,9 @@ layout(location = 1) out float pdfData;
 
 void do_planar_ssr(int index, vec3 V, vec3 N, vec3 T, vec3 B, vec3 planeNormal, vec3 viewPosition, float a2, vec4 rand)
 {
-	float pdf, NH;
-
-	/* Importance sampling bias */
-	rand.x = mix(rand.x, 0.0, BRDF_BIAS);
-
+	float NH;
 	vec3 H = sample_ggx(rand.xzw, a2, N, T, B, NH); /* Microfacet normal */
-	pdf = pdf_ggx_reflect(NH, a2);
+	float pdf = pdf_ggx_reflect(NH, a2);
 
 	vec3 R = reflect(-V, H);
 	R = reflect(R, planeNormal);
@@ -76,13 +72,9 @@ void do_planar_ssr(int index, vec3 V, vec3 N, vec3 T, vec3 B, vec3 planeNormal,
 
 void do_ssr(vec3 V, vec3 N, vec3 T, vec3 B, vec3 viewPosition, float a2, vec4 rand)
 {
-	float pdf, NH;
-
-	/* Importance sampling bias */
-	rand.x = mix(rand.x, 0.0, BRDF_BIAS);
-
+	float NH;
 	vec3 H = sample_ggx(rand.xzw, a2, N, T, B, NH); /* Microfacet normal */
-	pdf = pdf_ggx_reflect(NH, a2);
+	float pdf = pdf_ggx_reflect(NH, a2);
 
 	vec3 R = reflect(-V, H);
 	pdfData = min(1024e32, pdf); /* Theoretical limit of 16bit float */
@@ -138,6 +130,8 @@ void main()
 	if (roughness < 0.04) {
 		rand.xzw *= 0.0;
 	}
+	/* Importance sampling bias */
+	rand.x = mix(rand.x, 0.0, brdfBias);
 
 	vec3 worldPosition = transform_point(ViewMatrixInverse, viewPosition);
 	vec3 wN = transform_direction(ViewMatrixInverse, N);
@@ -363,7 +357,7 @@ vec4 get_ssr_samples(
 
 	/* Compute cone footprint in screen space. */
 	vec4 cone_footprint = hit_dist * cone_tan;
-	cone_footprint = BRDF_BIAS * 0.5 * cone_footprint * max(ProjectionMatrix[0][0], ProjectionMatrix[1][1]) / homcoord;
+	cone_footprint = brdfBias * 0.5 * cone_footprint * max(ProjectionMatrix[0][0], ProjectionMatrix[1][1]) / homcoord;
 
 	/* Estimate a cone footprint to sample a corresponding mipmap level. */
 	vec4 mip = log2(cone_footprint * max_v2(vec2(textureSize(depthBuffer, 0))));



More information about the Bf-blender-cvs mailing list