Skip to content

Add shader defines for prepass to support alpha test and dithered opacity#8606

Merged
slimbuck merged 2 commits intoplaycanvas:mainfrom
slimbuck:prepass-dev
Apr 17, 2026
Merged

Add shader defines for prepass to support alpha test and dithered opacity#8606
slimbuck merged 2 commits intoplaycanvas:mainfrom
slimbuck:prepass-dev

Conversation

@slimbuck
Copy link
Copy Markdown
Member

Summary

The prepass shader pass was sharing the same empty code path as the pick pass, which meant it had no shader defines set. This caused materials with alpha testing or opacity dithering to render incorrectly during the prepass because the relevant shader code was never compiled in.

This PR separates the prepass from the pick pass and adds a dedicated preparePrepassPass() method to LitShader that sets:

  • LIT_ALPHA_TEST — enables alpha-test discard in the prepass
  • LIT_BLEND_TYPE — sets the blend type so the shader can handle transparency correctly
  • STD_OPACITY_DITHER — enables opacity dithering (matching the shadow pass behavior via opacityShadowDither)

Technical Details

  • Adds the ditherNames import from constants.js
  • Splits the SHADER_PICK / SHADER_PREPASS combined branch in generateFragmentShader() so each pass gets its own preparation
  • The new preparePrepassPass() follows the same pattern as prepareShadowPass()

@slimbuck slimbuck requested review from a team and Copilot April 16, 2026 16:41
@slimbuck slimbuck self-assigned this Apr 16, 2026
Copy link
Copy Markdown
Contributor

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 fixes incorrect opacity handling in the prepass by giving the prepass its own shader-define preparation path (instead of sharing the “do nothing” pick-pass path). This ensures the prepass compiles the same alpha-test / opacity-dither branches that the material expects.

Changes:

  • Added a dedicated preparePrepassPass() in LitShader to set prepass-specific defines.
  • Split the SHADER_PICK || SHADER_PREPASS branch so SHADER_PREPASS runs its own preparation.
  • Imported ditherNames to support STD_OPACITY_DITHER define selection for the prepass.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/scene/shader-lib/programs/lit-shader.js Outdated
@slimbuck slimbuck merged commit 565bd8f into playcanvas:main Apr 17, 2026
6 of 8 checks passed
@slimbuck slimbuck deleted the prepass-dev branch April 17, 2026 08:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants