Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pbr support transmission #2478

Merged
merged 39 commits into from
Dec 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
dd09252
feat: shaderlab pbr support refraction
hhhhkrx Dec 18, 2024
1fc002e
fix: disableMacro
hhhhkrx Dec 19, 2024
adfdfec
fix: name
hhhhkrx Dec 19, 2024
62844aa
Merge branch 'dev/1.4' of github.com:galacean/engine into refraction
hhhhkrx Dec 20, 2024
ffa2912
fix: refraction mode
hhhhkrx Dec 20, 2024
1fc63b2
fix: keep iridescenceRange unified
hhhhkrx Dec 20, 2024
bab9582
fix: refraction
hhhhkrx Dec 20, 2024
174e0e7
fix: refraction
hhhhkrx Dec 20, 2024
47fb197
fix: refraction mode
hhhhkrx Dec 20, 2024
f9b748c
fix: refraction
hhhhkrx Dec 24, 2024
4ef6387
Merge branch 'dev/1.4' of github.com:galacean/engine into refraction
hhhhkrx Dec 24, 2024
76b40b1
fix: refraction
hhhhkrx Dec 24, 2024
3abe5c1
fix: refraction
hhhhkrx Dec 24, 2024
b81bbeb
fix: refraction
hhhhkrx Dec 24, 2024
bcc9daf
fix: refraction
hhhhkrx Dec 24, 2024
b9b9558
fix: refraction
hhhhkrx Dec 24, 2024
9d8a37e
Merge branch 'dev/1.4' of github.com:galacean/engine into refraction
hhhhkrx Dec 24, 2024
84e2f0d
fix: refraction mode
hhhhkrx Dec 24, 2024
e977cbc
fix: refraction mode
hhhhkrx Dec 24, 2024
4040c26
fix: refraction shader
hhhhkrx Dec 24, 2024
420566d
fix: refraction
hhhhkrx Dec 24, 2024
4a3ce3e
fix: refraction mode
hhhhkrx Dec 24, 2024
6b19600
fix: refraction
hhhhkrx Dec 24, 2024
129ac02
fix: refraction value
hhhhkrx Dec 24, 2024
1ff952d
fix: refraction
hhhhkrx Dec 24, 2024
0093886
Merge branch 'dev/1.4' of github.com:galacean/engine into refraction
hhhhkrx Dec 25, 2024
cf77ec4
feat: transmission
hhhhkrx Dec 25, 2024
2764f86
feat: transmission
hhhhkrx Dec 25, 2024
141095a
fix: transmission name
hhhhkrx Dec 26, 2024
36c994c
fix: refraction name
hhhhkrx Dec 26, 2024
2928dcc
fix: refraction mode
hhhhkrx Dec 26, 2024
26c7fd5
fix: refraction mode
hhhhkrx Dec 26, 2024
dd6e0ec
fix: refraction mode
hhhhkrx Dec 26, 2024
e9f3480
fix: specular name
hhhhkrx Dec 26, 2024
d12ff04
fix: specular name
hhhhkrx Dec 26, 2024
9338ec2
fix: diffuseColor mix refraction
hhhhkrx Dec 26, 2024
730548b
fix: diffuse and specular light
hhhhkrx Dec 26, 2024
0a776c4
fix: btdf
hhhhkrx Dec 26, 2024
ce75450
refactor: opt code
GuoLei1990 Dec 26, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
106 changes: 57 additions & 49 deletions packages/core/src/material/BaseMaterial.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@
protected static _emissiveColorProp: ShaderProperty = ShaderProperty.getByName("material_EmissiveColor");
protected static _emissiveTextureProp: ShaderProperty = ShaderProperty.getByName("material_EmissiveTexture");

private static _alphaCutoffProp: ShaderProperty = ShaderProperty.getByName("material_AlphaCutoff");
protected static _alphaCutoffProp: ShaderProperty = ShaderProperty.getByName("material_AlphaCutoff");
private static _alphaCutoffMacro: ShaderMacro = ShaderMacro.getByName("MATERIAL_IS_ALPHA_CUTOFF");

private _renderFace: RenderFace = RenderFace.Front;
private _isTransparent: boolean = false;
protected _isTransparent: boolean = false;
private _blendMode: BlendMode = BlendMode.Normal;

