Eevee: Ssr: Add ssr id to glossy nodes.
An id is given to each glossy node in order to determine which specular lobe is using ssr.
This commit is contained in:
@@ -24,7 +24,7 @@ in vec3 viewNormal;
|
||||
|
||||
/* ----------- default ----------- */
|
||||
|
||||
vec3 eevee_surface_lit(vec3 N, vec3 albedo, vec3 f0, float roughness, float ao)
|
||||
vec3 eevee_surface_lit(vec3 N, vec3 albedo, vec3 f0, float roughness, float ao, float ssr_id)
|
||||
{
|
||||
/* Zero length vectors cause issues, see: T51979. */
|
||||
#if 0
|
||||
@@ -166,7 +166,7 @@ vec3 eevee_surface_lit(vec3 N, vec3 albedo, vec3 f0, float roughness, float ao)
|
||||
vec3 eevee_surface_clearcoat_lit(
|
||||
vec3 N, vec3 albedo, vec3 f0, float roughness,
|
||||
vec3 C_N, float C_intensity, float C_roughness, /* Clearcoat params */
|
||||
float ao)
|
||||
float ao, float ssr_id)
|
||||
{
|
||||
roughness = clamp(roughness, 1e-8, 0.9999);
|
||||
float roughnessSquared = roughness * roughness;
|
||||
|
||||
@@ -2824,13 +2824,13 @@ void node_bsdf_principled(vec4 base_color, float subsurface, vec3 subsurface_rad
|
||||
|
||||
void node_bsdf_principled_simple(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, out Closure result)
|
||||
float clearcoat_roughness, float ior, float transmission, float transmission_roughness, vec3 N, vec3 CN, vec3 T, vec3 I, float ssr_id, out Closure result)
|
||||
{
|
||||
#ifdef EEVEE_ENGINE
|
||||
vec3 diffuse, f0;
|
||||
convert_metallic_to_specular_tinted(base_color.rgb, metallic, specular, specular_tint, diffuse, f0);
|
||||
|
||||
result = Closure(eevee_surface_lit(N, diffuse, f0, roughness, 1.0), 1.0);
|
||||
result = Closure(eevee_surface_lit(N, diffuse, f0, roughness, 1.0, ssr_id), 1.0);
|
||||
#else
|
||||
node_bsdf_principled(base_color, subsurface, subsurface_radius, subsurface_color, metallic, specular,
|
||||
specular_tint, roughness, anisotropic, anisotropic_rotation, sheen, sheen_tint, clearcoat,
|
||||
@@ -2840,7 +2840,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, out Closure result)
|
||||
float clearcoat_roughness, float ior, float transmission, float transmission_roughness, vec3 N, vec3 CN, vec3 T, vec3 I, float ssr_id, out Closure result)
|
||||
{
|
||||
#ifdef EEVEE_ENGINE
|
||||
vec3 diffuse, f0;
|
||||
@@ -2865,13 +2865,13 @@ void node_bsdf_principled_clearcoat(vec4 base_color, float subsurface, vec3 subs
|
||||
N = tangent_to_world(Ht, N, Y, X);
|
||||
|
||||
if (dot(N, cameraVec) > 0) {
|
||||
surface_color.rgb += eevee_surface_clearcoat_lit(N, diffuse, f0, sqrt(min(ax, ay)), CN, clearcoat, clearcoat_roughness, 1.0);
|
||||
surface_color.rgb += eevee_surface_clearcoat_lit(N, diffuse, f0, sqrt(min(ax, ay)), CN, clearcoat, clearcoat_roughness, 1.0, ssr_id);
|
||||
surface_color.a += 1.0;
|
||||
}
|
||||
}
|
||||
result = Closure(surface_color.rgb / surface_color.a, 1.0);
|
||||
#else
|
||||
result = Closure(eevee_surface_clearcoat_lit(N, diffuse, f0, roughness, CN, clearcoat, clearcoat_roughness, 1.0), 1.0);
|
||||
result = Closure(eevee_surface_clearcoat_lit(N, diffuse, f0, roughness, CN, clearcoat, clearcoat_roughness, 1.0, ssr_id), 1.0);
|
||||
#endif
|
||||
|
||||
#else
|
||||
@@ -4013,20 +4013,20 @@ void world_normals_get(out vec3 N)
|
||||
void node_eevee_metallic(
|
||||
vec4 basecol, float metallic, float specular, float roughness, vec4 emissive, float transp, vec3 normal,
|
||||
float clearcoat, float clearcoat_roughness, vec3 clearcoat_normal,
|
||||
float occlusion, out Closure result)
|
||||
float occlusion, float ssr_id, out Closure result)
|
||||
{
|
||||
vec3 diffuse, f0;
|
||||
convert_metallic_to_specular(basecol.rgb, metallic, specular, diffuse, f0);
|
||||
|
||||
result = Closure(eevee_surface_lit(normal, diffuse, f0, roughness, occlusion) + emissive.rgb, 1.0 - transp);
|
||||
result = Closure(eevee_surface_lit(normal, diffuse, f0, roughness, occlusion, ssr_id) + emissive.rgb, 1.0 - transp);
|
||||
}
|
||||
|
||||
void node_eevee_specular(
|
||||
vec4 diffuse, vec4 specular, float roughness, vec4 emissive, float transp, vec3 normal,
|
||||
float clearcoat, float clearcoat_roughness, vec3 clearcoat_normal,
|
||||
float occlusion, out Closure result)
|
||||
float occlusion, float ssr_id, out Closure result)
|
||||
{
|
||||
result = Closure(eevee_surface_lit(normal, diffuse.rgb, specular.rgb, roughness, occlusion) + emissive.rgb, 1.0 - transp);
|
||||
result = Closure(eevee_surface_lit(normal, diffuse.rgb, specular.rgb, roughness, occlusion, ssr_id) + emissive.rgb, 1.0 - transp);
|
||||
}
|
||||
|
||||
void node_output_eevee_material(Closure surface, out Closure result)
|
||||
|
||||
@@ -214,8 +214,11 @@ typedef struct bNode {
|
||||
* and replacing all uses with per-instance data.
|
||||
*/
|
||||
short preview_xsize, preview_ysize; /* reserved size of the preview rect */
|
||||
int pad2;
|
||||
short pad2[2];
|
||||
struct uiBlock *block; /* runtime during drawing */
|
||||
|
||||
float ssr_id; /* XXX: eevee only, id of screen space reflection layer, needs to be a float to feed GPU_uniform. */
|
||||
float pad3;
|
||||
} bNode;
|
||||
|
||||
/* node->flag */
|
||||
|
||||
@@ -475,6 +475,48 @@ static void ntree_shader_relink_displacement(bNodeTree *ntree,
|
||||
ntreeUpdateTree(G.main, ntree);
|
||||
}
|
||||
|
||||
static bool ntree_tag_ssr_bsdf_cb(bNode *fromnode, bNode *UNUSED(tonode), void *userdata, const bool UNUSED(reversed))
|
||||
{
|
||||
switch (fromnode->type) {
|
||||
case SH_NODE_BSDF_ANISOTROPIC:
|
||||
case SH_NODE_EEVEE_METALLIC:
|
||||
case SH_NODE_EEVEE_SPECULAR:
|
||||
case SH_NODE_BSDF_PRINCIPLED:
|
||||
case SH_NODE_BSDF_GLOSSY:
|
||||
fromnode->ssr_id = (*(float *)userdata);
|
||||
(*(float *)userdata) += 1;
|
||||
break;
|
||||
default:
|
||||
/* We could return false here but since we (will)
|
||||
* allow the use of Closure as RGBA, we can have
|
||||
* Bsdf nodes linked to other Bsdf nodes. */
|
||||
break;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/* EEVEE: Scan the ntree to set the Screen Space Reflection
|
||||
* layer id of every specular node.
|
||||
*/
|
||||
static void ntree_shader_tag_ssr_node(bNodeTree *ntree, short compatibility)
|
||||
{
|
||||
if (compatibility != NODE_NEWER_SHADING) {
|
||||
/* We can only deal with new shading system here. */
|
||||
return;
|
||||
}
|
||||
|
||||
bNode *output_node = ntree_shader_output_node(ntree);
|
||||
if (output_node == NULL) {
|
||||
return;
|
||||
}
|
||||
/* Make sure sockets links pointers are correct. */
|
||||
ntreeUpdateTree(G.main, ntree);
|
||||
|
||||
int lobe_count = 0;
|
||||
nodeChainIter(ntree, output_node, ntree_tag_ssr_bsdf_cb, &lobe_count, true);
|
||||
}
|
||||
|
||||
void ntreeGPUMaterialNodes(bNodeTree *ntree, GPUMaterial *mat, short compatibility)
|
||||
{
|
||||
/* localize tree to create links for reroute and mute */
|
||||
@@ -486,6 +528,8 @@ void ntreeGPUMaterialNodes(bNodeTree *ntree, GPUMaterial *mat, short compatibili
|
||||
*/
|
||||
ntree_shader_relink_displacement(localtree, compatibility);
|
||||
|
||||
ntree_shader_tag_ssr_node(localtree, compatibility);
|
||||
|
||||
exec = ntreeShaderBeginExecTree(localtree);
|
||||
ntreeExecGPUNodes(exec, mat, 1, compatibility);
|
||||
ntreeShaderEndExecTree(exec);
|
||||
|
||||
@@ -100,10 +100,10 @@ static int node_shader_gpu_bsdf_principled(GPUMaterial *mat, bNode *node, bNodeE
|
||||
|
||||
/* Only use complex versions when needed. */
|
||||
if (!in[12].link && (in[12].vec[0] == 0.0f)) {
|
||||
return GPU_stack_link(mat, node, "node_bsdf_principled_simple", in, out, GPU_builtin(GPU_VIEW_POSITION));
|
||||
return GPU_stack_link(mat, node, "node_bsdf_principled_simple", in, out, GPU_builtin(GPU_VIEW_POSITION), GPU_uniform(&node->ssr_id));
|
||||
}
|
||||
else {
|
||||
return GPU_stack_link(mat, node, "node_bsdf_principled_clearcoat", in, out, GPU_builtin(GPU_VIEW_POSITION));
|
||||
return GPU_stack_link(mat, node, "node_bsdf_principled_clearcoat", in, out, GPU_builtin(GPU_VIEW_POSITION), GPU_uniform(&node->ssr_id));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -68,7 +68,7 @@ static int node_shader_gpu_eevee_metallic(GPUMaterial *mat, bNode *node, bNodeEx
|
||||
GPU_link(mat, "set_value", GPU_uniform(&one), &in[10].link);
|
||||
}
|
||||
|
||||
return GPU_stack_link(mat, node, "node_eevee_metallic", in, out);
|
||||
return GPU_stack_link(mat, node, "node_eevee_metallic", in, out, GPU_uniform(&node->ssr_id));
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -67,7 +67,7 @@ static int node_shader_gpu_eevee_specular(GPUMaterial *mat, bNode *node, bNodeEx
|
||||
GPU_link(mat, "set_value", GPU_uniform(&one), &in[9].link);
|
||||
}
|
||||
|
||||
return GPU_stack_link(mat, node, "node_eevee_specular", in, out);
|
||||
return GPU_stack_link(mat, node, "node_eevee_specular", in, out, GPU_uniform(&node->ssr_id));
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user