fix: expose mesh-level shader defines to the fragment shader#8817
Merged
Conversation
Object/mesh-level shader defines (INSTANCING, SKIN, BATCH, MORPHING*, SCREENSPACE) were only declared in the vertex shader, so user chunk overrides could not branch on them in the fragment shader. Expose them to both shader stages via a shared helper, and deduplicate the mesh-define logic in the ShaderMaterial generator. Purely additive: built-in shader output is unchanged. Fixes #8815
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a limitation in shader generation where mesh/object-level shader defines (derived from MeshInstance shader defs) were only emitted for the vertex stage, preventing user fragment chunk overrides from branching on them (fixes #8815).
Changes:
- Exposes mesh/object-level defines to both vertex and fragment stages for
LitShaderprograms. - Refactors
LitShaderdefine emission via a newsharedDefineSet()helper to keep stage define maps in sync. - Refactors
ShaderMaterialprogram generation to centralize mesh/object-level define emission and apply it to both vertex and fragment definitions.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/scene/shader-lib/programs/shader-generator-shader.js | Adds a shared define helper so ShaderMaterial-generated programs expose mesh/object defines in both VS and FS. |
| src/scene/shader-lib/programs/lit-shader.js | Adds sharedDefineSet() and routes mesh/object-level defines through it so fragment shaders can see them too. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Object/mesh-level shader defines derived from MeshInstance shader defs were only declared in the vertex shader, so user chunk overrides could not branch on them in the fragment shader (issue #8815).
Changes:
INSTANCING,SKIN,BATCH,MORPHING/MORPHING_INT/MORPHING_POSITION/MORPHING_NORMAL,SCREENSPACE) are now exposed to both the vertex and fragment shaders.LitShader: added asharedDefineSet()helper (mirrorsfDefineSet) that writes to both the vertex and fragment define maps, and routed the object-level defines through it.addSharedDefines()method, now applied to both the vertex and fragment definitions.PIXELSNAPremains vertex-only (a transform-stage option, not a mesh property).This is purely additive: these defines are only consumed by built-in vertex chunks today, so no existing shader output changes — the symbols simply become available to user chunk overrides (e.g.
#if INSTANCINGindiffusePS).Fixes #8815