blender/intern/cycles/kernel/osl/shaders/node_metallic_bsdf.osl
Amogh Shivaram 2bd06093c7 Cycles: Thin film iridescence for metals
Applies thin film iridescence to metals in Metallic BSDF and Principled BSDF.

To get the complex IOR values for each spectral band from F82 Tint colors,
the code uses the parametrization from "Artist Friendly Metallic Fresnel",
where the g parameter is set to F82. This IOR is used to find the phase shift,
but reflectance is still calculated with the F82 Tint formula after adjusting
F0 for the film's IOR.

Co-authored-by: Lukas Stockner <lukas@lukasstockner.de>
Co-authored-by: Weizhen Huang <weizhen@blender.org>
Co-authored-by: RobertMoerland <rmoerlandrj@gmail.com>
Pull Request: https://projects.blender.org/blender/blender/pulls/141131
2025-09-29 02:58:20 +02:00

65 lines
2.3 KiB
Text

/* 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,
float ThinFilmThickness = 0.0,
float ThinFilmIOR = 1.33,
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,
"thinfilm_thickness",
ThinFilmThickness,
"thinfilm_ior",
ThinFilmIOR);
}
else {
BSDF = conductor_bsdf(Normal,
T,
alpha_x,
alpha_y,
max(IOR, 0.0),
max(Extinction, 0.0),
distribution,
"thinfilm_thickness",
ThinFilmThickness,
"thinfilm_ior",
ThinFilmIOR);
}
}