diff --git a/src/drawables/shapes/noisy-polygon-factory.ts b/src/drawables/shapes/noisy-polygon-factory.ts index 52cef59..ee76099 100644 --- a/src/drawables/shapes/noisy-polygon-factory.ts +++ b/src/drawables/shapes/noisy-polygon-factory.ts @@ -1,4 +1,5 @@ -import { mat2d, vec2 } from 'gl-matrix'; +import { mat2d, vec2, vec3, vec4 } from 'gl-matrix'; +import { codeForColorAccess } from '../../helper/code-for-color-access'; import { Drawable } from '../drawable'; import { DrawableDescriptor } from '../drawable-descriptor'; import { PolygonBase, PolygonFactory } from './polygon-factory'; @@ -11,9 +12,9 @@ interface NoisyPolygonBase extends PolygonBase { */ export const NoisyPolygonFactory = ( vertexCount: number, - colorIndex: number + color: vec3 | vec4 | number ): typeof PolygonBase & NoisyPolygonBase => { - class NoisyPolygon extends PolygonFactory(vertexCount, colorIndex) { + class NoisyPolygon extends PolygonFactory(vertexCount, color) { public static descriptor: DrawableDescriptor = { sdf: { shader: ` @@ -50,7 +51,7 @@ export const NoisyPolygonFactory = ( } float noisyPolygon${vertexCount}MinDistance(vec2 target, out vec4 color) { - color = readFromPalette(${colorIndex}); + color = ${codeForColorAccess(color)}; float minDistance = 100.0; @@ -100,12 +101,11 @@ export const NoisyPolygonFactory = ( distanceFunctionName: `noisyPolygon${vertexCount}MinDistance`, }, propertyUniformMapping: { - vertices: `noisyPolygon${vertexCount}Vertices`, length: `noisyPolygon${vertexCount}Lengths`, random: `noisyPolygon${vertexCount}Randoms`, center: `noisyPolygon${vertexCount}Centers`, + vertices: `noisyPolygon${vertexCount}Vertices`, }, - objectCountScaler: 1 / vertexCount, uniformCountMacroName: `NOISY_POLGYON${vertexCount}_COUNT`, shaderCombinationSteps: [0, 1, 2, 3, 8, 16], empty: (new NoisyPolygon( diff --git a/src/drawables/shapes/polygon-factory.ts b/src/drawables/shapes/polygon-factory.ts index 3cc45ce..131c726 100644 --- a/src/drawables/shapes/polygon-factory.ts +++ b/src/drawables/shapes/polygon-factory.ts @@ -1,5 +1,6 @@ -import { mat2d, vec2 } from 'gl-matrix'; +import { mat2d, vec2, vec3, vec4 } from 'gl-matrix'; import { clamp01 } from '../../helper/clamp'; +import { codeForColorAccess } from '../../helper/code-for-color-access'; import { Drawable } from '../drawable'; import { DrawableDescriptor } from '../drawable-descriptor'; import { EmptyDrawable } from '../empty-drawable'; @@ -18,7 +19,7 @@ export class PolygonBase extends EmptyDrawable { */ export const PolygonFactory = ( vertexCount: number, - colorIndex: number + color: vec3 | vec4 | number ): typeof PolygonBase => { class Polygon extends PolygonBase { public static descriptor: DrawableDescriptor = { @@ -42,7 +43,7 @@ export const PolygonFactory = ( } float polygon${vertexCount}MinDistance(vec2 target, out vec4 color) { - color = readFromPalette(${colorIndex}); + color = ${codeForColorAccess(color)}; float minDistance = 100.0; 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 e476941..e0bc264 100644 --- a/src/graphics/graphics-library/program/uniform-array-autoscaling-program.ts +++ b/src/graphics/graphics-library/program/uniform-array-autoscaling-program.ts @@ -70,7 +70,7 @@ export class UniformArrayAutoScalingProgram implements IProgram { public draw(uniforms: { [name: string]: any }): void { const values = this.descriptors.map((d) => { - const uniformNames = last(Object.entries(d.propertyUniformMapping)); + const uniformNames = Object.entries(d.propertyUniformMapping)[0]; if (!uniformNames) { return 0; }