-
Notifications
You must be signed in to change notification settings - Fork 3.6k
WIP: Alpha fixes #15573
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
WIP: Alpha fixes #15573
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -725,12 +725,6 @@ export abstract class PBRBaseMaterial extends PushMaterial { | |
| */ | ||
| public _alphaCutOff = 0.4; | ||
|
|
||
| /** | ||
| * Enforces alpha test in opaque or blend mode in order to improve the performances of some situations. | ||
| * @internal | ||
| */ | ||
| public override _forceAlphaTest = false; | ||
|
|
||
| /** | ||
| * A fresnel is applied to the alpha of the model to ensure grazing angles edges are not alpha tested. | ||
| * And/Or occlude the blended part. (alpha is converted to gamma to compute the fresnel) | ||
|
|
@@ -1001,55 +995,38 @@ export abstract class PBRBaseMaterial extends PushMaterial { | |
| return "PBRBaseMaterial"; | ||
| } | ||
|
|
||
| /** | ||
| * Returns true if alpha blending should be disabled. | ||
| */ | ||
| protected override get _disableAlphaBlending(): boolean { | ||
| return ( | ||
| this._transparencyMode === PBRBaseMaterial.PBRMATERIAL_OPAQUE || | ||
| this._transparencyMode === PBRBaseMaterial.PBRMATERIAL_ALPHATEST || | ||
| this.subSurface?.disableAlphaBlending | ||
| ); | ||
| protected _shouldUseAlphaFromAlbedoTexture(): boolean { | ||
| return this._albedoTexture != null && this._albedoTexture.hasAlpha && this._useAlphaFromAlbedoTexture && this._transparencyMode !== PBRBaseMaterial.PBRMATERIAL_OPAQUE; | ||
| } | ||
|
|
||
| /** | ||
| * @returns whether or not this material should be rendered in alpha blend mode. | ||
| */ | ||
| protected override _hasAlpha(mesh: AbstractMesh): boolean { | ||
| return super._hasAlpha(mesh) || this._shouldUseAlphaFromAlbedoTexture() || this._opacityTexture != null; | ||
| } | ||
|
|
||
| /** @override */ | ||
| public override needAlphaBlending(): boolean { | ||
| if (this._disableAlphaBlending) { | ||
| if (this._hasTransparencyMode) { | ||
| return this._transparencyModeIsBlend; | ||
| } | ||
|
|
||
| if (this.subSurface?.disableAlphaBlending) { | ||
| return false; | ||
| } | ||
|
|
||
| return this.alpha < 1.0 || this._opacityTexture != null || this._shouldUseAlphaFromAlbedoTexture(); | ||
| return super.needAlphaBlending(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
| } | ||
|
|
||
| /** | ||
| * @returns whether or not this material should be rendered in alpha test mode. | ||
| */ | ||
| /** @override */ | ||
| public override needAlphaTesting(): boolean { | ||
| if (this._forceAlphaTest) { | ||
| return true; | ||
| if (this._hasTransparencyMode) { | ||
| return this._transparencyModeIsTest; | ||
| } | ||
|
|
||
| if (this.subSurface?.disableAlphaBlending) { | ||
| return false; | ||
| } | ||
|
|
||
| return this._hasAlphaChannel() && (this._transparencyMode == null || this._transparencyMode === PBRBaseMaterial.PBRMATERIAL_ALPHATEST); | ||
| } | ||
|
|
||
| /** | ||
| * @returns whether or not the alpha value of the albedo texture should be used for alpha blending. | ||
| */ | ||
| protected _shouldUseAlphaFromAlbedoTexture(): boolean { | ||
| return this._albedoTexture != null && this._albedoTexture.hasAlpha && this._useAlphaFromAlbedoTexture && this._transparencyMode !== PBRBaseMaterial.PBRMATERIAL_OPAQUE; | ||
| } | ||
|
|
||
| /** | ||
| * @returns whether or not there is a usable alpha channel for transparency. | ||
| */ | ||
| protected _hasAlphaChannel(): boolean { | ||
| return (this._albedoTexture != null && this._albedoTexture.hasAlpha) || this._opacityTexture != null; | ||
| return super.needAlphaTesting(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
| } | ||
|
|
||
| /** | ||
|
|
@@ -1894,7 +1871,7 @@ export abstract class PBRBaseMaterial extends PushMaterial { | |
| this._useLogarithmicDepth, | ||
| this.pointsCloud, | ||
| this.fogEnabled, | ||
| this._shouldTurnAlphaTestOn(mesh) || this._forceAlphaTest, | ||
| this.needAlphaTestingForMesh(mesh), | ||
| defines, | ||
| this._applyDecalMapAfterDetailMap | ||
| ); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -866,47 +866,17 @@ export class StandardMaterial extends PushMaterial { | |
| return "StandardMaterial"; | ||
| } | ||
|
|
||
| /** | ||
| * Specifies if the material will require alpha blending | ||
| * @returns a boolean specifying if alpha blending is needed | ||
| */ | ||
| public override needAlphaBlending(): boolean { | ||
| if (this._disableAlphaBlending) { | ||
| return false; | ||
| } | ||
|
|
||
| return ( | ||
| this.alpha < 1.0 || | ||
| this._opacityTexture != null || | ||
| this._shouldUseAlphaFromDiffuseTexture() || | ||
| (this._opacityFresnelParameters && this._opacityFresnelParameters.isEnabled) | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * Specifies if this material should be rendered in alpha test mode | ||
| * @returns a boolean specifying if an alpha test is needed. | ||
| */ | ||
| public override needAlphaTesting(): boolean { | ||
| if (this._forceAlphaTest) { | ||
| return true; | ||
| } | ||
|
|
||
| return this._hasAlphaChannel() && (this._transparencyMode == null || this._transparencyMode === Material.MATERIAL_ALPHATEST); | ||
| } | ||
|
|
||
| /** | ||
| * @returns whether or not the alpha value of the diffuse texture should be used for alpha blending. | ||
| */ | ||
| protected _shouldUseAlphaFromDiffuseTexture(): boolean { | ||
| return this._diffuseTexture != null && this._diffuseTexture.hasAlpha && this._useAlphaFromDiffuseTexture && this._transparencyMode !== Material.MATERIAL_OPAQUE; | ||
| } | ||
|
|
||
| /** | ||
| * @returns whether or not there is a usable alpha channel for transparency. | ||
| */ | ||
| protected _hasAlphaChannel(): boolean { | ||
| return (this._diffuseTexture != null && this._diffuseTexture.hasAlpha) || this._opacityTexture != null; | ||
| protected override _hasAlpha(mesh: AbstractMesh): boolean { | ||
| return super._hasAlpha(mesh) || this._shouldUseAlphaFromDiffuseTexture() || this._opacityTexture != null; | ||
| } | ||
|
|
||
| /** @override */ | ||
| public override needAlphaBlending(): boolean { | ||
| return super.needAlphaBlending() || this._opacityFresnelParameters?.isEnabled; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As for the PBR material, the checks on |
||
| } | ||
|
|
||
| /** | ||
|
|
@@ -1221,7 +1191,7 @@ export class StandardMaterial extends PushMaterial { | |
| this._useLogarithmicDepth, | ||
| this.pointsCloud, | ||
| this.fogEnabled, | ||
| this._shouldTurnAlphaTestOn(mesh) || this._forceAlphaTest, | ||
| this.needAlphaTestingForMesh(mesh), | ||
| defines, | ||
| this._applyDecalMapAfterDetailMap | ||
| ); | ||
|
|
@@ -1687,7 +1657,7 @@ export class StandardMaterial extends PushMaterial { | |
| BindTextureMatrix(this._opacityTexture, ubo, "opacity"); | ||
| } | ||
|
|
||
| if (this._hasAlphaChannel()) { | ||
| if (this._hasAlpha(mesh)) { | ||
| ubo.updateFloat("alphaCutOff", this.alphaCutOff); | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should be checked first to be backward compatible.