[Bf-blender-cvs] [846cdf53187] blender2.8: Eevee : SSS : Add Translucency support.

Clément Foucault noreply at git.blender.org
Wed Nov 22 04:53:42 CET 2017


Commit: 846cdf53187174ac87dd24af4b7b0d413db4ad03
Author: Clément Foucault
Date:   Wed Nov 22 04:51:21 2017 +0100
Branches: blender2.8
https://developer.blender.org/rB846cdf53187174ac87dd24af4b7b0d413db4ad03

Eevee : SSS : Add Translucency support.

This adds the possibility to simulate things like red ears with strong backlight or material with high scattering distances.

To enable it you need to turn on the "Subsurface Translucency" option in the "Options" tab of the Material Panel (and of course to have "regular" SSS enabled in both render settings and material options).
Since the effect is adding another overhead I prefer to make it optional. But this is open to discussion.

Be aware that the effect only works for direct lights (so no indirect/world lighting) that have shadowmaps, and is affected by the "softness" of the shadowmap and resolution.

Technical notes:

This is inspired by http://www.iryoku.com/translucency/ but goes a bit beyond that.
We do not use a sum of gaussian to apply in regards to the object thickness but we precompute a 1D kernel texture.
This texture stores the light transmited to a point at the back of an infinite slab of material of variying thickness.
We make the assumption that the slab is perpendicular to the light so that no fresnel or diffusion term is taken into account.
The light is considered constant.
If the setup is similar to the one assume during the profile baking, the realtime render matches cycles reference.
Due to these assumptions the computed transmitted light is in most cases too bright for curvy objects.

Finally we jitter the shadow map sample per pixel so we can simulate dispersion inside the medium.
Radius of the dispersion is in world space and derived by from the "soft" shadowmap parameter.
Idea for this come from this presentation http://www.iryoku.com/stare-into-the-future (slide 164).

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

M	release/scripts/startup/bl_ui/properties_material.py
M	source/blender/draw/engines/eevee/eevee_lights.c
M	source/blender/draw/engines/eevee/eevee_materials.c
M	source/blender/draw/engines/eevee/eevee_private.h
M	source/blender/draw/engines/eevee/eevee_subsurface.c
M	source/blender/draw/engines/eevee/shaders/bsdf_common_lib.glsl
M	source/blender/draw/engines/eevee/shaders/effect_subsurface_frag.glsl
M	source/blender/draw/engines/eevee/shaders/lamps_lib.glsl
M	source/blender/draw/engines/eevee/shaders/lit_surface_frag.glsl
M	source/blender/gpu/GPU_material.h
M	source/blender/gpu/intern/gpu_material.c
M	source/blender/gpu/shaders/gpu_shader_material.glsl
M	source/blender/makesdna/DNA_material_types.h
M	source/blender/makesrna/intern/rna_material.c

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

diff --git a/release/scripts/startup/bl_ui/properties_material.py b/release/scripts/startup/bl_ui/properties_material.py
index b914bafaf3f..9aed338bad4 100644
--- a/release/scripts/startup/bl_ui/properties_material.py
+++ b/release/scripts/startup/bl_ui/properties_material.py
@@ -1178,7 +1178,7 @@ class EEVEE_MATERIAL_PT_options(MaterialButtonsPanel, Panel):
 
             row = layout.row()
             row.active = ((mat.blend_method == "CLIP") or (mat.transparent_shadow_method == "CLIP"))
-            layout.prop(mat, "alpha_threshold")
+            row.prop(mat, "alpha_threshold")
 
         if mat.blend_method not in {"OPAQUE", "CLIP", "HASHED"}:
             layout.prop(mat, "transparent_hide_backside")
@@ -1187,6 +1187,9 @@ class EEVEE_MATERIAL_PT_options(MaterialButtonsPanel, Panel):
         layout.prop(mat, "refraction_depth")
 
         layout.prop(mat, "use_screen_subsurface")
+        row = layout.row()
+        row.active = mat.use_screen_subsurface
+        row.prop(mat, "use_sss_translucency")
 
 
 classes = (
diff --git a/source/blender/draw/engines/eevee/eevee_lights.c b/source/blender/draw/engines/eevee/eevee_lights.c
index 09a090955c2..17295713001 100644
--- a/source/blender/draw/engines/eevee/eevee_lights.c
+++ b/source/blender/draw/engines/eevee/eevee_lights.c
@@ -530,6 +530,7 @@ static void eevee_shadow_cube_setup(Object *ob, EEVEE_LampsInfo *linfo, EEVEE_La
 	ubo_data->shadow_start = (float)(sh_data->layer_id);
 	ubo_data->data_start = (float)(sh_data->cube_id);
 	ubo_data->multi_shadow_count = (float)(sh_nbr);
+	ubo_data->shadow_blur = la->soft * 0.02f; /* Used by translucence shadowmap blur */
 
 	ubo_data->contact_dist = (la->mode & LA_SHAD_CONTACT) ? la->contact_dist : 0.0f;
 	ubo_data->contact_bias = 0.05f * la->contact_bias;
@@ -777,6 +778,7 @@ static void eevee_shadow_cascade_setup(Object *ob, EEVEE_LampsInfo *linfo, EEVEE
 	ubo_data->shadow_start = (float)(sh_data->layer_id);
 	ubo_data->data_start = (float)(sh_data->cascade_id);
 	ubo_data->multi_shadow_count = (float)(sh_nbr);
+	ubo_data->shadow_blur = la->soft * 0.02f; /* Used by translucence shadowmap blur */
 
 	ubo_data->contact_dist = (la->mode & LA_SHAD_CONTACT) ? la->contact_dist : 0.0f;
 	ubo_data->contact_bias = 0.05f * la->contact_bias;
diff --git a/source/blender/draw/engines/eevee/eevee_materials.c b/source/blender/draw/engines/eevee/eevee_materials.c
index dbd953553cd..4a9633b4f44 100644
--- a/source/blender/draw/engines/eevee/eevee_materials.c
+++ b/source/blender/draw/engines/eevee/eevee_materials.c
@@ -307,6 +307,9 @@ static char *eevee_get_defines(int options)
 	if ((options & VAR_MAT_SSS) != 0) {
 		BLI_dynstr_appendf(ds, "#define USE_SSS\n");
 	}
+	if ((options & VAR_MAT_TRANSLUC) != 0) {
+		BLI_dynstr_appendf(ds, "#define USE_TRANSLUCENCY\n");
+	}
 	if ((options & VAR_MAT_VSM) != 0) {
 		BLI_dynstr_appendf(ds, "#define SHADOW_VSM\n");
 	}
@@ -636,7 +639,7 @@ struct GPUMaterial *EEVEE_material_world_volume_get(struct Scene *scene, World *
 
 struct GPUMaterial *EEVEE_material_mesh_get(
         struct Scene *scene, Material *ma, EEVEE_Data *vedata,
-        bool use_blend, bool use_multiply, bool use_refract, bool use_sss, int shadow_method)
+        bool use_blend, bool use_multiply, bool use_refract, bool use_sss, bool use_translucency, int shadow_method)
 {
 	const void *engine = &DRW_engine_viewport_eevee_type;
 	int options = VAR_MAT_MESH;
@@ -645,6 +648,7 @@ struct GPUMaterial *EEVEE_material_mesh_get(
 	if (use_multiply) options |= VAR_MAT_MULT;
 	if (use_refract) options |= VAR_MAT_REFRACT;
 	if (use_sss) options |= VAR_MAT_SSS;
+	if (use_translucency) options |= VAR_MAT_TRANSLUC;
 	if (vedata->stl->effects->use_volumetrics && use_blend) options |= VAR_MAT_VOLUME;
 
 	options |= eevee_material_shadow_option(shadow_method);
@@ -977,6 +981,7 @@ static void material_opaque(
 	const bool use_gpumat = (ma->use_nodes && ma->nodetree);
 	const bool use_refract = ((ma->blend_flag & MA_BL_SS_REFRACTION) != 0) && ((stl->effects->enabled_effects & EFFECT_REFRACT) != 0);
 	const bool use_sss = ((ma->blend_flag & MA_BL_SS_SUBSURFACE) != 0) && ((stl->effects->enabled_effects & EFFECT_SSS) != 0);
+	const bool use_translucency = ((ma->blend_flag & MA_BL_TRANSLUCENCY) != 0) && ((stl->effects->enabled_effects & EFFECT_SSS) != 0);
 
 	EeveeMaterialShadingGroups *emsg = BLI_ghash_lookup(material_hash, (const void *)ma);
 
@@ -987,7 +992,7 @@ static void material_opaque(
 
 		/* This will have been created already, just perform a lookup. */
 		*gpumat = (use_gpumat) ? EEVEE_material_mesh_get(
-		        scene, ma, vedata, false, false, use_refract, use_sss, linfo->shadow_method) : NULL;
+		        scene, ma, vedata, false, false, use_refract, use_sss, use_translucency, linfo->shadow_method) : NULL;
 		*gpumat_depth = (use_gpumat) ? EEVEE_material_mesh_depth_get(
 		        scene, ma, (ma->blend_method == MA_BM_HASHED), false) : NULL;
 		return;
@@ -995,7 +1000,8 @@ static void material_opaque(
 
 	if (use_gpumat) {
 		/* Shading */
-		*gpumat = EEVEE_material_mesh_get(scene, ma, vedata, false, false, use_refract, use_sss, linfo->shadow_method);
+		*gpumat = EEVEE_material_mesh_get(scene, ma, vedata, false, false, use_refract,
+		                                  use_sss, use_translucency, linfo->shadow_method);
 
 		*shgrp = DRW_shgroup_material_create(*gpumat,
 		                                     (use_refract) ? psl->refract_pass :
@@ -1007,9 +1013,17 @@ static void material_opaque(
 			add_standard_uniforms(*shgrp, sldata, vedata, ssr_id, &ma->refract_depth, use_refract, false);
 
 			if (use_sss) {
+				struct GPUTexture *sss_tex_profile = NULL;
 				struct GPUUniformBuffer *sss_profile = GPU_material_sss_profile_get(*gpumat,
-				                                                                    stl->effects->sss_sample_count);
+				                                                                    stl->effects->sss_sample_count,
+				                                                                    &sss_tex_profile);
+
 				if (sss_profile) {
+					if (use_translucency) {
+						DRW_shgroup_uniform_block(*shgrp, "sssProfile", sss_profile);
+						DRW_shgroup_uniform_texture(*shgrp, "sssTexProfile", sss_tex_profile);
+					}
+
 					DRW_shgroup_stencil_mask(*shgrp, e_data.sss_count + 1);
 					EEVEE_subsurface_add_pass(vedata, e_data.sss_count + 1, sss_profile);
 					e_data.sss_count++;
@@ -1099,7 +1113,7 @@ static void material_transparent(
 	if (ma->use_nodes && ma->nodetree) {
 		/* Shading */
 		*gpumat = EEVEE_material_mesh_get(scene, ma, vedata, true, (ma->blend_method == MA_BM_MULTIPLY), use_refract,
-		                                  false, linfo->shadow_method);
+		                                  false, false, linfo->shadow_method);
 
 		*shgrp = DRW_shgroup_material_create(*gpumat, psl->transparent_pass);
 		if (*shgrp) {
diff --git a/source/blender/draw/engines/eevee/eevee_private.h b/source/blender/draw/engines/eevee/eevee_private.h
index b1ed108bad0..6a3adb36a7c 100644
--- a/source/blender/draw/engines/eevee/eevee_private.h
+++ b/source/blender/draw/engines/eevee/eevee_private.h
@@ -116,6 +116,7 @@ enum {
 	VAR_MAT_REFRACT  = (1 << 12),
 	VAR_MAT_VOLUME   = (1 << 13),
 	VAR_MAT_SSS      = (1 << 14),
+	VAR_MAT_TRANSLUC = (1 << 15),
 };
 
 /* Shadow Technique */
@@ -280,7 +281,7 @@ typedef struct EEVEE_Light {
 
 typedef struct EEVEE_Shadow {
 	float near, far, bias, exp;
-	float shadow_start, data_start, multi_shadow_count, pad;
+	float shadow_start, data_start, multi_shadow_count, shadow_blur;
 	float contact_dist, contact_bias, contact_spread, contact_thickness;
 } EEVEE_Shadow;
 
@@ -639,7 +640,7 @@ struct GPUMaterial *EEVEE_material_world_background_get(struct Scene *scene, str
 struct GPUMaterial *EEVEE_material_world_volume_get(struct Scene *scene, struct World *wo);
 struct GPUMaterial *EEVEE_material_mesh_get(
         struct Scene *scene, Material *ma, EEVEE_Data *vedata,
-        bool use_blend, bool use_multiply, bool use_refract, bool use_sss, int shadow_method);
+        bool use_blend, bool use_multiply, bool use_refract, bool use_sss, bool use_translucency, int shadow_method);
 struct GPUMaterial *EEVEE_material_mesh_volume_get(struct Scene *scene, Material *ma);
 struct GPUMaterial *EEVEE_material_mesh_depth_get(struct Scene *scene, Material *ma, bool use_hashed_alpha, bool is_shadow);
 struct GPUMaterial *EEVEE_material_hair_get(struct Scene *scene, Material *ma, int shadow_method);
diff --git a/source/blender/draw/engines/eevee/eevee_subsurface.c b/source/blender/draw/engines/eevee/eevee_subsurface.c
index 6827d44aea4..fe6e77ddf29 100644
--- a/source/blender/draw/engines/eevee/eevee_subsurface.c
+++ b/source/blender/draw/engines/eevee/eevee_subsurface.c
@@ -123,7 +123,6 @@ void EEVEE_subsurface_add_pass(EEVEE_Data *vedata, unsigned int sss_id, struct G
 	DRW_shgroup_uniform_buffer(grp, "depthBuffer", &dtxl->depth);
 	DRW_shgroup_uniform_buffer(grp, "sssData", &txl->sss_data);
 	DRW_shgroup_uniform_block(grp, "sssProfile", sss_profile);
-	DRW_shgroup_uniform_int(grp, "sampleCount", &effects->sss_sample_count, 1);
 	DRW_shgroup_uniform_float(grp, "jitterThreshold", &effects->sss_jitter_threshold, 1);
 	DRW_shgroup_stencil_mask(grp, sss_id);
 	DRW_shgroup_call_add(grp, quad, NULL);
@@ -134,7 +133,6 @@ void EEVEE_subsurface_add_pass(EEVEE_Data *vedata, unsigned int sss_id, struct G
 	DRW_shgroup_uniform_buffer(grp, "depthBuffer", &dtxl->depth);
 	DRW_shgroup_uniform_buffer(grp, "sssData", &txl->sss_blur);
 	DRW_shgroup_uniform_block(grp, "sssProfile", sss_profile);
-	DRW_shgroup_uniform_int(grp, "sampleCount", &effects->sss_sample_count, 1);
 	DRW_shgroup_uniform_float(grp, "jitterThreshold", &effects->sss_jitter_threshold, 1);
 	DRW_shgroup_stencil_mask(grp, sss_id);
 	DRW_shgroup_call_add(grp, quad, NULL);
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 bd6c1923bfe..32d27838da3 100644
--- a/source/blender/draw/engines/eevee/shaders/bsdf_common_lib.glsl
+++ b/source/blender/draw/engines/eevee/shaders/bsdf_common_lib.glsl
@@ -103,6 +103,7 @@ struct ShadowCascadeData {
 #define sh_tex_start    shadow_data_start_end.x


@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list