Streamline brush settings

This commit is contained in:
Andras Schmelczer 2023-05-28 09:50:30 +01:00
parent a95a5f83a3
commit 8eaee2fa65
No known key found for this signature in database
GPG key ID: FC8F2C3D3D1A718C
7 changed files with 94 additions and 34 deletions

View file

@ -21,7 +21,7 @@ fn main(
let direction = position - center;
agents[id] = Agent(
position,
state.size / 2.0,
atan2(direction.y, direction.x),
0,
);

View file

@ -119,11 +119,11 @@ export class BrushPipeline {
this.linePoints.length = 0;
}
public setParameters({ brushWidth, brushWidthVariation }: BrushSettings) {
public setParameters({ brushSize, brushSizeVariation }: BrushSettings) {
this.device.queue.writeBuffer(
this.uniforms,
0,
new Float32Array([brushWidth / 2, (brushWidth / 2) * brushWidthVariation])
new Float32Array([brushSize / 2, Math.floor((brushSize / 2) * brushSizeVariation)])
);
this.actualPoints = this.linePoints.slice();
@ -148,7 +148,7 @@ export class BrushPipeline {
new Array(this.lineCount).fill(0).flatMap((_, i) => {
const from = this.actualPoints[i];
const to = this.actualPoints[i + 1];
const [a, b, c, d] = this.getSegmentBoundingBox(from, to, brushWidth / 2);
const [a, b, c, d] = this.getSegmentBoundingBox(from, to, brushSize / 2);
return [a, b, c, b, c, d].flatMap((v) => [...v, ...from, ...to]);
})
)

View file

@ -1,4 +1,4 @@
export interface BrushSettings {
brushWidth: number;
brushWidthVariation: number;
brushSize: number;
brushSizeVariation: number;
}

View file

@ -1,6 +1,6 @@
struct Settings {
brushWidth: f32,
brushWidthVariation: f32
brushSize: f32,
brushSizeVariation: f32
};
@group(1) @binding(0) var<uniform> settings: Settings;
@ -31,9 +31,9 @@ fn fragment(
) -> @location(0) vec4<f32> {
var distance = distanceFromLine(screenPosition, start, end);
let noise = textureSample(noise, noiseSampler, screenPosition / state.size / 50);
distance += noise.r * settings.brushWidthVariation;
distance += noise.r * settings.brushSizeVariation;
if(distance > settings.brushWidth) {
if(distance > settings.brushSize) {
discard;
}