Fix particle system with unlit mesh emitter#7795
Open
liamdon wants to merge 2 commits intoplaycanvas:mainfrom
Open
Fix particle system with unlit mesh emitter#7795liamdon wants to merge 2 commits intoplaycanvas:mainfrom
liamdon wants to merge 2 commits intoplaycanvas:mainfrom
Conversation
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR restores rendering of unlit mesh particle emitters by decoupling the normal‐mapping flag from lighting and introducing a separate LIGHTING define.
- Add a
LIGHTINGdefine in shader generation when lighting is enabled - Guard shading blocks in both WGSL and GLSL shaders with
LIGHTING && NORMAL != NONE - Update
ParticleMaterialto supplylightingand to use vertex normals for unlit mesh emitters
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/scene/shader-lib/wgsl/chunks/particle/frag/particle-shader.js | Only run lighting shading when LIGHTING is defined |
| src/scene/shader-lib/glsl/chunks/particle/frag/particle-shader.js | Mirror WGSL change in GLSL |
| src/scene/shader-lib/programs/particle.js | Set LIGHTING define based on emitter option |
| src/scene/particle-system/particle-material.js | Pass new lighting flag and adjust normal for unlit meshes |
Comments suppressed due to low confidence (2)
src/scene/particle-system/particle-material.js:48
- This new branch (
lighting === false && useMesh === true) handles unlit mesh normals. Consider adding a dedicated test case to verify that unlit mesh particles render correctly with vertex normals when lighting is off.
normal: emitter.lighting ? ((emitter.normalMap !== null) ? 2 : 1) : (this.emitter.useMesh ? 1 : 0),
src/scene/shader-lib/wgsl/chunks/particle/frag/particle-shader.js:45
- Using
#if LIGHTINGwith a define that has no explicit numeric value can lead to preprocessor ambiguity. Consider using#ifdef LIGHTINGor definingLIGHTINGas1to ensure the condition is evaluated as intended.
#if LIGHTING && NORMAL != NONE
Contributor
I have not checked in detail, but is particle shader using normals for any other reason? |
Contributor
|
Anything left preventing this from being merged? |
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.
Currently, mesh particle emitters with
lighting: falsewill not render in either WebGL2 or WebGPU. For a repro, look at https://playcanvas.vercel.app/#/graphics/particles-mesh and toggle thelightingoption.I think the main issue is that we are using the
NORMALdefine as a proxy for whether to use lighting, but in the case of an unlit mesh we do want mesh normals, we just don't want that mesh to be shaded.This PR restores rendering for unlit mesh emitters by:
Try the latest preview deployment on this PR and you will see that now, on the particles-mesh example, particles are still rendered when
lightingis off. We can also see that the shading on those particles is flat. If you reduce the directional light intensity to 0.01 in this scene, you will see that the particles are not affected by the light whenlightingis off.I confirm I have read the contributing guidelines and signed the Contributor License Agreement.