Add cancer
This commit is contained in:
parent
b547dc3339
commit
3414f38c3a
14 changed files with 246 additions and 149 deletions
|
|
@ -4,8 +4,9 @@ struct Settings {
|
|||
turnRate: f32,
|
||||
sensorAngle: f32,
|
||||
sensorOffset: f32,
|
||||
nextGenerationAggression: f32,
|
||||
// nextGenerationParity: f32,
|
||||
evenGenerationAggression: f32,
|
||||
oddGenerationAggression: f32,
|
||||
nextGenerationId: f32
|
||||
};
|
||||
|
||||
@group(1) @binding(0) var<uniform> settings: Settings;
|
||||
|
|
@ -16,7 +17,7 @@ struct Settings {
|
|||
fn main(@builtin(global_invocation_id) global_id: vec3<u32>) {
|
||||
let id = global_id.x;
|
||||
|
||||
if (id >= arrayLength(&agents) || agents[id].timeToLive <= 0) {
|
||||
if (id >= arrayLength(&agents)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -26,19 +27,11 @@ fn main(@builtin(global_invocation_id) global_id: vec3<u32>) {
|
|||
let trailCurrent = textureLoad(trailMapIn, vec2<i32>(agent.position), 0);
|
||||
|
||||
var weight: f32;
|
||||
if(agent.species == 0) {
|
||||
if trailCurrent.r < trailCurrent.g {
|
||||
agent.species = 1;
|
||||
agents[id] = agent;
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
if trailCurrent.g < trailCurrent.r {
|
||||
agent.timeToLive = 0;
|
||||
agents[id] = agent;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// even generation id -> red channel
|
||||
// odd generation id -> green channel
|
||||
|
||||
let isFromEvenGeneration = agent.species % 2 == 0;
|
||||
|
||||
let trailForward = sense(agent.position, agent.angle, settings.sensorOffset, 0);
|
||||
let trailLeft = sense(agent.position, agent.angle, settings.sensorOffset, settings.sensorAngle);
|
||||
|
|
@ -47,14 +40,14 @@ fn main(@builtin(global_invocation_id) global_id: vec3<u32>) {
|
|||
var weightForward: f32 = trailForward.a * settings.brushTrailWeight;
|
||||
var weightLeft: f32 = trailLeft.a * settings.brushTrailWeight;
|
||||
var weightRight: f32 = trailRight.a * settings.brushTrailWeight;
|
||||
if (agent.species == 0) {
|
||||
weightForward += trailForward.r - trailForward.g;
|
||||
weightLeft += trailLeft.r - trailLeft.g;
|
||||
weightRight += trailRight.r - trailRight.g;
|
||||
if (isFromEvenGeneration) {
|
||||
weightForward += trailForward.r + settings.evenGenerationAggression * trailForward.g;
|
||||
weightLeft += trailLeft.r + settings.evenGenerationAggression * trailLeft.g;
|
||||
weightRight += trailRight.r + settings.evenGenerationAggression * trailRight.g;
|
||||
} else {
|
||||
weightForward += trailForward.g + trailForward.r * settings.nextGenerationAggression;
|
||||
weightLeft += trailLeft.g + trailLeft.r * settings.nextGenerationAggression;
|
||||
weightRight += trailRight.g + trailRight.r * settings.nextGenerationAggression;
|
||||
weightForward += trailForward.g + settings.oddGenerationAggression * trailForward.r;
|
||||
weightLeft += trailLeft.g + settings.oddGenerationAggression * trailLeft.r;
|
||||
weightRight += trailRight.g + settings.oddGenerationAggression * trailRight.r;
|
||||
}
|
||||
|
||||
var rotation: f32 = 0;
|
||||
|
|
@ -77,16 +70,35 @@ fn main(@builtin(global_invocation_id) global_id: vec3<u32>) {
|
|||
}
|
||||
|
||||
var trail = vec4<f32>(0, 0.1, 0, 0);
|
||||
if (agent.species == 0) {
|
||||
if (isFromEvenGeneration) {
|
||||
trail = vec4(0.1, 0, 0, 0);
|
||||
}
|
||||
|
||||
let current = textureLoad(trailMapIn, vec2<i32>(nextPosition), 0);
|
||||
textureStore(trailMapOut, vec2<i32>(nextPosition), vec4(trail.rgb + current.rgb, current.a));
|
||||
let current = textureLoad(trailMapIn, vec2<i32>(nextPosition), 0);
|
||||
let next = vec4(trail.rgb + current.rgb, current.a);
|
||||
textureStore(trailMapOut, vec2<i32>(nextPosition), next);
|
||||
|
||||
|
||||
if(isFromEvenGeneration) {
|
||||
if next.r < next.g {
|
||||
if agent.species == settings.nextGenerationId {
|
||||
// agent.species -= 1;
|
||||
} else {
|
||||
agent.species += 1;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if next.g < next.r {
|
||||
if agent.species == settings.nextGenerationId {
|
||||
// agent.species -= 1;
|
||||
} else {
|
||||
agent.species += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
agent.position = nextPosition;
|
||||
agent.angle = nextAngle;
|
||||
agent.timeToLive -= state.deltaTime;
|
||||
agents[id] = agent;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue