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

Fix glTF mask #18579

Merged
merged 7 commits into from
Feb 13, 2020
Merged
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
6 changes: 6 additions & 0 deletions examples/js/loaders/GLTFLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -2107,6 +2107,12 @@ THREE.GLTFLoader = ( function () {

materialParams.alphaTest = materialDef.alphaCutoff !== undefined ? materialDef.alphaCutoff : 0.5;

} else {

// for ALPHA_MODES.OPAQUE, we use a negative alphaTest value to enable alphaTesting,
// causing the test to always be passed, but also replacing any alpha value with 1.0.
materialParams.alphaTest = - 0.5;

}

}
Expand Down
6 changes: 6 additions & 0 deletions examples/jsm/loaders/GLTFLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -2172,6 +2172,12 @@ var GLTFLoader = ( function () {

materialParams.alphaTest = materialDef.alphaCutoff !== undefined ? materialDef.alphaCutoff : 0.5;

} else {

// for ALPHA_MODES.OPAQUE, we use a negative alphaTest value to enable alphaTesting,
// causing the test to always be passed, but also replacing any alpha value with 1.0.
materialParams.alphaTest = - 0.5;

}

}
Expand Down
67 changes: 67 additions & 0 deletions examples/models/gltf/AlphaBlendModeTest/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# Alpha Blend Mode Test

## Screenshot

![screenshot](screenshot/screenshot_large.jpg)

## Description

This model tests the various alpha modes available in glTF 2.0. There are three settings for `alphaMode`: `"OPAQUE"` (the default), `"BLEND"`, and `"MASK"`. Of these, `"MASK"` takes an additional `alphaCutoff` value that modifies it.

## `OPAQUE` vs `BLEND`

![screenshot](screenshot/OpaqueVsBlend.jpg)

The box on the far left uses the default alphaMode, `OPAQUE`. Although the texturemap supplies an alpha channel, the alpha values are intentionally ignored here.

The next box shows the effects of alpha blending. The texture contains a linear alpha ramp inside a black border, along with some labels. At the bottom there are green check marks and hidden red X's, that will show check marks only when the requested mode is correctly applied.

## Problem: Alpha Values Used in Opaque Mode

![screenshot](screenshot/OpaqueFail.jpg)

The above screenshot shows what typically happens if a rendering engine decides to process alpha values from a texturemap without blending being specifically requested. This is a test failure, and should be corrected in the engine.

Note that a red "X" mark has appeared next to `OPAQUE`, due to a green checkmark with zero alpha values being blended away.

# Problem: Lack of Alpha Blending

![screenshot](screenshot/BlendFail.jpg)

In the above screenshot, it appears that alpha blending is not available, or not enabled when a model requests it. This is also a test failure, and could be due to a missing feature or other issues in the rendering engine.

Note that a red "X" mark has appeared next to `BLEND`. This "X" has zero alpha values, and should be blended away, revealing a green checkmark behind it.

## `MASK` and `alphaCutoff`

![screenshot](screenshot/CutoffTests.jpg)

This model tests `MASK` mode with the default value, shown in the middle box of three in the above screenshot, surrounded by cutoff values of `0.25` and `0.75`.

Because the alpha values in the box are a smooth linear ramp, we can expect the contents to be cut off at the corresponding values, as indicated by the green triangles.

Note that alpha blending should not be applied here: Each texel is either fully opaque or discarded. Depth buffering with writes enabled may be used in `MASK` mode.

## Known Mipmapping Issues

![screenshot](screenshot/MissingBorder.png)

When a texture gets farther from the camera, a process called mipmapping may be used to blend texels (texturemap pixels) together. This particular test model has a very thin opaque border adjacent to a lot of transparent texels. When mipmapping blends these together, the resulting alpha values can land in the middle someplace. Setting a high alpha mask cutoff value can cause these blended texels to be discarded. This is not considered a failure for the purpose of this particular test. However, if you see this effect in your own models, you may wish to set a lower cutoff value or increase the thickness of the affected area.

## Problem: `alphaCutoff` Not Respected

![screenshot](screenshot/CutoffValueFail.jpg)

In the above screenshot, the requested `alphaCutoff` value is not being respected, and the default value of `0.5` appears to be applied regardless of the setting. This is a test failure.

## Problem: No Default Cutoff

![screenshot](screenshot/CutoffDefaultFail.jpg)

In this screenshot, it appears that the rendering engine is not using the value `0.5` for the default value of `alphaCutoff` when the model does not specify a particular value. The glTF specification [names `0.5` as the default](https://github.com/KhronosGroup/glTF/blob/0890b76c62cc762ce82d4010df9bfebb1634839b/specification/2.0/schema/material.schema.json#L68), so this is a test failure.

## License Information

Copyright 2018 Analytical Graphics, Inc.
CC-BY 4.0 https://creativecommons.org/licenses/by/4.0/
Model and textures by Ed Mackey.
Binary file not shown.
Loading