Add Metallic BSDF Node to the shader editor. This node can primarily be used to create more realistic looking metallic materials than the existing Glossy BSDF node. This commit does not add any new closures to Cycles, it simply exposes existing closures that were previous hard to access on their own. - Exposes the F82 fresnel type that is currently used by the metallic component of the Principled BSDF. Results should match between the Metallic BSDF and Principled BSDF when using the same settings. - Exposes the Physical Conductor fresnel type that was previously limited to custom OSL scripts. The Conductor fresnel type accepts IOR and Extinction coefficients to define the appearance of the material based off real life measurements. EEVEE only supports the F82 fresnel type with internal code to convert the the physical conductor inputs in to a colour format for F82, which can lead to noticeable rendering differences with some configurations. Pull Request: https://projects.blender.org/blender/blender/pulls/114958
45 lines
1.6 KiB
Plaintext
45 lines
1.6 KiB
Plaintext
/* SPDX-FileCopyrightText: 2024 Blender Foundation
|
|
*
|
|
* SPDX-License-Identifier: Apache-2.0 */
|
|
|
|
#include "node_fresnel.h"
|
|
#include "stdcycles.h"
|
|
|
|
shader node_metallic_bsdf(color BaseColor = color(0.617, 0.577, 0.540),
|
|
color EdgeTint = color(0.695, 0.726, 0.770),
|
|
vector IOR = vector(2.757, 2.513, 2.231),
|
|
vector Extinction = vector(3.867, 3.404, 3.009),
|
|
string distribution = "multi_ggx",
|
|
string fresnel_type = "f82",
|
|
float Roughness = 0.5,
|
|
float Anisotropy = 0.0,
|
|
float Rotation = 0.0,
|
|
normal Normal = N,
|
|
normal Tangent = 0.0,
|
|
output closure color BSDF = 0)
|
|
{
|
|
float r2 = clamp(Roughness, 0.0, 1.0);
|
|
r2 *= r2;
|
|
float alpha_x = r2, alpha_y = r2;
|
|
|
|
/* Handle anisotropy. */
|
|
vector T = Tangent;
|
|
if (Anisotropy > 0.0) {
|
|
float aspect = sqrt(1.0 - clamp(Anisotropy, 0.0, 1.0) * 0.9);
|
|
alpha_x /= aspect;
|
|
alpha_y *= aspect;
|
|
if (Rotation != 0.0)
|
|
T = rotate(T, Rotation * M_2PI, point(0.0, 0.0, 0.0), Normal);
|
|
}
|
|
|
|
if (fresnel_type == "f82") {
|
|
color F0 = clamp(BaseColor, color(0.0), color(1.0));
|
|
color F82 = clamp(EdgeTint, color(0.0), color(1.0));
|
|
BSDF = microfacet_f82_tint(distribution, Normal, T, alpha_x, alpha_y, F0, F82);
|
|
}
|
|
else {
|
|
BSDF = conductor_bsdf(
|
|
Normal, T, alpha_x, alpha_y, max(IOR, 0.0), max(Extinction, 0.0), distribution);
|
|
}
|
|
}
|