Optimise serialising

This commit is contained in:
Andras Schmelczer 2026-06-10 21:40:36 +01:00
parent d2b7eb29fb
commit 0da4144b9d

View file

@ -29,13 +29,24 @@ export class DistanceRenderPass extends RenderPass {
const radiusInNDC = worldR * commonUniforms.scaleWorldLengthToNDC; const radiusInNDC = worldR * commonUniforms.scaleWorldLengthToNDC;
const stepsInNDC = 2 * stepsInUV; const stepsInNDC = 2 * stepsInUV;
const maxMinDistance = radiusInNDC * (this.isWorldInverted ? -1 : 1);
const serializedDrawables = this.drawables.map((drawable) => {
const drawableUniforms: { [name: string]: Array<any> } = {};
drawable.serializeToUniforms(
drawableUniforms,
commonUniforms.transformWorldToNDC,
commonUniforms.scaleWorldLengthToNDC
);
return { drawable, drawableUniforms };
});
let drawnDrawablesCount = 0; let drawnDrawablesCount = 0;
for (let x = -1; x < 1; x += stepsInNDC) { for (let x = -1; x < 1; x += stepsInNDC) {
for (let y = -1; y < 1; y += stepsInNDC) { for (let y = -1; y < 1; y += stepsInNDC) {
const uniforms = { const uniforms: any = {
...commonUniforms, ...commonUniforms,
maxMinDistance: radiusInNDC * (this.isWorldInverted ? -1 : 1), maxMinDistance,
}; };
const uvBottomLeft = vec2.fromValues(x / 2 + 0.5, y / 2 + 0.5); const uvBottomLeft = vec2.fromValues(x / 2 + 0.5, y / 2 + 0.5);
@ -55,19 +66,20 @@ export class DistanceRenderPass extends RenderPass {
uniforms.uvToWorld uniforms.uvToWorld
); );
const drawablesNearTile = this.drawables.filter( for (const { drawable, drawableUniforms } of serializedDrawables) {
(d) => d.minDistance(tileCenterWorldCoordinates) < 2 * worldR if (drawable.minDistance(tileCenterWorldCoordinates) >= 2 * worldR) {
); continue;
}
drawnDrawablesCount += drawablesNearTile.length; drawnDrawablesCount++;
drawablesNearTile.forEach((p) => for (const name in drawableUniforms) {
p.serializeToUniforms( if (!Object.prototype.hasOwnProperty.call(uniforms, name)) {
uniforms, uniforms[name] = [];
uniforms.transformWorldToNDC, }
uniforms.scaleWorldLengthToNDC uniforms[name].push(...drawableUniforms[name]);
) }
); }
this.program.draw(uniforms); this.program.draw(uniforms);
} }