🔺 Vertex Shader Demo
Geometry Transformation Only - No Lighting
← Home
→ See Fragment Shader Demo
What You're Seeing:
• Flat colors (NO lighting calculations)
• Pure geometry transformation
• Vertex shader transforms each vertex
• Fragment shader just outputs vertex color
Vertex Shader Role
• Transforms 3D → 2D screen positions
• Runs ONCE per vertex (24 times/frame)
• Handles rotation & positioning
• Passes color to fragment shader
Theory: Coordinate Pipeline
Model → World → View → Clip → NDC → Screen
world = M · v_model (rotate/scale/translate)
view = V · world (inverse of camera pose)
clip = P · view (perspective projection)
NDC = clip.xyz / clip.w (perspective divide, done by GPU)
screen.x = (NDC.x + 1)/2 · width
screen.y = (NDC.y + 1)/2 · height
Theory: Rotation Matrix (Y axis)
| cosθ 0 sinθ 0 |
| 0 1 0 0 |
| -sinθ 0 cosθ 0 |
| 0 0 0 1 |
x' = x·cosθ + z·sinθ
z' = -x·sinθ + z·cosθ
Theory: Perspective Projection
f = 1 / tan(fov / 2)
| f/aspect 0 0 0 |
| 0 f 0 0 |
| 0 0 (far+near)/(near-far) 2·far·near/(near-far) |
| 0 0 -1 0 |
clip.w = -z_view, so distant points shrink after dividing by w.
Theory: Normal Matrix
N = transpose(inverse(mat3(M)))
Normals are not transformed by M directly; non-uniform
scale would skew them off perpendicular. Output is
normalized and sent to the fragment shader.
Theory: Varyings
vColor, vNormal and vWorldPos are written per vertex, then the rasterizer interpolates them across each triangle using barycentric coordinates: v = a·v0 + b·v1 + c·v2 (a+b+c=1).