Tidy up object count handling
This commit is contained in:
parent
63a1772afa
commit
c158f8655b
7 changed files with 30 additions and 31 deletions
|
|
@ -47,6 +47,15 @@ export interface DrawableDescriptor {
|
|||
isInverted?: boolean;
|
||||
};
|
||||
|
||||
/**
|
||||
* Calculating the number of objects to be drawn is done using the following pseudo-formula:
|
||||
*
|
||||
* objectCountScaler * propertyUniformMapping[0].length
|
||||
*
|
||||
* By default, its value is 1
|
||||
*/
|
||||
objectCountScaler?: number;
|
||||
|
||||
/**
|
||||
* Number of possible drawables around each tile.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ export class CircleLight extends LightDrawable {
|
|||
},
|
||||
uniformCountMacroName: 'CIRCLE_LIGHT_COUNT',
|
||||
shaderCombinationSteps: [0, 1, 2, 4, 8, 16],
|
||||
empty: new CircleLight(vec2.fromValues(0, 0), vec3.fromValues(0, 0, 0), 0),
|
||||
empty: new CircleLight(vec2.create(), vec3.create(), 0),
|
||||
};
|
||||
|
||||
constructor(center: vec2, color: vec3, intensity: number) {
|
||||
|
|
|
|||
|
|
@ -16,12 +16,7 @@ export class Flashlight extends LightDrawable {
|
|||
},
|
||||
uniformCountMacroName: 'FLASHLIGHT_COUNT',
|
||||
shaderCombinationSteps: [0, 1, 2, 4],
|
||||
empty: new Flashlight(
|
||||
vec2.fromValues(0, 0),
|
||||
vec3.fromValues(0, 0, 0),
|
||||
0,
|
||||
vec2.fromValues(1, 0)
|
||||
),
|
||||
empty: new Flashlight(vec2.create(), vec3.create(), 0, vec2.create()),
|
||||
};
|
||||
|
||||
public constructor(
|
||||
|
|
|
|||
|
|
@ -51,12 +51,7 @@ export class Droplet extends Drawable {
|
|||
},
|
||||
uniformCountMacroName: 'DROPLET_COUNT',
|
||||
shaderCombinationSteps: [0, 1, 4, 16, 32],
|
||||
empty: new Droplet(
|
||||
vec2.fromValues(-100000, -100000),
|
||||
vec2.fromValues(-100000, -100000),
|
||||
0,
|
||||
0
|
||||
),
|
||||
empty: new Droplet(vec2.create(), vec2.create(), 0, 0),
|
||||
};
|
||||
|
||||
constructor(
|
||||
|
|
|
|||
|
|
@ -21,14 +21,14 @@ export class InvertedTunnel extends Drawable {
|
|||
uniform sampler2D noiseTexture;
|
||||
|
||||
#ifdef WEBGL2_IS_AVAILABLE
|
||||
float myTerrain(float h) {
|
||||
float invertedTunnelTerrain(float h) {
|
||||
return texture(
|
||||
noiseTexture,
|
||||
vec2(h, 0.5)
|
||||
)[0] - 0.5;
|
||||
}
|
||||
#else
|
||||
float myTerrain(float h) {
|
||||
float invertedTunnelTerrain(float h) {
|
||||
return texture2D(
|
||||
noiseTexture,
|
||||
vec2(h, 0.5)
|
||||
|
|
@ -39,7 +39,7 @@ export class InvertedTunnel extends Drawable {
|
|||
float invertedTunnelMinDistance(vec2 target, out float colorIndex) {
|
||||
colorIndex = 3.0;
|
||||
|
||||
float minDistance = 1000.0;
|
||||
float minDistance = -1000.0;
|
||||
for (int i = 0; i < INVERTED_TUNNEL_COUNT; i++) {
|
||||
|
||||
vec2 targetFromDelta = target - froms[i];
|
||||
|
|
@ -53,12 +53,12 @@ export class InvertedTunnel extends Drawable {
|
|||
fromRadii[i], toRadii[i], clampedH
|
||||
) + distance(
|
||||
targetFromDelta, toFromDeltas[i] * clampedH
|
||||
) - myTerrain(h) / 12.0;
|
||||
) - invertedTunnelTerrain(h) / 12.0;
|
||||
|
||||
minDistance = min(minDistance, currentDistance);
|
||||
minDistance = max(minDistance, -currentDistance);
|
||||
}
|
||||
|
||||
return -minDistance;
|
||||
return minDistance;
|
||||
}
|
||||
`,
|
||||
isInverted: true,
|
||||
|
|
@ -72,12 +72,7 @@ export class InvertedTunnel extends Drawable {
|
|||
},
|
||||
uniformCountMacroName: 'INVERTED_TUNNEL_COUNT',
|
||||
shaderCombinationSteps: [0, 1, 4, 16, 32],
|
||||
empty: new InvertedTunnel(
|
||||
vec2.fromValues(10000, 10000),
|
||||
vec2.fromValues(10000, 10000),
|
||||
0,
|
||||
0
|
||||
),
|
||||
empty: new InvertedTunnel(vec2.create(), vec2.create(), 0, 0),
|
||||
};
|
||||
|
||||
constructor(
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ export class MetaCircle extends Drawable {
|
|||
},
|
||||
uniformCountMacroName: 'META_CIRCLE_COUNT',
|
||||
shaderCombinationSteps: [0, 1, 2, 3, 8, 16],
|
||||
empty: new MetaCircle(vec2.fromValues(10000, 10000), -1000),
|
||||
empty: new MetaCircle(vec2.create(), 0),
|
||||
};
|
||||
|
||||
constructor(public center: vec2, public radius: number) {
|
||||
|
|
|
|||
|
|
@ -75,7 +75,8 @@ export class UniformArrayAutoScalingProgram implements IProgram {
|
|||
return 0;
|
||||
}
|
||||
const uniformName = uniformNames[1];
|
||||
return uniforms[uniformName] ? uniforms[uniformName].length : 0;
|
||||
const scaler = d.objectCountScaler === undefined ? 1 : d.objectCountScaler;
|
||||
return uniforms[uniformName] ? scaler * uniforms[uniformName].length : 0;
|
||||
});
|
||||
|
||||
const closest = this.programs.find((p) => p.values.every((v, i) => v >= values[i]));
|
||||
|
|
@ -91,7 +92,11 @@ export class UniformArrayAutoScalingProgram implements IProgram {
|
|||
this.descriptors!.map((d, i) => {
|
||||
const difference = closest.values[i] - values[i];
|
||||
for (let i = 0; i < difference; i++) {
|
||||
d.empty.serializeToUniforms(uniforms, mat2d.create(), 0);
|
||||
d.empty.serializeToUniforms(
|
||||
uniforms,
|
||||
mat2d.fromTranslation(mat2d.create(), vec2.fromValues(-10000, -10000)),
|
||||
0
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
@ -171,12 +176,12 @@ export class UniformArrayAutoScalingProgram implements IProgram {
|
|||
}(position, objectColor);
|
||||
|
||||
color = mix(
|
||||
objectColor / {paletteSize},
|
||||
color,
|
||||
objectColor / {paletteSize},
|
||||
color,
|
||||
${
|
||||
descriptors[i].sdf?.isInverted
|
||||
? `step(-distanceNdcPixelSize, -objectMinDistance)`
|
||||
: `step(1.0 * distanceNdcPixelSize, objectMinDistance)`
|
||||
: `step(distanceNdcPixelSize, objectMinDistance)`
|
||||
}
|
||||
);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue