Skip to content

Conversation

liamdon
Copy link
Contributor

@liamdon liamdon commented Jun 24, 2025

Currently, mesh particle emitters with lighting: false will not render in either WebGL2 or WebGPU. For a repro, look at https://playcanvas.vercel.app/#/graphics/particles-mesh and toggle the lighting option.

I think the main issue is that we are using the NORMAL define 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:

  1. Setting NORMAL=VERTEX if the emitter is a mesh and no normalMap is provided (otherwise, NORMAL=NONE).
  2. Passing in LIGHTING as a separate define, and disabling the shading if it's not defined.

Try the latest preview deployment on this PR and you will see that now, on the particles-mesh example, particles are still rendered when lighting is 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 when lighting is off.

I confirm I have read the contributing guidelines and signed the Contributor License Agreement.

Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 LIGHTING define in shader generation when lighting is enabled
  • Guard shading blocks in both WGSL and GLSL shaders with LIGHTING && NORMAL != NONE
  • Update ParticleMaterial to supply lighting and 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 LIGHTING with a define that has no explicit numeric value can lead to preprocessor ambiguity. Consider using #ifdef LIGHTING or defining LIGHTING as 1 to ensure the condition is evaluated as intended.
    #if LIGHTING && NORMAL != NONE

@mvaligursky
Copy link
Contributor

but in the case of an unlit mesh we do want mesh normals, we just don't want that mesh to be shaded

I have not checked in detail, but is particle shader using normals for any other reason?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: graphics Graphics related issue area: particles bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants