Optimise serialising
This commit is contained in:
parent
d2b7eb29fb
commit
0da4144b9d
1 changed files with 25 additions and 13 deletions
|
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue