← Back to Pull requests

feat(shaders): draw a mesh with Godot's unshaded scene template #1986

Open
unknown opened this pull request with 557 lines diff across 6 files
View on GitHub
unknown unknown commented on Nov 17, 2026 14:57 UTC
Author

Godot measurement

Godot 4.6.3 and the port draw the same pixels for Godot's default spatial shader with render_mode unshaded. Both scenes are 64 by 64 pixels, and the port matches Godot at 0/255 on all 4,096 pixels of each.

| Scene | Mesh | Camera | Pixels over 0/255 |
| --- | --- | --- | --- |
| spatial-default-unshaded | A quad at the origin | Straight on | 0 of 4,096 |
| spatial-unshaded-moved | The quad moved by (0.3, -0.2, -0.5), rotated by (20°, 35°, -10°) and scaled by (1.4, 0.6, 1) | Turned | 0 of 4,096 |

Godot draws each scene in a SubViewport with a Camera3D and a MeshInstance3D. The mesh is an ArrayMesh with no compression flags, and its material is a ShaderMaterial with Godot's default spatial shader.

The test can fail. When the instance basis is written by columns, not by rows, the moved scene has 212 pixels over 2/255, at most 127/255. Before this change, the unshaded variant did not link on WebGL 2.

The corpus has 5 more real shaders that transpile: 15 of 176, before 10. No shader moved back.

What changes

This is T13a of #1451, the first of three parts of T13 (#1831). It targets feature/shader-translator.

  • shaders/spatial/transpileSpatial.ts links a spatial shader into the unshaded variant of forward_clustered/scene_forward_clustered.glsl and builds one three.js node material from it.

  • shaders/spatial/spatialBindings.ts writes the scene data and the instance data as Godot writes them, and gives the projection Godot's clip space correction.

  • shaders/spatial/instanceData.ts writes the 44 words of Godot's InstanceData. That includes the transposed 3 by 4 transform and the non-uniform scale flag.

  • shaders/spatial/meshAttributes.ts adds Godot's two attributes to a geometry. godot/rendering/meshNormalTangent.ts encodes the normal and tangent as octahedrons, as Godot does. With no tangent array, it makes the tangent Godot makes. Its test holds the bytes Godot 4.6.3 writes for six vertices.

  • shaders/template/blockLayout.ts places the members of a block with the std140 and std430 rules.

  • shaders/template/rowTexture.ts reads a buffer block from an RGBA32UI texture at its offsets, because WebGL 2 has no storage buffers.

  • shaders/template/globalParameters.ts passes each global that a function writes as an inout parameter, because three's functions read only their parameters.

  • shaders/template/squareMatrices.ts holds a non-square matrix as a square one.

  • shaders/language/subgroupComposites.ts reads each subgroup operation as a subgroup of one lane.

  • A function name never has two underscores in a row, because GLSL ES reserves them.

  • The guide has a spatial chapter, with the two scenes as showcases.

  • shaders/spatial/ joins the transpiler's paths in scripts/ci/shaderScope.mjs.
  • Boundaries

    These parts of #1831 are in the next two PRs:

  • T13b: the material varyings (flat and smooth), the branch rows and the built-in rows.

  • T13c: a GPU compile or link failure reported as a translator fault, installGodotShading(renderer), ref:diff --lit-surface nodes, the render mode and stencil mode rows.
  • These are cuts in this PR. Each is visible here so that it is not lost:

  • The scene data leaves prev_data unset, where Godot writes the previous frame's data. Motion vectors need it, and the unshaded colour does not read it.

  • The scene data leaves the shadow kernels and the fog unset. The unshaded variant reads neither.

  • Each mesh gets one material, and the instance buffer holds one instance.

  • The names transpileSpatial, writeSpatialBindings and writeSpatialInstance are provisional until installGodotShading in T13c.
  • How you checked it

  • pnpm test:shaders:e2e --update: both mesh scenes at 0/255 on all pixels, and every sky scene stays within 1/255.

  • The core unit tests: 46,137 pass.

  • pnpm vitest run apps/textscene-three-godot-shaders: 8,484 tests pass.

  • pnpm godot:shader-language is up to date. pnpm comments:check --base origin/feature/shader-translator, ESLint, tsc and the pre-push checks pass.

  • The link test came first and failed on the GL link.
  • Review findings

    | Finding | Handling |
    | --- | --- |
    | Pre-push: three exports had only test readers | Fixed: they are module-private |
    | Pre-push: shaders/spatial/ imported the transpiler from outside its paths | Fixed: the folder is one of the transpiler's paths |

    Part of #1831.

    ---
    _Generated by Claude Code_

    Diff: 557 lines (+417 / -140) across 6 files Reviewer: claude[bot] Review duration: 8m
    All Vouch review confidence checks passed
    Residual risk 0.30 = Change Risk (0.48) × (1 − Review Confidence (0.38)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.48 · 557 lines diff across 6 files
    0.48
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 63% · Reviewer familiarity: 35%
    37%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.378
    Shallow Review Depth shallow_review_depth
    0.344
    Real PR Conversation Timeline
    1 comments
    "Review active on #1986"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 37.6% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 48.2% (MEDIUM) · Higher = larger blast radius
    48.2%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 37.6% · Lower = rushed or shallow review
    37.6%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 30% · Safe to merge
    30%