Command Palette

Search for a command to run...

Hectal
Phase 14: Under the Hood: Raw WebGL 2 and WebGPU
3D Web · Exercise 3 of 4 PreviousNext
Advanced

Lay out a WGSL uniform struct

layout(members) should return each member's byte offset and the struct's size by WGSL's rules for uniform structs: each member starts at the next multiple of its alignment, and the size rounds up to the largest alignment.

The starter packs everything tightly, like a JavaScript array. Fix both TODOs.

What Check tests

  1. The glow struct packs into 32 bytes
  2. A vec2f after a vec3f starts at 16
  3. The size rounds up to the largest alignment
  4. A vec3f followed by an f32 shares 16 bytes

Stuck? One hint at a time

The solution unlocks after your first Check. Try first: that is where the learning happens.

Runs in your browser. Your code is saved here.

Your page

Press Run to see the page.

Console

Nothing logged yet.