Skip to content

Commit

Permalink
fix: sheen
Browse files Browse the repository at this point in the history
  • Loading branch information
hhhhkrx committed Dec 11, 2024
1 parent d1dda0c commit 5604310
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
18 changes: 9 additions & 9 deletions packages/core/src/material/PBRMaterial.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export class PBRMaterial extends PBRBaseMaterial {
private static _iridescenceTextureProp = ShaderProperty.getByName("material_IridescenceTexture");
private _iridescenceRange = new Vector2(100, 400);

private _sheen: boolean = false;
private _sheenEnabled = false;
private static _sheenColorProp = ShaderProperty.getByName("material_SheenColor");
private static _sheenRoughnessProp = ShaderProperty.getByName("material_SheenRoughness");
private static _sheenTextureProp = ShaderProperty.getByName("material_SheenTexture");
Expand Down Expand Up @@ -196,7 +196,7 @@ export class PBRMaterial extends PBRBaseMaterial {

/**
* The range of iridescence thickness, x is minimum, y is maximum.
* @defaultValue `[100, 400]`.
* @defaultValue `[100, 400]`
*/
get iridescenceThicknessRange(): Vector2 {
return this._iridescenceRange;
Expand Down Expand Up @@ -229,7 +229,7 @@ export class PBRMaterial extends PBRBaseMaterial {
}

/**
* Sheen color
* Sheen color.
* @defaultValue `[0,0,0]`
*/
get sheenColor(): Color {
Expand All @@ -256,7 +256,7 @@ export class PBRMaterial extends PBRBaseMaterial {
}

Check warning on line 256 in packages/core/src/material/PBRMaterial.ts

View check run for this annotation

Codecov / codecov/patch

packages/core/src/material/PBRMaterial.ts#L255-L256

Added lines #L255 - L256 were not covered by tests

/**
* Sheencolor texture, multiply ‘sheencolor’.
* SheenColor texture, multiply ‘sheenColor’.
*/
get sheenColorTexture(): Texture2D {
return <Texture2D>this.shaderData.getTexture(PBRMaterial._sheenTextureProp);
Expand All @@ -272,6 +272,7 @@ export class PBRMaterial extends PBRBaseMaterial {
}

Check warning on line 272 in packages/core/src/material/PBRMaterial.ts

View check run for this annotation

Codecov / codecov/patch

packages/core/src/material/PBRMaterial.ts#L266-L272

Added lines #L266 - L272 were not covered by tests

/**
* SheenRoughness texture.
* @remarks Use alpha channel, and multiply 'sheenRoughness'.
*/
get sheenRoughnessTexture(): Texture2D {
Expand Down Expand Up @@ -300,21 +301,20 @@ export class PBRMaterial extends PBRBaseMaterial {
shaderData.setFloat(PBRMaterial._iorProp, 1.5);
shaderData.setVector3(PBRMaterial._anisotropyInfoProp, new Vector3(1, 0, 0));
shaderData.setVector4(PBRMaterial._iridescenceInfoProp, new Vector4(0, 1.3, 100, 400));
shaderData.setColor(PBRMaterial._sheenColorProp, new Color(0, 0, 0, 0));
shaderData.setColor(PBRMaterial._sheenColorProp, new Color(0, 0, 0));
// @ts-ignore
this._iridescenceRange._onValueChanged = this._onIridescenceRangeChanged.bind(this);
// @ts-ignore
this.sheenColor._onValueChanged = () => {
const r = this.sheenColor.r;
const g = this.sheenColor.g;
const b = this.sheenColor.b;
const a = this.sheenColor.a;
/**
* The sheen layer switch.
*/
const enableSheen = (r + g + b) * a > 0;
if (enableSheen !== this._sheen) {
this._sheen = enableSheen;
const enableSheen = r + g + b > 0;
if (enableSheen !== this._sheenEnabled) {
this._sheenEnabled = enableSheen;
if (enableSheen) {
this.shaderData.enableMacro("MATERIAL_ENABLE_SHEEN");
} else {
Expand Down
3 changes: 2 additions & 1 deletion packages/loader/src/gltf/extensions/KHR_materials_sheen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ class KHR_materials_sheen extends GLTFExtensionParser {
material.sheenColor.set(
Color.linearToGammaSpace(sheenColorFactor[0]),
Color.linearToGammaSpace(sheenColorFactor[1]),
Color.linearToGammaSpace(sheenColorFactor[2])
Color.linearToGammaSpace(sheenColorFactor[2]),
undefined
);
}

Expand Down

0 comments on commit 5604310

Please sign in to comment.