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

Enable alpha test when using vertex alpha in some cases #15504

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions packages/dev/core/src/Layers/effectLayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,7 @@ export abstract class EffectLayer {

// Diffuse
if (material) {
const needAlphaTest = material.needAlphaTesting();
const needAlphaTest = material.needAlphaTestingForMesh(mesh);

const diffuseTexture = material.getAlphaTestTexture();
const needAlphaBlendFromDiffuse =
Expand Down Expand Up @@ -986,7 +986,7 @@ export abstract class EffectLayer {
}

if (!renderingMaterial) {
const needAlphaTest = material.needAlphaTesting();
const needAlphaTest = material.needAlphaTestingForMesh(effectiveMesh);

const diffuseTexture = material.getAlphaTestTexture();
const needAlphaBlendFromDiffuse =
Expand Down
2 changes: 1 addition & 1 deletion packages/dev/core/src/Lights/Shadows/shadowGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1563,7 +1563,7 @@ export class ShadowGenerator implements IShadowGenerator {
}

// Alpha test
const needAlphaTesting = material.needAlphaTesting();
const needAlphaTesting = material.needAlphaTestingForMesh(mesh);

if (needAlphaTesting || material.needAlphaBlending()) {
if (this.useOpacityTextureForTransparentShadow) {
Expand Down
11 changes: 10 additions & 1 deletion packages/dev/core/src/Materials/material.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1147,13 +1147,22 @@ export class Material implements IAnimatable, IClipPlanesHolder {
return false;
}

/**
* Specifies whether or not this material should be rendered in alpha test mode when used with the given mesh.
* @param mesh defines the mesh to check
* @returns a boolean specifying if an alpha test is needed.
*/
public needAlphaTestingForMesh(mesh: AbstractMesh): boolean {
return mesh.hasVertexAlpha || this.needAlphaTesting();
}

/**
* Specifies if material alpha testing should be turned on for the mesh
* @param mesh defines the mesh to check
* @returns a boolean specifying if alpha testing should be turned on for the mesh
*/
protected _shouldTurnAlphaTestOn(mesh: AbstractMesh): boolean {
return !this.needAlphaBlendingForMesh(mesh) && this.needAlphaTesting();
return !this.needAlphaBlendingForMesh(mesh) && this.needAlphaTestingForMesh(mesh);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ export class VolumetricLightScatteringPostProcess extends PostProcess {

// Alpha test
if (material) {
if (material.needAlphaTesting()) {
if (material.needAlphaTestingForMesh(mesh)) {
defines.push("#define ALPHATEST");
}

Expand Down Expand Up @@ -463,7 +463,7 @@ export class VolumetricLightScatteringPostProcess extends PostProcess {
effect.setMatrix("viewProjection", scene.getTransformMatrix());

// Alpha test
if (material.needAlphaTesting()) {
if (material.needAlphaTestingForMesh(effectiveMesh)) {
const alphaTexture = material.getAlphaTestTexture();

if (alphaTexture) {
Expand Down
4 changes: 2 additions & 2 deletions packages/dev/core/src/Rendering/depthRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ export class DepthRenderer {

if (!renderingMaterial) {
// Alpha test
if (material.needAlphaTesting()) {
if (material.needAlphaTestingForMesh(effectiveMesh)) {
const alphaTexture = material.getAlphaTestTexture();

if (alphaTexture) {
Expand Down Expand Up @@ -404,7 +404,7 @@ export class DepthRenderer {
const attribs = [VertexBuffer.PositionKind];

// Alpha test
if (material.needAlphaTesting() && material.getAlphaTestTexture()) {
if (material.needAlphaTestingForMesh(mesh) && material.getAlphaTestTexture()) {
defines.push("#define ALPHATEST");
if (mesh.isVerticesDataPresent(VertexBuffer.UVKind)) {
attribs.push(VertexBuffer.UVKind);
Expand Down
4 changes: 2 additions & 2 deletions packages/dev/core/src/Rendering/geometryBufferRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ export class GeometryBufferRenderer {
if (material) {
let needUv = false;
// Alpha test
if (material.needAlphaTesting() && material.getAlphaTestTexture()) {
if (material.needAlphaTestingForMesh(mesh) && material.getAlphaTestTexture()) {
defines.push("#define ALPHATEST");
defines.push(`#define ALPHATEST_UV${material.getAlphaTestTexture().coordinatesIndex + 1}`);
needUv = true;
Expand Down Expand Up @@ -951,7 +951,7 @@ export class GeometryBufferRenderer {
material._preBind(drawWrapper, sideOrientation);

// Alpha test
if (material.needAlphaTesting()) {
if (material.needAlphaTestingForMesh(effectiveMesh)) {
const alphaTexture = material.getAlphaTestTexture();
if (alphaTexture) {
effect.setTexture("diffuseSampler", alphaTexture);
Expand Down
4 changes: 2 additions & 2 deletions packages/dev/core/src/Rendering/outlineRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ export class OutlineRenderer implements ISceneComponent {
}

// Alpha test
if (material && material.needAlphaTesting()) {
if (material && material.needAlphaTestingForMesh(effectiveMesh)) {
const alphaTexture = material.getAlphaTestTexture();
if (alphaTexture) {
effect.setTexture("diffuseSampler", alphaTexture);
Expand Down Expand Up @@ -288,7 +288,7 @@ export class OutlineRenderer implements ISceneComponent {
const scene = mesh.getScene();

// Alpha test
if (material.needAlphaTesting()) {
if (material.needAlphaTestingForMesh(mesh)) {
defines.push("#define ALPHATEST");
if (mesh.isVerticesDataPresent(VertexBuffer.UVKind)) {
attribs.push(VertexBuffer.UVKind);
Expand Down
2 changes: 1 addition & 1 deletion packages/dev/core/src/Rendering/renderingGroup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ export class RenderingGroup {
if (material.needAlphaBlendingForMesh(mesh)) {
// Transparent
this._transparentSubMeshes.push(subMesh);
} else if (material.needAlphaTesting()) {
} else if (material.needAlphaTestingForMesh(mesh)) {
// Alpha test
if (material.needDepthPrePass) {
this._depthOnlySubMeshes.push(subMesh);
Expand Down
Loading