CesiumGS / CesiumGS/cesium

Custom Shader - detect `material.alpha` instead of `isTranslucent` flag?

Open
#10,604 3 comments 0 reactions 0 assignees View on GitHub
category - model/gltf
Dominant language
JavaScript
Stars
15.7k
Forks
3.9k
Avg merge
4d 6h
Merged PRs (30d)
34

Description

Right now, when using a `CustomShader` with `ModelExperimental`, `material.alpha` only affects the translucency when `CustomShader.isTranslucent` is set `true` in the constructor.

This seems to be non-obvious. Another way this could be addressed is to check for the presence of `material.alpha` in the shader text (this should already be parsed in `customShader.usedVariablesFragment.materialSet` and if set, change the pass to translucent. This would replace the check in `CustomShaderPipelineStage` to something along the lines of this:

```
if (materialSet.hasOwnProperty('alpha')) {
alphaOptions.pass = Pass.TRANSLUCENT;
} else {
alphaOptions.pass = undefined;
}
```

Note that this would not be able to detect that `material.alpha = 1.0` would be opaque since in general the result will be an expression evaluated on the GPU.

Contributor guide

Open the contributing guide

Research direction

Start by reading CustomShaderPipelineStage and the customShader.usedVariablesFragment.materialSet entry point described in the issue. Trace how material.alpha usage currently affects alphaOptions.pass, then verify the expected translucent behavior while preserving the stated limitation that GPU expressions such as material.alpha = 1.0 cannot be classified as opaque.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
computer-graphics
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.