diff --git a/src/pipelines/agents/agent.wgsl b/src/pipelines/agents/agent.wgsl index 884abe2..d06066c 100644 --- a/src/pipelines/agents/agent.wgsl +++ b/src/pipelines/agents/agent.wgsl @@ -7,23 +7,23 @@ struct Agent { struct Settings { size: vec2, - deltaTime : f32, - time : f32, + deltaTime: f32, + time: f32, - trailWeight : f32, - moveRate : f32, - turnRate : f32, - sensorAngle : f32, - sensorOffsetDst : f32, + trailWeight: f32, + moveRate: f32, + turnRate: f32, + sensorAngle: f32, + sensorOffsetDst: f32, }; -@group(0) @binding(0) var settings : Settings; -@group(0) @binding(1) var agents : array; -@group(0) @binding(2) var TrailMapIn : texture_2d; -@group(0) @binding(3) var TrailMapOut : texture_storage_2d; +@group(0) @binding(0) var settings: Settings; +@group(0) @binding(1) var agents: array; +@group(0) @binding(2) var TrailMapIn: texture_2d; +@group(0) @binding(3) var TrailMapOut: texture_storage_2d; @compute @workgroup_size(8, 8) -fn main(@builtin(global_invocation_id) global_id : vec3) { +fn main(@builtin(global_invocation_id) global_id: vec3) { let id = global_id.x; if (id >= arrayLength(&agents)) { @@ -34,9 +34,9 @@ fn main(@builtin(global_invocation_id) global_id : vec3) { let random = random(id + u32(settings.time * 10000 + agent.position.y * 10 + agent.position.x)); - let weightForward : f32 = sense(agent, 0.); - let weightLeft : f32 = sense(agent, settings.sensorAngle); - let weightRight : f32 = sense(agent, -settings.sensorAngle); + let weightForward: f32 = sense(agent, 0.); + let weightLeft: f32 = sense(agent, settings.sensorAngle); + let weightRight: f32 = sense(agent, -settings.sensorAngle); if (weightForward < weightLeft && weightForward < weightRight) { agent.angle += (random - 0.5) * 2. * settings.turnRate; @@ -63,15 +63,15 @@ fn main(@builtin(global_invocation_id) global_id : vec3) { agents[id] = agent; } -fn sense(agent : Agent, sensorAngleOffset : f32) -> f32 { - let sensorAngle : f32 = agent.angle + sensorAngleOffset; - let sensorDir : vec2 = vec2(cos(sensorAngle), sin(sensorAngle)) / normalize(settings.size); - let sensorPos : vec2 = agent.position + sensorDir * settings.sensorOffsetDst; +fn sense(agent: Agent, sensorAngleOffset: f32) -> f32 { + let sensorAngle: f32 = agent.angle + sensorAngleOffset; + let sensorDir: vec2 = vec2(cos(sensorAngle), sin(sensorAngle)) / normalize(settings.size); + let sensorPos: vec2 = agent.position + sensorDir * settings.sensorOffsetDst; return textureLoad(TrailMapIn, vec2(sensorPos * settings.size), 0).x; } -fn random(state0 : u32) -> f32 { - var state : u32 = state0; +fn random(state0: u32) -> f32 { + var state: u32 = state0; state = state ^ 2747636419u; state = state * 2654435769u; state = state ^ (state >> 16u); diff --git a/src/pipelines/brush/brush.wgsl b/src/pipelines/brush/brush.wgsl index 2145011..b6319c0 100644 --- a/src/pipelines/brush/brush.wgsl +++ b/src/pipelines/brush/brush.wgsl @@ -1,27 +1,27 @@ struct Settings { - size : vec2, - deltaTime : f32, - time : f32, + size: vec2, + deltaTime: f32, + time: f32, brushWidth: f32, brushBlurWidth: f32 }; -@group(0) @binding(0) var settings : Settings; +@group(0) @binding(0) var settings: Settings; @group(0) @binding(1) var Sampler: sampler; -@group(0) @binding(2) var noise : texture_2d; +@group(0) @binding(2) var noise: texture_2d; struct VertexOutput { - @builtin(position) position : vec4, - @location(0) screenPosition : vec2, - @location(1) start : vec2, - @location(2) end : vec2 + @builtin(position) position: vec4, + @location(0) screenPosition: vec2, + @location(1) start: vec2, + @location(2) end: vec2 } @vertex fn vertex( - @location(0) screenPosition : vec2, - @location(1) @interpolate(flat) start : vec2, - @location(2) @interpolate(flat) end : vec2 + @location(0) screenPosition: vec2, + @location(1) @interpolate(flat) start: vec2, + @location(2) @interpolate(flat) end: vec2 ) -> VertexOutput { let uv = screenPosition / settings.size; let position = uv * 2.0 - 1.0; diff --git a/src/pipelines/diffusion/diffuse.wgsl b/src/pipelines/diffusion/diffuse.wgsl index d3a830d..6fac26d 100644 --- a/src/pipelines/diffusion/diffuse.wgsl +++ b/src/pipelines/diffusion/diffuse.wgsl @@ -1,15 +1,15 @@ struct Settings { - size : vec2, - deltaTime : f32, - time : f32, + size: vec2, + deltaTime: f32, + time: f32, - diffusionRate : f32, - decayRate : f32, + diffusionRate: f32, + decayRate: f32, }; -@group(0) @binding(0) var settings : Settings; +@group(0) @binding(0) var settings: Settings; @group(0) @binding(1) var Sampler: sampler; -@group(0) @binding(2) var trailMap : texture_2d; +@group(0) @binding(2) var trailMap: texture_2d; @fragment fn fragment(@location(0) uv: vec2) -> @location(0) vec4 { diff --git a/src/pipelines/render/render.wgsl b/src/pipelines/render/render.wgsl index 6a72648..878e28e 100644 --- a/src/pipelines/render/render.wgsl +++ b/src/pipelines/render/render.wgsl @@ -1,12 +1,12 @@ struct Settings { - size : vec2, - deltaTime : f32, - time : f32, + size: vec2, + deltaTime: f32, + time: f32, }; -@group(0) @binding(0) var settings : Settings; +@group(0) @binding(0) var settings: Settings; @group(0) @binding(1) var mySampler: sampler; -@group(0) @binding(2) var TargetTexture : texture_2d; +@group(0) @binding(2) var TargetTexture: texture_2d; @fragment fn fragment(@location(0) uv: vec2) -> @location(0) vec4 { diff --git a/src/utils/graphics/full-screen-quad/full-screen-quad.wgsl b/src/utils/graphics/full-screen-quad/full-screen-quad.wgsl index 703e472..beb8216 100644 --- a/src/utils/graphics/full-screen-quad/full-screen-quad.wgsl +++ b/src/utils/graphics/full-screen-quad/full-screen-quad.wgsl @@ -1,12 +1,12 @@ struct VertexOutput { - @builtin(position) position : vec4, - @location(0) uv : vec2, + @builtin(position) position: vec4, + @location(0) uv: vec2, } @vertex fn vertex( - @location(0) position : vec2, - @location(1) uv : vec2 + @location(0) position: vec2, + @location(1) uv: vec2 ) -> VertexOutput { return VertexOutput(vec4(position, 0.0, 1.0), uv); }