Skip to content

fix: Declare the dynamic refraction resources in the lit shader - #9691

Merged
mvaligursky merged 1 commit into
mainfrom
claude/lit-refraction-declarations
Oct 12, 2026
Merged

mvaligursky merged 1 commit into
mainfrom
claude/lit-refraction-declarations

Conversation

@mvaligursky

Copy link
Copy Markdown
Contributor

A LitMaterial with dynamic refraction failed to compile on both WebGL2 and WebGPU. The lit shader's dynamic refraction code reads the scene color map, screen_size and, in GLSL, matrix_viewProjection. The lit shader enables their declarations with LIT_SCENE_COLOR, LIT_SCREEN_SIZE and LIT_TRANSFORMS, but only the StandardMaterial declarations declared them, so other front ends left them undeclared. On WebGPU the shader failed with "cannot use address space 'uniform' as value" at uniform.screen_size.

Changes:

  • The scene color map, screen_size and GLSL matrix_viewProjection declarations move from the StandardMaterial declarations into the lit shader's forward declarations, next to the code that reads them.
  • The unused WGSL var<private> matrix_viewProjection is removed, as the WGSL refraction reads uniform.matrix_viewProjection from the view uniform buffer.
  • StandardMaterial shaders are unchanged, apart from where these declarations sit in the source.

The lit shader's dynamic refraction reads the scene color map, screen_size and (GLSL) matrix_viewProjection, but only the StandardMaterial declarations declared them, so a LitMaterial with dynamic refraction failed to compile. Move the declarations into the lit forward declarations and remove the unused WGSL private matrix_viewProjection.
@github-actions

github-actions Bot commented Oct 7, 2026

Copy link
Copy Markdown

Build size report

This PR changes the size of the minified bundles.

Bundle Minified Gzip Brotli
playcanvas.min.js 2508.0 KB (−113 B, −0.00%) 648.2 KB (+13 B, +0.00%) 502.8 KB (−207 B, −0.04%)
playcanvas.min.mjs 2504.8 KB (−113 B, −0.00%) 646.9 KB (+11 B, +0.00%) 502.8 KB (−114 B, −0.02%)

@mvaligursky mvaligursky left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Automated PR review by Codex (OpenAI AI agent), posted through the account holder's authorized automated review process.

Reviewed the full diff at a2c081921afdb9bb2509499d9e0b7f27fc8ab92a. No actionable findings. Moving the resource declarations into the shared forward-lit declarations fixes the front-end dependency at its source. The existing feature guards are preserved, and the removed WGSL private matrix was unused: dynamic refraction reads the view-buffer matrix instead. No public API changes or additional render-loop work were introduced.

Validation:

  • Reproduced the baseline LitMaterial failure on WebGL2 (uSceneColorMap undeclared) and WebGPU (cannot use address space 'uniform' as value at uniform.screen_size). The PR compiles and renders successfully on both backends, including dynamic refraction, dispersion, and refraction combined with iridescence/clearcoat; no GPU validation errors or unset-uniform warnings remained in the configured tests.
  • StandardMaterial byte-exact comparison: 0 / 294,912 differing pixels on WebGPU and 0 / 294,912 on WebGL2. Repeated baselines were also identical. Covered non-refractive, dynamic-refraction, dispersion and combined-feature materials at two camera poses plus a motion phase.
  • Unit suite: 3,971 passing, 28 pending. Changed-file lint, debug/release ESM builds, declaration build and consumer type tests passed; GitHub CI is green.

Non-blocking testing suggestion: add a permanent regression test with both LitMaterial.hasRefraction and LitMaterial.dynamicRefraction enabled. The existing LitMaterial dispersion test does not enable that branch, so it would not catch these missing declarations returning.

@mvaligursky
mvaligursky merged commit d3473bb into main Oct 12, 2026
11 checks passed
@mvaligursky
mvaligursky deleted the claude/lit-refraction-declarations branch October 12, 2026 11:31

This branch was successfully deployed

2 active deployments
Preview – engine — a2c08192 Deployed Oct 7, 2026 by vercel[bot]
Preview – engine-api-docs — a2c08192 Deployed Oct 7, 2026 by vercel[bot]
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.

1 participant