[Bf-blender-cvs] [16a28021493] blender2.8: Eevee: SSS: Principled Shader: Add a workaround the lack of scale input

Clément Foucault noreply at git.blender.org
Fri Nov 24 06:47:43 CET 2017


Commit: 16a28021493d5a54efff5e6aade39f7b015366cd
Author: Clément Foucault
Date:   Thu Nov 23 03:39:06 2017 +0100
Branches: blender2.8
https://developer.blender.org/rB16a28021493d5a54efff5e6aade39f7b015366cd

Eevee: SSS: Principled Shader: Add a workaround the lack of scale input

This is a hack to make the user control the SSS radius even though the profile is baked with the default radius values.

This is completly against UI principles since you cannot edit the profile radiuses while there is something plugged into the radius socket.
Better solution will be to either have a dedicated node value for RGB radiuses and a SSS scale socket only for eevee.

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

M	source/blender/gpu/shaders/gpu_shader_material.glsl
M	source/blender/nodes/shader/nodes/node_shader_bsdf_principled.c

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

diff --git a/source/blender/gpu/shaders/gpu_shader_material.glsl b/source/blender/gpu/shaders/gpu_shader_material.glsl
index 5d0ca35cc1f..c3345f51b4c 100644
--- a/source/blender/gpu/shaders/gpu_shader_material.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_material.glsl
@@ -2895,7 +2895,7 @@ void node_bsdf_principled_simple(vec4 base_color, float subsurface, vec3 subsurf
 void node_bsdf_principled_clearcoat(vec4 base_color, float subsurface, vec3 subsurface_radius, vec4 subsurface_color, float metallic, float specular,
 	float specular_tint, float roughness, float anisotropic, float anisotropic_rotation, float sheen, float sheen_tint, float clearcoat,
 	float clearcoat_roughness, float ior, float transmission, float transmission_roughness, vec3 N, vec3 CN, vec3 T, vec3 I, float ssr_id,
-	float sss_id, out Closure result)
+	float sss_id, vec3 sss_scale, out Closure result)
 {
 #ifdef EEVEE_ENGINE
 	if (clearcoat == 0.0) {
@@ -2953,10 +2953,10 @@ void node_bsdf_principled_clearcoat(vec4 base_color, float subsurface, vec3 subs
 
 #ifdef USE_SSS
 	/* OPTI : Make irradiance computation shared with the diffuse. */
-	result.sss_data.rgb = eevee_surface_translucent_lit(N, subsurface_color.rgb, 1.0);
+	result.sss_data.a = dot(sss_scale, vec3(1.0 / 3.0));
+	result.sss_data.rgb = eevee_surface_translucent_lit(N, subsurface_color.rgb, result.sss_data.a);
 	result.sss_data.rgb += eevee_surface_diffuse_lit(N, vec3(1.0), 1.0);
 	result.sss_data.rgb *= mix(vec3(0.0), subsurface_color.rgb, subsurface);
-	result.sss_data.a = 1.0; /* TODO Find a parametrization */
 #endif
 
 #endif
diff --git a/source/blender/nodes/shader/nodes/node_shader_bsdf_principled.c b/source/blender/nodes/shader/nodes/node_shader_bsdf_principled.c
index aa2b3bbfc32..b0ca4128d19 100644
--- a/source/blender/nodes/shader/nodes/node_shader_bsdf_principled.c
+++ b/source/blender/nodes/shader/nodes/node_shader_bsdf_principled.c
@@ -65,6 +65,7 @@ static void node_shader_init_principled(bNodeTree *UNUSED(ntree), bNode *node)
 
 static int node_shader_gpu_bsdf_principled(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
 {
+	GPUNodeLink *sss_scale;
 #if 0 /* Old 2.7 glsl viewport */
 	// normal
 	if (!in[17].link)
@@ -107,8 +108,16 @@ static int node_shader_gpu_bsdf_principled(GPUMaterial *mat, bNode *node, bNodeE
 		GPU_material_sss_profile_create(mat, &socket_data->value[1], &profile, NULL);
 	}
 
+	if (in[2].link) {
+		sss_scale = in[2].link;
+	}
+	else {
+		float one[3] = {1.0f, 1.0f, 1.0f};
+		GPU_link(mat, "set_rgb", GPU_uniform((float *)one), &sss_scale);
+	}
+
 	return GPU_stack_link(mat, node, "node_bsdf_principled_clearcoat", in, out, GPU_builtin(GPU_VIEW_POSITION),
-	                      GPU_uniform(&node->ssr_id), GPU_uniform(&node->sss_id));
+	                      GPU_uniform(&node->ssr_id), GPU_uniform(&node->sss_id), sss_scale);
 }
 
 static void node_shader_update_principled(bNodeTree *UNUSED(ntree), bNode *node)



More information about the Bf-blender-cvs mailing list