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.
This commit is contained in:
Clément Foucault 2017-11-23 03:39:06 +01:00
parent f3b384862d
commit 16a2802149
2 changed files with 13 additions and 4 deletions

View File

@ -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

View File

@ -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)