Files
wsg/lib/src/shaders
Jérôme Bousquié 5ae978da23 doc
2026-09-21 10:07:32 +02:00
..
doc
2026-09-21 10:07:32 +02:00

Shaders Directory

Overview

Contains WGSL shader source files used by the PipelineCache module. These are loaded at runtime from disk when referenced by their registered ID in PipelineCache.register_shader(). If a file is missing, PipelineCache falls back to the embedded STANDARD_SHADER constant defined in utils::conf.

Since Step 5, only one shader remains: standard_shader.wgsl (Phong). The former basic_shader.wgsl was removed as a separate pipeline — flat 2D rendering is now the unlit variant of standard (decision ratified in the DRAFT: "2D ⊂ 3D").

Files

File Purpose
standard_shader.wgsl Standard (Phong) vertex/fragment shader — ambient + multi-light (directional + point + spot) diffuse with an explicit unlit mode. Carries the full uniform contract (frame @group(0) + object @group(1) + texture @group(2)).

Shader Contract (standard_shader.wgsl)

standard_shader.wgsl is WSG's unified (Phong) shader. It exposes the two bind groups shared by every material (Step 3: a single layout for all).

Vertex Input Layout (56-byte stride — correspond au resources::Vertex)

Location Attribute Type Offset (bytes)
0 position vec3 0
1 normal vec3 12
2 uv vec2 24
3 color vec4 32

Uniforms (bind groups)

Group / Binding Struct Content
@group(0) @binding(0) FrameUniforms (704 B) view, proj, cam_pos, ambient, lights[8], num_directional, num_point, num_spot, options (.x = unlit flag)
@group(1) @binding(0) ObjectUniform (64 B) model (the entity's model matrix)

FrameUniforms carries a global light list (Steps 12–13, Phase 4.2): lights[0..num_directional] are directional lights (position_dir.xyz = direction from the surface toward the light), lights[num_directional..num_directional + num_point] are point lights (position_dir.xyz = world position, radius.x = linear attenuation radius), and lights[num_directional + num_point..] are spot lights (position_dir.xyz = world position, dir_angle.xyz = light cone axis toward the scene, dir_angle.w = cos of the half-angle). The index disambiguates the type — no flag. ambient is the color of the hemispherical ambient term.

Unlit mode

The options.x != 0 flag disables all lights and returns the vertex color as-is (flat color). On the API side, Renderer::set_unlit(true) (or app.renderer_mut().set_unlit(true)) sets this flag in the frame uniforms. Flat 2D rendering is thus a special case of lit 3D.