Fix bugs with polygons

This commit is contained in:
schmelczerandras 2020-10-16 23:26:42 +02:00
parent c110f110d2
commit fbd85a667e
3 changed files with 11 additions and 10 deletions

View file

@ -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 { Drawable } from '../drawable';
import { DrawableDescriptor } from '../drawable-descriptor'; import { DrawableDescriptor } from '../drawable-descriptor';
import { PolygonBase, PolygonFactory } from './polygon-factory'; import { PolygonBase, PolygonFactory } from './polygon-factory';
@ -11,9 +12,9 @@ interface NoisyPolygonBase extends PolygonBase {
*/ */
export const NoisyPolygonFactory = ( export const NoisyPolygonFactory = (
vertexCount: number, vertexCount: number,
colorIndex: number color: vec3 | vec4 | number
): typeof PolygonBase & NoisyPolygonBase => { ): typeof PolygonBase & NoisyPolygonBase => {
class NoisyPolygon extends PolygonFactory(vertexCount, colorIndex) { class NoisyPolygon extends PolygonFactory(vertexCount, color) {
public static descriptor: DrawableDescriptor = { public static descriptor: DrawableDescriptor = {
sdf: { sdf: {
shader: ` shader: `
@ -50,7 +51,7 @@ export const NoisyPolygonFactory = (
} }
float noisyPolygon${vertexCount}MinDistance(vec2 target, out vec4 color) { float noisyPolygon${vertexCount}MinDistance(vec2 target, out vec4 color) {
color = readFromPalette(${colorIndex}); color = ${codeForColorAccess(color)};
float minDistance = 100.0; float minDistance = 100.0;
@ -100,12 +101,11 @@ export const NoisyPolygonFactory = (
distanceFunctionName: `noisyPolygon${vertexCount}MinDistance`, distanceFunctionName: `noisyPolygon${vertexCount}MinDistance`,
}, },
propertyUniformMapping: { propertyUniformMapping: {
vertices: `noisyPolygon${vertexCount}Vertices`,
length: `noisyPolygon${vertexCount}Lengths`, length: `noisyPolygon${vertexCount}Lengths`,
random: `noisyPolygon${vertexCount}Randoms`, random: `noisyPolygon${vertexCount}Randoms`,
center: `noisyPolygon${vertexCount}Centers`, center: `noisyPolygon${vertexCount}Centers`,
vertices: `noisyPolygon${vertexCount}Vertices`,
}, },
objectCountScaler: 1 / vertexCount,
uniformCountMacroName: `NOISY_POLGYON${vertexCount}_COUNT`, uniformCountMacroName: `NOISY_POLGYON${vertexCount}_COUNT`,
shaderCombinationSteps: [0, 1, 2, 3, 8, 16], shaderCombinationSteps: [0, 1, 2, 3, 8, 16],
empty: (new NoisyPolygon( empty: (new NoisyPolygon(

View file

@ -1,5 +1,6 @@
import { mat2d, vec2 } from 'gl-matrix'; import { mat2d, vec2, vec3, vec4 } from 'gl-matrix';
import { clamp01 } from '../../helper/clamp'; import { clamp01 } from '../../helper/clamp';
import { codeForColorAccess } from '../../helper/code-for-color-access';
import { Drawable } from '../drawable'; import { Drawable } from '../drawable';
import { DrawableDescriptor } from '../drawable-descriptor'; import { DrawableDescriptor } from '../drawable-descriptor';
import { EmptyDrawable } from '../empty-drawable'; import { EmptyDrawable } from '../empty-drawable';
@ -18,7 +19,7 @@ export class PolygonBase extends EmptyDrawable {
*/ */
export const PolygonFactory = ( export const PolygonFactory = (
vertexCount: number, vertexCount: number,
colorIndex: number color: vec3 | vec4 | number
): typeof PolygonBase => { ): typeof PolygonBase => {
class Polygon extends PolygonBase { class Polygon extends PolygonBase {
public static descriptor: DrawableDescriptor = { public static descriptor: DrawableDescriptor = {
@ -42,7 +43,7 @@ export const PolygonFactory = (
} }
float polygon${vertexCount}MinDistance(vec2 target, out vec4 color) { float polygon${vertexCount}MinDistance(vec2 target, out vec4 color) {
color = readFromPalette(${colorIndex}); color = ${codeForColorAccess(color)};
float minDistance = 100.0; float minDistance = 100.0;

View file

@ -70,7 +70,7 @@ export class UniformArrayAutoScalingProgram implements IProgram {
public draw(uniforms: { [name: string]: any }): void { public draw(uniforms: { [name: string]: any }): void {
const values = this.descriptors.map((d) => { const values = this.descriptors.map((d) => {
const uniformNames = last(Object.entries(d.propertyUniformMapping)); const uniformNames = Object.entries(d.propertyUniformMapping)[0];
if (!uniformNames) { if (!uniformNames) {
return 0; return 0;
} }