From ebabaf6ee59557adc914a17ca2794667d3bdb052 Mon Sep 17 00:00:00 2001 From: Andras Schmelczer Date: Sat, 27 May 2023 19:51:11 +0100 Subject: [PATCH] Minor fixes --- .../agent-generation/agent-first-generation.wgsl | 10 +++++++--- .../agent-generation/agent-generation-pipeline.ts | 12 ++---------- src/pipelines/agents/agent-pipeline.ts | 3 +-- src/pipelines/agents/agent.wgsl | 13 +++++++++---- src/pipelines/common-state/common-state.ts | 2 +- src/utils/delta-time-calculator.ts | 2 +- 6 files changed, 21 insertions(+), 21 deletions(-) diff --git a/src/pipelines/agents/agent-generation/agent-first-generation.wgsl b/src/pipelines/agents/agent-generation/agent-first-generation.wgsl index 57e3d9b..7345e70 100644 --- a/src/pipelines/agents/agent-generation/agent-first-generation.wgsl +++ b/src/pipelines/agents/agent-generation/agent-first-generation.wgsl @@ -9,10 +9,14 @@ fn main( return; } - let position = vec2( - hash(id) * state.size.x, - hash(id * id) * state.size.y, + let random = textureSampleLevel( + noise, + noiseSampler, + vec2(f32(id % 1999) / 2000, f32(id) / 1999 / 2000), + 0 ); + + let position = random.xy * state.size; let center = state.size / 2.0; let direction = position - center; diff --git a/src/pipelines/agents/agent-generation/agent-generation-pipeline.ts b/src/pipelines/agents/agent-generation/agent-generation-pipeline.ts index 0e38c4e..a1ef84e 100644 --- a/src/pipelines/agents/agent-generation/agent-generation-pipeline.ts +++ b/src/pipelines/agents/agent-generation/agent-generation-pipeline.ts @@ -1,5 +1,4 @@ import { getWorkgroupCounts } from '../../../utils/graphics/get-workgroup-counts'; -import random from '../../../utils/graphics/random.wgsl'; import { smartCompile } from '../../../utils/graphics/smart-compile'; import { CommonState } from '../../common-state/common-state'; import { AGENT_SIZE_IN_BYTES } from './agent'; @@ -107,7 +106,6 @@ export class AgentGenerationPipeline { module: smartCompile( device, CommonState.shaderCode, - random, agentSchema, firstGenerationShader ), @@ -120,13 +118,7 @@ export class AgentGenerationPipeline { bindGroupLayouts: [commonState.bindGroupLayout, this.bindGroupLayout], }), compute: { - module: smartCompile( - device, - CommonState.shaderCode, - random, - agentSchema, - countingShader - ), + module: smartCompile(device, CommonState.shaderCode, agentSchema, countingShader), entryPoint: 'main', }, }); @@ -135,7 +127,7 @@ export class AgentGenerationPipeline { public get maxAgentCount(): number { return Math.min( this.maxAgentCountUpperLimit, - Math.floor(this.device.limits.maxBufferSize / AGENT_SIZE_IN_BYTES), + Math.floor(this.device.limits.maxBufferSize / AGENT_SIZE_IN_BYTES) - 1, this.device.limits.maxComputeWorkgroupsPerDimension ** 3 ); } diff --git a/src/pipelines/agents/agent-pipeline.ts b/src/pipelines/agents/agent-pipeline.ts index 3123b59..e3dc8f8 100644 --- a/src/pipelines/agents/agent-pipeline.ts +++ b/src/pipelines/agents/agent-pipeline.ts @@ -1,5 +1,4 @@ import { getWorkgroupCounts } from '../../utils/graphics/get-workgroup-counts'; -import random from '../../utils/graphics/random.wgsl'; import { smartCompile } from '../../utils/graphics/smart-compile'; import { CommonState } from '../common-state/common-state'; import agentSchme from './agent-generation/agent-schema.wgsl'; @@ -33,7 +32,7 @@ export class AgentPipeline { bindGroupLayouts: [commonState.bindGroupLayout, this.bindGroupLayout], }), compute: { - module: smartCompile(device, CommonState.shaderCode, random, agentSchme, shader), + module: smartCompile(device, CommonState.shaderCode, agentSchme, shader), entryPoint: 'main', }, }); diff --git a/src/pipelines/agents/agent.wgsl b/src/pipelines/agents/agent.wgsl index 140b938..3de8ef7 100644 --- a/src/pipelines/agents/agent.wgsl +++ b/src/pipelines/agents/agent.wgsl @@ -1,13 +1,12 @@ struct Settings { brushTrailWeight: f32, moveRate: f32, - turnRate: f32, + sensorAngle: f32, - sensorOffset: f32, - evenGenerationAggression: f32, + evenGenerationAggression: f32, oddGenerationAggression: f32, nextGenerationId: f32, @@ -62,7 +61,13 @@ fn main( return; } - let random = hash(id + u32(state.time % 107 * 1673.7)); + let random = textureSampleLevel( + noise, + noiseSampler, + vec2(f32(id) % 23647 / 2000, + state.time % 6294 / 2000), + 0 + ).a; let isFromEvenGeneration = agent.generation % 2 == 0; let isFromNextGeneration = agent.generation == settings.nextGenerationId; diff --git a/src/pipelines/common-state/common-state.ts b/src/pipelines/common-state/common-state.ts index b70536e..72c2de0 100644 --- a/src/pipelines/common-state/common-state.ts +++ b/src/pipelines/common-state/common-state.ts @@ -1,4 +1,4 @@ -import { generateNoise } from '../../utils/graphics/noise/noise'; +import { generateNoise } from '../../utils/graphics/noise'; import { vec2 } from 'gl-matrix'; diff --git a/src/utils/delta-time-calculator.ts b/src/utils/delta-time-calculator.ts index 5705f78..dd430c3 100644 --- a/src/utils/delta-time-calculator.ts +++ b/src/utils/delta-time-calculator.ts @@ -2,7 +2,7 @@ import { clamp } from './clamp'; import { exponentialDecay } from './exponential-decay'; export class DeltaTimeCalculator { - private static FPS_EXPONENTIAL_DECAY_STRENGTH = 0.1; + private static FPS_EXPONENTIAL_DECAY_STRENGTH = 0.01; private previousTime: DOMHighResTimeStamp | null = null; private deltaTimeAccumulator: number | null = null;