diff --git a/src/drawables/drawable-descriptor.ts b/src/drawables/drawable-descriptor.ts index 058d884..6a85929 100644 --- a/src/drawables/drawable-descriptor.ts +++ b/src/drawables/drawable-descriptor.ts @@ -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. * diff --git a/src/drawables/lights/circle-light.ts b/src/drawables/lights/circle-light.ts index 3001190..6c1d952 100644 --- a/src/drawables/lights/circle-light.ts +++ b/src/drawables/lights/circle-light.ts @@ -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) { diff --git a/src/drawables/lights/flashlight.ts b/src/drawables/lights/flashlight.ts index 34924f8..66b90c8 100644 --- a/src/drawables/lights/flashlight.ts +++ b/src/drawables/lights/flashlight.ts @@ -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( diff --git a/src/drawables/shapes/droplet.ts b/src/drawables/shapes/droplet.ts index 4df630e..c35928d 100644 --- a/src/drawables/shapes/droplet.ts +++ b/src/drawables/shapes/droplet.ts @@ -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( diff --git a/src/drawables/shapes/inverted-tunnel.ts b/src/drawables/shapes/inverted-tunnel.ts index 18c7cea..c36f400 100644 --- a/src/drawables/shapes/inverted-tunnel.ts +++ b/src/drawables/shapes/inverted-tunnel.ts @@ -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( diff --git a/src/drawables/shapes/meta-circle.ts b/src/drawables/shapes/meta-circle.ts index c383883..0c7c848 100644 --- a/src/drawables/shapes/meta-circle.ts +++ b/src/drawables/shapes/meta-circle.ts @@ -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) { diff --git a/src/graphics/graphics-library/program/uniform-array-autoscaling-program.ts b/src/graphics/graphics-library/program/uniform-array-autoscaling-program.ts index 8b6ff95..77dc6d1 100644 --- a/src/graphics/graphics-library/program/uniform-array-autoscaling-program.ts +++ b/src/graphics/graphics-library/program/uniform-array-autoscaling-program.ts @@ -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)` } );