Skip to content

Fix shader problem that broke 2-D vertex data - #715

Open
alexhuth wants to merge 2 commits into
mainfrom
claude/issue-714-irf5g0
Open

Fix shader problem that broke 2-D vertex data#715
alexhuth wants to merge 2 commits into
mainfrom
claude/issue-714-irf5g0

Conversation

@alexhuth

Copy link
Copy Markdown
Contributor

This pr fixes the recently introduced shader bug that broke 2-D vertex data displays (see issue #714). The core issue is that we are hitting the upper limit on the number of vertex attributes that we can pass to the shaders, and this causes threejs to silently choke. It also adds some tests that look for blank rendered images. This is not a real visual regression test — that would supersede this test.

claude added 2 commits August 23, 2026 18:38
The surface shaders sit right up against the 16 vertex attribute slots
WebGL guarantees, and #679 added two more of them (flatheight and
flatBumpNorms) to the vertex data shader so that bumpy_flatmap would work
for Vertex dataviews. 2D vertex data needs four data attributes rather
than two, which pushed surface_vertex to 17: it still compiles, but it
fails to link with "Too many attributes", and three.js only reports that
on the browser console, so the viewer just draws a black screen. The same
overflow hits plain Vertex data as soon as equivolume sampling is on.

Rather than giving these values slots of their own, pack them into the
spare components of attributes that are already bound:

- the white matter and pial vertex areas, which only the equivolume depth
  sampling reads, move into auxdat.zw (auxdat.x is the medial wall mask
  and .y the curvature; z and w were left at zero by brainctm)
- the flatmap bump height moves into the fourth component of the bumped
  flatmap normals, so the two become a single vec4 flatbump attribute

Every shader variant now links: the worst case, 2D vertex data on a
subject with a flatmap, goes from 19 attributes to 16. Renders of the
paths that did work before -- volume data with equivolume sampling, and
the bumpy flatmap -- are pixel-identical to what they were.

Fixes gh-714.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013wiUP7TLgDqSfnv4n9ySZj
Nothing caught gh-714: the shader that failed to link compiled fine, the
page raised no javascript error, and the screenshot was written -- it was
just empty. Two checks that would have caught it:

test_webgl_shaders links every combination of options the viewer builds
surface, pick and depth shaders with, in a real (swiftshader) GL context,
and reports how many of the available vertex attributes the variant uses
when linking fails. It needs Chromium but no subject database, so it runs
in a couple of seconds.

test_datatype_renders additionally asserts the render is not a single
flat color, which is what a viewer that failed to draw anything produces.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013wiUP7TLgDqSfnv4n9ySZj
@alexhuth
alexhuth requested a review from kroq-gar78 August 23, 2026 19:27
@kroq-gar78

Copy link
Copy Markdown
Contributor

This fixes Vertex2D in Chromium. I was hoping it would also fix it in Firefox (#375), since the root cause was the same from my investigation, but apparently not.

@kroq-gar78

kroq-gar78 commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

I also don't like that this test duplicates a chunk of the shader code (mainly definitions). I think we should test for general OpenGL errors in one of the basic rendering tests, or even cortex.export.save_3d_views at runtime.

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