Improve spawn shape
This commit is contained in:
parent
8ce9b97cf2
commit
6085f9da9f
4 changed files with 53 additions and 36 deletions
|
|
@ -63,7 +63,6 @@ export class AgentPipeline {
|
|||
turnSpeed,
|
||||
sensorAngleDegrees,
|
||||
sensorOffsetDst,
|
||||
sensorSize,
|
||||
}: {
|
||||
width: number;
|
||||
height: number;
|
||||
|
|
@ -74,7 +73,6 @@ export class AgentPipeline {
|
|||
turnSpeed: number;
|
||||
sensorAngleDegrees: number;
|
||||
sensorOffsetDst: number;
|
||||
sensorSize: number;
|
||||
}) {
|
||||
this.device.queue.writeBuffer(
|
||||
this.uniforms,
|
||||
|
|
@ -88,7 +86,6 @@ export class AgentPipeline {
|
|||
turnSpeed * deltaTime,
|
||||
(sensorAngleDegrees * Math.PI) / 180,
|
||||
sensorOffsetDst,
|
||||
sensorSize,
|
||||
])
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,7 +13,6 @@ struct Settings {
|
|||
|
||||
sensorAngle : f32,
|
||||
sensorOffsetDst : f32,
|
||||
sensorSize : f32,
|
||||
};
|
||||
|
||||
@group(0) @binding(0) var<uniform> settings : Settings;
|
||||
|
|
@ -21,20 +20,7 @@ struct Settings {
|
|||
@group(0) @binding(2) var TrailMapIn : texture_2d<f32>;
|
||||
@group(0) @binding(3) var TrailMapOut : texture_storage_2d<rgba16float, write>;
|
||||
|
||||
|
||||
// Hash function www.cs.ubc.ca/~rbridson/docs/schechter-sca08-turbulence.pdf
|
||||
fn hash(state0 : u32) -> u32 {
|
||||
var state : u32 = state0;
|
||||
state = state ^ 2747636419u;
|
||||
state = state * 2654435769u;
|
||||
state = state ^ (state >> 16u);
|
||||
state = state * 2654435769u;
|
||||
state = state ^ (state >> 16u);
|
||||
state = state * 2654435769u;
|
||||
return state;
|
||||
}
|
||||
|
||||
@compute @workgroup_size(64)
|
||||
@compute @workgroup_size(8, 8)
|
||||
fn main(@builtin(global_invocation_id) global_id : vec3<u32>) {
|
||||
let id = global_id.x;
|
||||
|
||||
|
|
@ -60,10 +46,9 @@ fn main(@builtin(global_invocation_id) global_id : vec3<u32>) {
|
|||
|
||||
let direction = vec2(cos(agent.angle), sin(agent.angle));
|
||||
var newPos = agent.position + direction / normalize(settings.size) * settings.moveRate;
|
||||
|
||||
newPos = clamp(newPos, vec2<f32>(0, 0), vec2<f32>(1, 1));
|
||||
if (newPos.x == 0. || newPos.x == 1. || newPos.y == 0. || newPos.y == 1.) {
|
||||
agent.angle = random * 2. * 3.1415;
|
||||
agent.angle += 3.14159265359 + random - 0.5;
|
||||
}
|
||||
|
||||
textureStore(
|
||||
|
|
@ -76,6 +61,18 @@ fn main(@builtin(global_invocation_id) global_id : vec3<u32>) {
|
|||
agents[id] = agent;
|
||||
}
|
||||
|
||||
fn hash(state0 : u32) -> u32 {
|
||||
// Hash function www.cs.ubc.ca/~rbridson/docs/schechter-sca08-turbulence.pdf
|
||||
var state : u32 = state0;
|
||||
state = state ^ 2747636419u;
|
||||
state = state * 2654435769u;
|
||||
state = state ^ (state >> 16u);
|
||||
state = state * 2654435769u;
|
||||
state = state ^ (state >> 16u);
|
||||
state = state * 2654435769u;
|
||||
return state;
|
||||
}
|
||||
|
||||
fn sense(agent : Agent, sensorAngleOffset : f32) -> f32 {
|
||||
let sensorAngle : f32 = agent.angle + sensorAngleOffset;
|
||||
let sensorDir : vec2<f32> = vec2(cos(sensorAngle), sin(sensorAngle)) / normalize(settings.size);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue