33 lines
905 B
WebGPU Shading Language
33 lines
905 B
WebGPU Shading Language
#import bevy_sprite::mesh2d_vertex_output::VertexOutput
|
|
|
|
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(2) @binding(0)
|
|
var<uniform> canvas_material: CanvasMaterial;
|
|
|
|
@fragment
|
|
fn fragment(input: VertexOutput) -> @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 = pow(length(canvas_material.tile_lights[i].position - input.world_position.xy), -2.0);
|
|
luminance *= canvas_material.tile_lights[i].intensity * 2.5;
|
|
lighting += vec4<f32>(luminance * canvas_material.tile_lights[i].color.rgb, 0.0);
|
|
}
|
|
|
|
output_color += lighting;
|
|
return output_color;
|
|
}
|