Clamp some of the inputs of the Glossy BSDF, Glass BSDF, Sheen BSDF, and Subsurface Scattering nodes to improve consistency between render engines and to avoid unexpected results. * Clamp roughness to 0..1 * Clamp subsurface radius to 0..inf * Clamp colors to 0..inf Pull Request: https://projects.blender.org/blender/blender/pulls/120390
51 lines
1.5 KiB
Plaintext
51 lines
1.5 KiB
Plaintext
/* SPDX-FileCopyrightText: 2011-2022 Blender Foundation
|
|
*
|
|
* SPDX-License-Identifier: Apache-2.0 */
|
|
|
|
#include "node_fresnel.h"
|
|
#include "stdcycles.h"
|
|
|
|
shader node_glossy_bsdf(color Color = 0.8,
|
|
string distribution = "ggx",
|
|
float Roughness = 0.2,
|
|
float Anisotropy = 0.0,
|
|
float Rotation = 0.0,
|
|
normal Normal = N,
|
|
normal Tangent = 0.0,
|
|
output closure color BSDF = 0)
|
|
{
|
|
/* compute roughness */
|
|
color base_color = max(Color, color(0.0));
|
|
float roughness = clamp(Roughness, 0.0, 1.0);
|
|
roughness = roughness * roughness;
|
|
float roughness_u, roughness_v;
|
|
float aniso = clamp(Anisotropy, -0.99, 0.99);
|
|
|
|
/* rotate tangent around normal */
|
|
vector T = Tangent;
|
|
|
|
if (abs(aniso) <= 1e-4) {
|
|
roughness_u = roughness;
|
|
roughness_v = roughness;
|
|
}
|
|
else {
|
|
if (Rotation != 0.0)
|
|
T = rotate(T, Rotation * M_2PI, point(0.0, 0.0, 0.0), Normal);
|
|
|
|
if (aniso < 0.0) {
|
|
roughness_u = roughness / (1.0 + aniso);
|
|
roughness_v = roughness * (1.0 + aniso);
|
|
}
|
|
else {
|
|
roughness_u = roughness * (1.0 - aniso);
|
|
roughness_v = roughness / (1.0 - aniso);
|
|
}
|
|
}
|
|
|
|
if (distribution == "Multiscatter GGX")
|
|
BSDF = base_color *
|
|
microfacet_multi_ggx_aniso(Normal, T, roughness_u, roughness_v, base_color);
|
|
else
|
|
BSDF = base_color * microfacet(distribution, Normal, T, roughness_u, roughness_v, 0.0, 0);
|
|
}
|