Skip to content

Commit

Permalink
Principled material: option to disable multiplication of metallic by …
Browse files Browse the repository at this point in the history
…specular
  • Loading branch information
johguenther committed Sep 23, 2024
1 parent 5e5b0b4 commit 7eddbc4
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
2 changes: 2 additions & 0 deletions doc/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
2 changes: 2 additions & 0 deletions modules/cpu/render/materials/Principled.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<bool>("specularMetallic", true);
ior = getMaterialParam1f("ior", 1.f);
transmission = getMaterialParam1f("transmission", 0.f);
transmissionColor = getMaterialParam3f("transmissionColor", vec3f(1.f));
Expand Down Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion modules/cpu/render/materials/Principled.ispc
Original file line number Diff line number Diff line change
Expand Up @@ -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)));
Expand Down
2 changes: 2 additions & 0 deletions modules/cpu/render/materials/PrincipledShared.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ struct Principled
// specular weight in [0, 1]
float specular;
TextureParam specularMap;
bool specularMetallic;

// index of refraction
float ior;
Expand Down Expand Up @@ -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),
Expand Down

0 comments on commit 7eddbc4

Please sign in to comment.