/**
Expand Down Expand Up @@ -73,24 +73,7 @@
}

set isTransparent(value: boolean) {
if (value !== this._isTransparent) {
this.setIsTransparent(0, value);

const { shaderData } = this;
if (value) {
// Use alpha test queue to simulate transparent shadow
shaderData.setFloat(BaseMaterial._shadowCasterRenderQueueProp, RenderQueueType.AlphaTest);
} else {
const alphaCutoff = shaderData.getFloat(BaseMaterial._alphaCutoffProp);
if (alphaCutoff) {
shaderData.setFloat(BaseMaterial._shadowCasterRenderQueueProp, RenderQueueType.AlphaTest);
} else {
shaderData.setFloat(BaseMaterial._shadowCasterRenderQueueProp, RenderQueueType.Opaque);
}
}

this._isTransparent = value;
}
this._seIsTransparent(value);
}

/**
Expand Down Expand Up @@ -119,35 +102,7 @@
}

set alphaCutoff(value: number) {
const { shaderData } = this;
if (shaderData.getFloat(BaseMaterial._alphaCutoffProp) !== value) {
if (value) {
shaderData.enableMacro(BaseMaterial._alphaCutoffMacro);
shaderData.setFloat(BaseMaterial._shadowCasterRenderQueueProp, RenderQueueType.AlphaTest);
} else {
shaderData.disableMacro(BaseMaterial._alphaCutoffMacro);
if (this._isTransparent) {
shaderData.setFloat(BaseMaterial._shadowCasterRenderQueueProp, RenderQueueType.AlphaTest);
} else {
shaderData.setFloat(BaseMaterial._shadowCasterRenderQueueProp, RenderQueueType.Opaque);
}
}

const { renderStates } = this;
for (let i = 0, n = renderStates.length; i < n; i++) {
const renderState = renderStates[i];
if (value > 0) {
renderState.renderQueueType = renderState.blendState.targetBlendState.enabled
? RenderQueueType.Transparent
: RenderQueueType.AlphaTest;
} else {
renderState.renderQueueType = renderState.blendState.targetBlendState.enabled
? RenderQueueType.Transparent
: RenderQueueType.Opaque;
}
}
shaderData.setFloat(BaseMaterial._alphaCutoffProp, value);
}
this._setAlphaCutoff(value);
}

/**
Expand Down Expand Up @@ -279,4 +234,57 @@
target._isTransparent = this._isTransparent;
target._blendMode = this._blendMode;
}

protected _seIsTransparent(value: boolean): void {
if (value !== this._isTransparent) {
this.setIsTransparent(0, value);

const { shaderData } = this;
if (value) {
// Use alpha test queue to simulate transparent shadow
shaderData.setFloat(BaseMaterial._shadowCasterRenderQueueProp, RenderQueueType.AlphaTest);
} else {
const alphaCutoff = shaderData.getFloat(BaseMaterial._alphaCutoffProp);
if (alphaCutoff) {
shaderData.setFloat(BaseMaterial._shadowCasterRenderQueueProp, RenderQueueType.AlphaTest);
} else {
shaderData.setFloat(BaseMaterial._shadowCasterRenderQueueProp, RenderQueueType.Opaque);
}
}

Check warning on line 253 in packages/core/src/material/BaseMaterial.ts

View check run for this annotation

Codecov / codecov/patch

packages/core/src/material/BaseMaterial.ts#L247-L253

Added lines #L247 - L253 were not covered by tests

this._isTransparent = value;
}
}

protected _setAlphaCutoff(value: number): void {
const { shaderData } = this;
if (shaderData.getFloat(BaseMaterial._alphaCutoffProp) !== value) {
if (value) {
shaderData.enableMacro(BaseMaterial._alphaCutoffMacro);
shaderData.setFloat(BaseMaterial._shadowCasterRenderQueueProp, RenderQueueType.AlphaTest);
} else {
shaderData.disableMacro(BaseMaterial._alphaCutoffMacro);
if (this._isTransparent) {
shaderData.setFloat(BaseMaterial._shadowCasterRenderQueueProp, RenderQueueType.AlphaTest);
} else {
shaderData.setFloat(BaseMaterial._shadowCasterRenderQueueProp, RenderQueueType.Opaque);
}
}

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

View check run for this annotation

Codecov / codecov/patch

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

Added lines #L266 - L272 were not covered by tests

const { renderStates } = this;
for (let i = 0, n = renderStates.length; i < n; i++) {
const renderState = renderStates[i];
if (value > 0) {
renderState.renderQueueType = renderState.blendState.targetBlendState.enabled
? RenderQueueType.Transparent
: RenderQueueType.AlphaTest;
} else {
renderState.renderQueueType = renderState.blendState.targetBlendState.enabled
? RenderQueueType.Transparent
: RenderQueueType.Opaque;
}

Check warning on line 285 in packages/core/src/material/BaseMaterial.ts

View check run for this annotation

Codecov / codecov/patch

packages/core/src/material/BaseMaterial.ts#L282-L285

Added lines #L282 - L285 were not covered by tests
}
shaderData.setFloat(BaseMaterial._alphaCutoffProp, value);
}
}
}
Loading
Loading