Refactor & improve

This commit is contained in:
Andras Schmelczer 2023-05-01 12:14:36 +01:00
commit b3d9229af5
No known key found for this signature in database
GPG key ID: FC8F2C3D3D1A718C
22 changed files with 713 additions and 334 deletions

View file

@ -1,14 +1,9 @@
struct Settings {
size: vec2<f32>,
deltaTime: f32,
time: f32,
brushWidth: f32,
brushWidthRandomness: f32
};
@group(0) @binding(0) var<uniform> settings: Settings;
@group(0) @binding(1) var Sampler: sampler;
@group(0) @binding(2) var noise: texture_2d<f32>;
@group(1) @binding(0) var<uniform> settings: Settings;
struct VertexOutput {
@builtin(position) position: vec4<f32>,
@ -23,7 +18,7 @@ fn vertex(
@location(1) @interpolate(flat) start: vec2<f32>,
@location(2) @interpolate(flat) end: vec2<f32>
) -> VertexOutput {
let uv = screenPosition / settings.size;
let uv = screenPosition / state.size;
let position = uv * 2.0 - 1.0;
return VertexOutput(vec4(position, 0.0, 1.0), screenPosition, start, end);
}
@ -35,7 +30,7 @@ fn fragment(
@location(2) end: vec2<f32>
) -> @location(0) vec4<f32> {
var distance = distanceFromLine(screenPosition, start, end);
let noise = textureSample(noise, Sampler, screenPosition / settings.size);
let noise = textureSample(noise, noiseSampler, screenPosition / state.size / 50);
distance += noise.r * settings.brushWidthRandomness;
if(distance > settings.brushWidth) {