38 lines
1.0 KiB
WebGPU Shading Language
38 lines
1.0 KiB
WebGPU Shading Language
struct FragmentInput {
|
|
@builtin(position) fragment_coordinate: vec4<f32>,
|
|
@location(0) world_position: vec4<f32>,
|
|
@location(1) world_normal: vec3<f32>,
|
|
@location(2) uv: vec2<f32>,
|
|
};
|
|
|
|
struct TileLight {
|
|
color: vec4<f32>,
|
|
intensity: f32,
|
|
position: vec2<f32>,
|
|
};
|
|
|
|
struct CanvasMaterial {
|
|
ambient_color: vec4<f32>,
|
|
tile_lights: array<TileLight, 256u>,
|
|
number_of_lights: u32,
|
|
};
|
|
|
|
|
|
@group(1) @binding(0)
|
|
var<uniform> canvas_material: CanvasMaterial;
|
|
|
|
@fragment
|
|
fn fragment(input: FragmentInput) -> @location(0) vec4<f32> {
|
|
var output_color = canvas_material.ambient_color;
|
|
|
|
var lighting = vec4<f32>();
|
|
for (var i: u32 = 0u; i < canvas_material.number_of_lights; i++) {
|
|
var luminance = canvas_material.tile_lights[i].intensity * pow(length(canvas_material.tile_lights[i].position - input.world_position.xy), -1.7) * 2.0;
|
|
lighting += vec4<f32>(luminance * canvas_material.tile_lights[i].color.rgb, 0.0);
|
|
}
|
|
|
|
output_color += lighting;
|
|
|
|
return output_color;
|
|
}
|