Skip to content

Keep the sprite shader text identical to TurboWarp - #7

Merged
Mistium merged 1 commit into
developfrom
keep-sprite-shader-text
Oct 1, 2026
Merged

Mistium merged 1 commit into
developfrom
keep-sprite-shader-text

Conversation

@Mistium

@Mistium Mistium commented Oct 1, 2026 •

Copy link
Copy Markdown
Member

Projects using unsandboxed extensions that patch the renderer's shaders with find-and-replace, such as SharkPool's Looks Expanded, flood the console with Failed to compile shader (mode line, effects 0): 'a_texCoord' : undeclared identifier. Their pen lines never draw, and the shader recompiles and fails again on every draw.

The cause is #5 (batch pen triangles). It added a triangle draw mode to sprite.vert and sprite.frag and changed the vertex guard to #if !(defined(DRAW_MODE_line) || defined(DRAW_MODE_background) || defined(DRAW_MODE_triangle)). Looks Expanded replaces the TurboWarp version of that exact line with #if 1 so its injected code can use a_texCoord and the matrices in every mode. With the new text the replace no longer matches, so the patched line and triangle shaders fail to compile.

Changes

  • sprite.vert and sprite.frag are back to TurboWarp's text, byte for byte.
  • Pen triangles draw with a new triangle.vert / triangle.frag pair from ShaderManager.getTriangleShader(). That method is built outside _buildShader and the _shaderCache, so extensions that rewrite sprite shaders, or delete every cached program, leave it alone.
  • DRAW_MODE.triangle is removed. Nothing outside PenSkin used it.
  • The compile and error handling moved into _compileProgram, which both paths share.
  • New test/unit/ShaderSourceTests.js checks that the sprite shaders still contain the lines extensions patch, and that the triangle mode has not crept back into them.

Testing

  • npm run lint, npm run build and npx tap test/unit pass locally.
  • I built scratch-gui with this branch, loaded an empty project with only Looks Expanded and drew a pen triangle and a pen line through the renderer. Both draw (5000 and 1068 pixels), the same as without the extension. On mistwarp.org today the line shader fails to compile in that setup.

This change has nothing visible in the UI, so the PR has no screenshots. The symptom was console errors and missing pen lines.

Extensions such as Looks Expanded patch the sprite shaders with find-and-replace
on exact lines. Batching pen triangles added a triangle draw mode to sprite.vert
and sprite.frag and changed the vertex guard those patches match, so the
patched line shader referenced a_texCoord and u_projectionMatrix without
declaring them. Every pen line then failed to compile, logging the error again
on each draw.

Pen triangles now use their own small shader, built outside _buildShader and
the sprite shader cache, so extension patches and cache clears leave it alone.
The sprite shaders are back to TurboWarp's text, and a test checks the lines
extensions rely on.
@Mistium
Mistium merged commit 7cd8fa4 into develop Oct 1, 2026
2 checks passed
@Mistium
Mistium deleted the keep-sprite-shader-text branch October 1, 2026 18:50
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