From 7eddbc415f9a5270dd1007e5537b3452cfde540e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20G=C3=BCnther?= Date: Mon, 23 Sep 2024 14:01:14 +0200 Subject: [PATCH] Principled material: option to disable multiplication of metallic by specular --- CHANGELOG.md | 3 +++ doc/api.md | 2 ++ modules/cpu/render/materials/Principled.cpp | 2 ++ modules/cpu/render/materials/Principled.ispc | 3 ++- modules/cpu/render/materials/PrincipledShared.h | 2 ++ 5 files changed, 11 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ad6820677..86faef336 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,9 @@ Version History of the first *non-specular* hit for denoising) - Channel `OSP_FB_POSITION` holds the world-space position of the first hit - Improved sampling of layered materials +- New parameter `specularMetallic` for the Principled material to + optionally disable the incluence of `specular` to metallicness, + improving compatibility with glTF `KHR_materials_specular` ### Changes in v3.2.0: diff --git a/doc/api.md b/doc/api.md index 0d6dfb1c9..6e98822ab 100644 --- a/doc/api.md +++ b/doc/api.md @@ -1977,6 +1977,8 @@ listed in the table below. float specular 1 specular reflection/transmission weight in [0–1] + bool specularMetallic true whether specular influences metallic + float ior 1 dielectric index of refraction float transmission 0 specular transmission weight in [0–1] diff --git a/modules/cpu/render/materials/Principled.cpp b/modules/cpu/render/materials/Principled.cpp index b470660f1..62ea8b72a 100644 --- a/modules/cpu/render/materials/Principled.cpp +++ b/modules/cpu/render/materials/Principled.cpp @@ -39,6 +39,7 @@ void Principled::commit() metallic = getMaterialParam1f("metallic", 0.f); diffuse = getMaterialParam1f("diffuse", 1.f); specular = getMaterialParam1f("specular", 1.f); + bool specularMetallic = getParam("specularMetallic", true); ior = getMaterialParam1f("ior", 1.f); transmission = getMaterialParam1f("transmission", 0.f); transmissionColor = getMaterialParam3f("transmissionColor", vec3f(1.f)); @@ -88,6 +89,7 @@ void Principled::commit() getSh()->diffuse = diffuse.factor; getSh()->diffuseMap = diffuse.tex; getSh()->specular = specular.factor; + getSh()->specularMetallic = specularMetallic; getSh()->specularMap = specular.tex; getSh()->ior = ior.factor; getSh()->iorMap = ior.tex; diff --git a/modules/cpu/render/materials/Principled.ispc b/modules/cpu/render/materials/Principled.ispc index 68d33a045..7f1e3569d 100644 --- a/modules/cpu/render/materials/Principled.ispc +++ b/modules/cpu/render/materials/Principled.ispc @@ -308,7 +308,8 @@ SYCL_EXTERNAL const varying BSDF *uniform Principled_getBSDF( } // conductor base - const float conductor = metallic * specular; + const float conductor = + metallic * (self->specularMetallic ? specular : 1.0f); if (conductor > EPS) { const vec3f edgeColor = clamp( self->edgeColor * get3f(self->edgeColorMap, dg, make_vec3f(1.f))); diff --git a/modules/cpu/render/materials/PrincipledShared.h b/modules/cpu/render/materials/PrincipledShared.h index 693658770..1e2336ce1 100644 --- a/modules/cpu/render/materials/PrincipledShared.h +++ b/modules/cpu/render/materials/PrincipledShared.h @@ -32,6 +32,7 @@ struct Principled // specular weight in [0, 1] float specular; TextureParam specularMap; + bool specularMetallic; // index of refraction float ior; @@ -132,6 +133,7 @@ struct Principled metallic(0.f), diffuse(1.f), specular(1.f), + specularMetallic(true), ior(1.f), transmission(0.f), transmissionColor(1.f),