render iteration
This commit is contained in:
44
src/shaders/snow_deform.wgsl
Normal file
44
src/shaders/snow_deform.wgsl
Normal file
@@ -0,0 +1,44 @@
|
||||
@group(0) @binding(0)
|
||||
var snow_depth: texture_storage_2d<r32float, read_write>;
|
||||
|
||||
@group(0) @binding(1)
|
||||
var<uniform> params: DeformParams;
|
||||
|
||||
struct DeformParams {
|
||||
position_x: f32,
|
||||
position_z: f32,
|
||||
radius: f32,
|
||||
depth: f32,
|
||||
}
|
||||
|
||||
@compute @workgroup_size(16, 16, 1)
|
||||
fn deform(@builtin(global_invocation_id) global_id: vec3<u32>) {
|
||||
let texture_size = textureDimensions(snow_depth);
|
||||
|
||||
if (global_id.x >= texture_size.x || global_id.y >= texture_size.y) {
|
||||
return;
|
||||
}
|
||||
|
||||
let coords = vec2<i32>(i32(global_id.x), i32(global_id.y));
|
||||
|
||||
let terrain_size = vec2<f32>(1000.0, 1000.0);
|
||||
let half_size = terrain_size / 2.0;
|
||||
|
||||
let uv = vec2<f32>(f32(global_id.x) / f32(texture_size.x), f32(global_id.y) / f32(texture_size.y));
|
||||
let world_pos = uv * terrain_size - half_size;
|
||||
|
||||
let deform_center = vec2<f32>(params.position_x, params.position_z);
|
||||
let distance = length(world_pos - deform_center);
|
||||
|
||||
if (distance < params.radius) {
|
||||
let current_depth = textureLoad(snow_depth, coords).r;
|
||||
|
||||
let falloff = 1.0 - (distance / params.radius);
|
||||
let falloff_smooth = falloff * falloff;
|
||||
|
||||
let deform_amount = params.depth * falloff_smooth;
|
||||
let new_depth = max(0.0, current_depth - deform_amount);
|
||||
|
||||
textureStore(snow_depth, coords, vec4<f32>(new_depth, 0.0, 0.0, 0.0));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user