Files
simple-rt/shaders_old/lighting.wgsl
2026-01-10 17:43:54 +01:00

31 lines
984 B
WebGPU Shading Language

@vertex
fn vertex_main(@builtin(vertex_index) vertex_id: u32) -> @builtin(position) vec4<f32>
{
let vertices = array<vec2<f32>, 3>(
vec2(-1., -3.),
vec2(-1., 1.),
vec2(3., 1.),
);
return vec4(vertices[vertex_id], 0., 1.);
}
@group(0) @binding(0) var albedo_tex: texture_storage_2d<rgba32float, read>;
@group(0) @binding(1) var position_tex: texture_storage_2d<rgba32float, read>;
@group(0) @binding(2) var normal_tex: texture_storage_2d<rgba32float, read>;
@group(0) @binding(3) var depth_tex: texture_depth_2d;
@fragment
fn fragment_main(@builtin(position) screen_position: vec4<f32>) -> @location(0) vec4<f32>
{
let texel_position = vec2<u32>(screen_position.xy);
let albedo = textureLoad(albedo_tex, texel_position);
let position = textureLoad(position_tex, texel_position);
let normal = textureLoad(normal_tex, texel_position);
let depth = textureLoad(depth_tex, texel_position, 0);
return vec4(depth / 1000.);
}