From 8eaee2fa65d6b98d696e588a426e436d875d2dc7 Mon Sep 17 00:00:00 2001 From: Andras Schmelczer Date: Sun, 28 May 2023 09:50:30 +0100 Subject: [PATCH] Streamline brush settings --- src/page/set-up-settings-page.ts | 89 ++++++++++++++++--- .../agent-first-generation.wgsl | 2 +- src/pipelines/brush/brush-pipeline.ts | 6 +- src/pipelines/brush/brush-settings.ts | 4 +- src/pipelines/brush/brush.wgsl | 8 +- src/settings.ts | 14 +-- src/utils/persist.ts | 5 +- 7 files changed, 94 insertions(+), 34 deletions(-) diff --git a/src/page/set-up-settings-page.ts b/src/page/set-up-settings-page.ts index 8104217..2fd05bc 100644 --- a/src/page/set-up-settings-page.ts +++ b/src/page/set-up-settings-page.ts @@ -14,13 +14,6 @@ export const setUpSettingsPage = ( rounding: Math.round, }), - new SettingsSlider(settings, 'moveSpeed', { - min: 10, - max: 500, - scaling: ValueScaling.Quadratic, - rounding: Math.round, - }), - new SettingsSlider(settings, 'currentGenerationAggression', { min: -20, max: 20, @@ -31,8 +24,81 @@ export const setUpSettingsPage = ( 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', { - min: 1, + min: 0, max: 1000, }), @@ -47,15 +113,10 @@ export const setUpSettingsPage = ( step: 0.1, }), - new SettingsSlider(settings, 'brushWidth', { + new SettingsSlider(settings, 'brushSize', { min: 1, max: 60, }), - - new SettingsSlider(settings, 'brushWidthVariation', { - min: 0, - max: 1, - }), ], ]; diff --git a/src/pipelines/agents/agent-generation/agent-first-generation.wgsl b/src/pipelines/agents/agent-generation/agent-first-generation.wgsl index 7345e70..a47bcd3 100644 --- a/src/pipelines/agents/agent-generation/agent-first-generation.wgsl +++ b/src/pipelines/agents/agent-generation/agent-first-generation.wgsl @@ -21,7 +21,7 @@ fn main( let direction = position - center; agents[id] = Agent( - position, + state.size / 2.0, atan2(direction.y, direction.x), 0, ); diff --git a/src/pipelines/brush/brush-pipeline.ts b/src/pipelines/brush/brush-pipeline.ts index 0936915..4676601 100644 --- a/src/pipelines/brush/brush-pipeline.ts +++ b/src/pipelines/brush/brush-pipeline.ts @@ -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]); }) ) diff --git a/src/pipelines/brush/brush-settings.ts b/src/pipelines/brush/brush-settings.ts index 61f0008..cecb7a1 100644 --- a/src/pipelines/brush/brush-settings.ts +++ b/src/pipelines/brush/brush-settings.ts @@ -1,4 +1,4 @@ export interface BrushSettings { - brushWidth: number; - brushWidthVariation: number; + brushSize: number; + brushSizeVariation: number; } diff --git a/src/pipelines/brush/brush.wgsl b/src/pipelines/brush/brush.wgsl index 819e315..f705ead 100644 --- a/src/pipelines/brush/brush.wgsl +++ b/src/pipelines/brush/brush.wgsl @@ -1,6 +1,6 @@ struct Settings { - brushWidth: f32, - brushWidthVariation: f32 + brushSize: f32, + brushSizeVariation: f32 }; @group(1) @binding(0) var settings: Settings; @@ -31,9 +31,9 @@ fn fragment( ) -> @location(0) vec4 { 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; } diff --git a/src/settings.ts b/src/settings.ts index 4cf4033..027822a 100644 --- a/src/settings.ts +++ b/src/settings.ts @@ -15,11 +15,11 @@ export const settings: { [key: string]: number } & GameLoopSettings & currentGenerationAggression: 0.1, nextGenerationAggression: 10, - moveSpeed: 80, - turnSpeed: 550, - sensorOffsetAngle: 30, - sensorOffsetDistance: 30, - turnWhenGoingInTheRightDirection: 0.05, + moveSpeed: 70, + turnSpeed: 345, + sensorOffsetAngle: 32, + sensorOffsetDistance: 23, + turnWhenGoingInTheRightDirection: 0, turnWhenLost: 0.2, deinfectionProbability: 0.001, @@ -34,8 +34,8 @@ export const settings: { [key: string]: number } & GameLoopSettings & spawnInterval: 600, clarity: 2, - brushWidth: 12, - brushWidthVariation: 0.5, + brushSize: 12, + brushSizeVariation: 0.5, startColorHue: 200, diff --git a/src/utils/persist.ts b/src/utils/persist.ts index 77142c5..8cdc4cb 100644 --- a/src/utils/persist.ts +++ b/src/utils/persist.ts @@ -1,9 +1,8 @@ export const persist = >(wrapee: T): T => { const keys = Object.keys(wrapee); + keys.sort(); - const keysToShortKeys = Object.fromEntries( - keys.map((key, i) => [key, String.fromCharCode(97 + i)]) - ); + const keysToShortKeys = Object.fromEntries(keys.map((key, i) => [key, key])); const params = new URLSearchParams(window.location.search); const newParams = new URLSearchParams();