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

@ -14,13 +14,6 @@ export const setUpSettingsPage = (
rounding: Math.round, rounding: Math.round,
}), }),
new SettingsSlider(settings, 'moveSpeed', {
min: 10,
max: 500,
scaling: ValueScaling.Quadratic,
rounding: Math.round,
}),
new SettingsSlider(settings, 'currentGenerationAggression', { new SettingsSlider(settings, 'currentGenerationAggression', {
min: -20, min: -20,
max: 20, max: 20,
@ -31,8 +24,81 @@ export const setUpSettingsPage = (
max: 20, max: 20,
}), }),
new SettingsSlider(settings, 'moveSpeed', {
min: 10,
max: 500,
scaling: ValueScaling.Quadratic,
rounding: Math.round,
}),
new SettingsSlider(settings, 'turnSpeed', {
min: 10,
max: 1000,
scaling: ValueScaling.Quadratic,
rounding: Math.round,
}),
new SettingsSlider(settings, 'sensorOffsetAngle', {
min: 0,
max: 90,
step: 1,
}),
new SettingsSlider(settings, 'sensorOffsetDistance', {
min: 0,
max: 200,
scaling: ValueScaling.Quadratic,
rounding: Math.round,
}),
new SettingsSlider(settings, 'turnWhenLost', {
min: 0,
max: 1,
}),
new SettingsSlider(settings, 'turnWhenGoingInTheRightDirection', {
min: 0,
max: 1,
}),
new SettingsSlider(settings, 'deinfectionProbability', {
min: 0,
max: 1,
scaling: ValueScaling.Quadratic,
}),
new SettingsSlider(settings, 'brushTrailWeight', {
min: 0,
max: 10,
}),
new SettingsSlider(settings, 'individualTrailWeight', {
min: 0,
max: 1,
}),
new SettingsSlider(settings, 'diffusionRateTrails', {
min: 0,
max: 10,
}),
new SettingsSlider(settings, 'decayRateTrails', {
min: 0,
max: 10,
}),
new SettingsSlider(settings, 'diffusionRateBrush', {
min: 0,
max: 10,
}),
new SettingsSlider(settings, 'decayRateBrush', {
min: 0,
max: 10,
}),
new SettingsSlider(settings, 'spawnRadius', { new SettingsSlider(settings, 'spawnRadius', {
min: 1, min: 0,
max: 1000, max: 1000,
}), }),
@ -47,15 +113,10 @@ export const setUpSettingsPage = (
step: 0.1, step: 0.1,
}), }),
new SettingsSlider(settings, 'brushWidth', { new SettingsSlider(settings, 'brushSize', {
min: 1, min: 1,
max: 60, max: 60,
}), }),
new SettingsSlider(settings, 'brushWidthVariation', {
min: 0,
max: 1,
}),
], ],
]; ];

View file

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

View file

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

View file

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

View file

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

View file

@ -15,11 +15,11 @@ export const settings: { [key: string]: number } & GameLoopSettings &
currentGenerationAggression: 0.1, currentGenerationAggression: 0.1,
nextGenerationAggression: 10, nextGenerationAggression: 10,
moveSpeed: 80, moveSpeed: 70,
turnSpeed: 550, turnSpeed: 345,
sensorOffsetAngle: 30, sensorOffsetAngle: 32,
sensorOffsetDistance: 30, sensorOffsetDistance: 23,
turnWhenGoingInTheRightDirection: 0.05, turnWhenGoingInTheRightDirection: 0,
turnWhenLost: 0.2, turnWhenLost: 0.2,
deinfectionProbability: 0.001, deinfectionProbability: 0.001,
@ -34,8 +34,8 @@ export const settings: { [key: string]: number } & GameLoopSettings &
spawnInterval: 600, spawnInterval: 600,
clarity: 2, clarity: 2,
brushWidth: 12, brushSize: 12,
brushWidthVariation: 0.5, brushSizeVariation: 0.5,
startColorHue: 200, startColorHue: 200,

View file

@ -1,9 +1,8 @@
export const persist = <T extends Record<string, number>>(wrapee: T): T => { export const persist = <T extends Record<string, number>>(wrapee: T): T => {
const keys = Object.keys(wrapee); const keys = Object.keys(wrapee);
keys.sort();
const keysToShortKeys = Object.fromEntries( const keysToShortKeys = Object.fromEntries(keys.map((key, i) => [key, key]));
keys.map((key, i) => [key, String.fromCharCode(97 + i)])
);
const params = new URLSearchParams(window.location.search); const params = new URLSearchParams(window.location.search);
const newParams = new URLSearchParams(); const newParams = new URLSearchParams();