Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Assets/Scripts/Slime/Simulation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@ void RunSimulation()

// Assign textures
compute.SetTexture(updateKernel, "TrailMap", trailMap);
compute.SetTexture(updateKernel, "DiffusedTrailMap", diffusedTrailMap);

compute.SetTexture(diffuseMapKernel, "TrailMap", trailMap);
compute.SetTexture(diffuseMapKernel, "DiffusedTrailMap", diffusedTrailMap);

Expand Down
6 changes: 3 additions & 3 deletions Assets/Scripts/Slime/SlimeSim.compute
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ RWStructuredBuffer<Agent> agents;
uint numAgents;

RWTexture2D<float4> TrailMap;
RWTexture2D<float4> DiffusedTrailMap;
int width;
int height;

Expand Down Expand Up @@ -65,7 +66,7 @@ float sense(Agent agent, SpeciesSettings settings, float sensorAngleOffset) {
for (int offsetY = -settings.sensorSize; offsetY <= settings.sensorSize; offsetY ++) {
int sampleX = min(width - 1, max(0, sensorCentreX + offsetX));
int sampleY = min(height - 1, max(0, sensorCentreY + offsetY));
sum += dot(senseWeight, TrailMap[int2(sampleX,sampleY)]);
sum += dot(senseWeight, DiffusedTrailMap[int2(sampleX,sampleY)]);
}
}

Expand Down Expand Up @@ -128,7 +129,7 @@ void Update (uint3 id : SV_DispatchThreadID)
agents[id.x].angle = randomAngle;
}
else {
float4 oldTrail = TrailMap[int2(newPos)];
float4 oldTrail = DiffusedTrailMap[int2(newPos)];
TrailMap[int2(newPos)] = min(1, oldTrail + agent.speciesMask * trailWeight * deltaTime);
}

Expand All @@ -139,7 +140,6 @@ void Update (uint3 id : SV_DispatchThreadID)

float decayRate;
float diffuseRate;
RWTexture2D<float4> DiffusedTrailMap;

[numthreads(8,8,1)]
void Diffuse (uint3 id : SV_DispatchThreadID)
Expand Down