Add ant presence texture for future spatial neighbor queries

This commit is contained in:
Jared Miller 2026-03-09 10:50:44 -04:00
parent bdf42a3176
commit 862cbfc3b7
Signed by: shmup
GPG key ID: 22B5C6D66A38B06C
3 changed files with 25 additions and 0 deletions

View file

@ -79,6 +79,17 @@ export default class Renderer {
minFilter: THREE.NearestFilter, minFilter: THREE.NearestFilter,
}, },
), ),
antsPresenceRenderTarget: new THREE.WebGLRenderTarget(
Config.worldSize,
Config.worldSize,
{
format: THREE.RGBAFormat,
type: THREE.FloatType,
depthBuffer: false,
magFilter: THREE.NearestFilter,
minFilter: THREE.NearestFilter,
},
),
}; };
} }
@ -109,6 +120,9 @@ export default class Renderer {
this.resources.worldRenderTarget.texture; this.resources.worldRenderTarget.texture;
this.renderer.render(scenes.worldBlur, scenes.worldBlur.camera); this.renderer.render(scenes.worldBlur, scenes.worldBlur.camera);
this.renderer.setRenderTarget(this.resources.antsPresenceRenderTarget);
this.renderer.clear();
this.setViewportFromRT(antsComputeTarget); this.setViewportFromRT(antsComputeTarget);
this.renderer.setRenderTarget(antsComputeTarget); this.renderer.setRenderTarget(antsComputeTarget);
scenes.ants.material.uniforms.tLastState.value = scenes.ants.material.uniforms.tLastState.value =
@ -117,6 +131,8 @@ export default class Renderer {
antsComputeSource.textures[1]; antsComputeSource.textures[1];
scenes.ants.material.uniforms.tWorld.value = scenes.ants.material.uniforms.tWorld.value =
this.resources.worldBlurredRenderTarget.texture; this.resources.worldBlurredRenderTarget.texture;
scenes.ants.material.uniforms.tPresence.value =
this.resources.antsPresenceRenderTarget.texture;
this.renderer.render(scenes.ants, scenes.ants.camera); this.renderer.render(scenes.ants, scenes.ants.camera);
this.setViewportFromRT(this.resources.antsDiscreteRenderTarget); this.setViewportFromRT(this.resources.antsDiscreteRenderTarget);
@ -266,6 +282,13 @@ export default class Renderer {
this.renderer.setRenderTarget(this.resources.antsDiscreteRenderTarget); this.renderer.setRenderTarget(this.resources.antsDiscreteRenderTarget);
this.renderer.clear(); this.renderer.clear();
this.resources.antsPresenceRenderTarget.setSize(
Config.worldSize,
Config.worldSize,
);
this.renderer.setRenderTarget(this.resources.antsPresenceRenderTarget);
this.renderer.clear();
for (const scene of Object.values(scenes)) { for (const scene of Object.values(scenes)) {
scene.recompileMaterials(); scene.recompileMaterials();
} }

View file

@ -21,6 +21,7 @@ export default class AntsComputeScene extends AbstractScene {
tLastState: { value: null }, tLastState: { value: null },
tLastExtState: { value: null }, tLastExtState: { value: null },
tWorld: { value: null }, tWorld: { value: null },
tPresence: { value: null },
}, },
vertexShader, vertexShader,
fragmentShader, fragmentShader,

View file

@ -12,6 +12,7 @@ uniform float uTime;
uniform sampler2D tLastState; uniform sampler2D tLastState;
uniform sampler2D tLastExtState; uniform sampler2D tLastExtState;
uniform sampler2D tWorld; uniform sampler2D tWorld;
uniform sampler2D tPresence;
const float sampleDistance = 20.; const float sampleDistance = 20.;
const float cellSize = 1. / WORLD_SIZE; const float cellSize = 1. / WORLD_SIZE;