The whole-file #import "file.wgsl" form (without ::) does not reliably bring functions into scope in naga_oil/Bevy 0.19 — the renderer was failing at runtime with 'no definition in scope for identifier: ray_direction' (and rot_x, deriv, etc.), producing a blank screen despite 'cargo build' passing (shaders aren't compile-checked at build time). Fix: add #define_import_path to each module file and import symbols explicitly via namespace::name (the canonical Bevy pattern from the shader_material_2d example). Verified the full shader pipeline compiles and runs at runtime with zero WGSL errors. This was a pre-existing bug masked by incomplete runtime verification in earlier tasks; it is NOT specific to Task 15's grid work. All earlier visual features (shadow, Doppler disk, Einstein halo, stars, planets, grid) now actually render.
17 lines
773 B
WebGPU Shading Language
17 lines
773 B
WebGPU Shading Language
// Builds a world-space camera ray direction for the current pixel.
|
|
// `uv` is the pixel coordinate normalized to [-1,1] with aspect correction.
|
|
#define_import_path singularity::ray_gen
|
|
|
|
fn ray_direction(uv: vec2<f32>) -> vec3<f32> {
|
|
// NOTE: `fov` is packed into the `.w` of `up` in BlackHoleUniforms
|
|
// (the Rust struct lays out `up: Vec3` + `fov: f32` as one vec4 block).
|
|
// The WGSL struct must stay exactly as-is per the task spec, so read fov
|
|
// from `uniforms.up.w` rather than a separate `uniforms.fov` field.
|
|
let tan_half_fov = tan(uniforms.up.w * 0.5);
|
|
let dir =
|
|
normalize(uniforms.forward.xyz)
|
|
+ uniforms.right.xyz * (uv.x * tan_half_fov)
|
|
+ uniforms.up.xyz * (uv.y * tan_half_fov);
|
|
return normalize(dir);
|
|
}
|