Allow more combinations
This commit is contained in:
parent
7e61ea317e
commit
3755177843
4 changed files with 43 additions and 23 deletions
|
|
@ -15,6 +15,10 @@ class CircleBase extends EmptyDrawable {
|
|||
}
|
||||
}
|
||||
|
||||
// Suffixing the GLSL names with a per-factory-invocation id lets multiple
|
||||
// circle types (e.g. different colors) coexist in one compiled shader.
|
||||
let _id = 0;
|
||||
|
||||
/**
|
||||
* @category Drawable
|
||||
*/
|
||||
|
|
@ -23,27 +27,27 @@ export const CircleFactory = (color: vec3 | vec4 | number): typeof CircleBase =>
|
|||
public static descriptor: DrawableDescriptor = {
|
||||
sdf: {
|
||||
shader: `
|
||||
uniform vec2 circleCenters[CIRCLE_COUNT];
|
||||
uniform float circleRadii[CIRCLE_COUNT];
|
||||
uniform vec2 circleCenters${_id}[CIRCLE_COUNT${_id}];
|
||||
uniform float circleRadii${_id}[CIRCLE_COUNT${_id}];
|
||||
|
||||
float circleMinDistance(vec2 target, out vec4 color) {
|
||||
float circleMinDistance${_id}(vec2 target, out vec4 color) {
|
||||
color = ${codeForColorAccess(color)};
|
||||
float minDistance = 1000.0;
|
||||
for (int i = 0; i < CIRCLE_COUNT; i++) {
|
||||
float dist = distance(circleCenters[i], target) - circleRadii[i];
|
||||
for (int i = 0; i < CIRCLE_COUNT${_id}; i++) {
|
||||
float dist = distance(circleCenters${_id}[i], target) - circleRadii${_id}[i];
|
||||
minDistance = min(minDistance, dist);
|
||||
}
|
||||
|
||||
return minDistance;
|
||||
}
|
||||
`,
|
||||
distanceFunctionName: 'circleMinDistance',
|
||||
distanceFunctionName: `circleMinDistance${_id}`,
|
||||
},
|
||||
propertyUniformMapping: {
|
||||
center: 'circleCenters',
|
||||
radius: 'circleRadii',
|
||||
center: `circleCenters${_id}`,
|
||||
radius: `circleRadii${_id}`,
|
||||
},
|
||||
uniformCountMacroName: 'CIRCLE_COUNT',
|
||||
uniformCountMacroName: `CIRCLE_COUNT${_id}`,
|
||||
shaderCombinationSteps: [0, 1, 2, 3, 8, 16],
|
||||
empty: new Circle(vec2.create(), 0),
|
||||
};
|
||||
|
|
@ -60,5 +64,7 @@ export const CircleFactory = (color: vec3 | vec4 | number): typeof CircleBase =>
|
|||
}
|
||||
}
|
||||
|
||||
_id++;
|
||||
|
||||
return Circle;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ export class ColorfulCircle extends Drawable {
|
|||
uniform float colorfulCircleRadii[COLORFUL_CIRCLE_COUNT];
|
||||
uniform int colorfulCircleColorIndex[COLORFUL_CIRCLE_COUNT];
|
||||
|
||||
float circleMinDistance(vec2 target, out vec4 color) {
|
||||
float colorfulCircleMinDistance(vec2 target, out vec4 color) {
|
||||
float minDistance = 1000.0;
|
||||
for (int i = 0; i < COLORFUL_CIRCLE_COUNT; i++) {
|
||||
float dist = distance(colorfulCircleCenters[i], target) - colorfulCircleRadii[i];
|
||||
|
|
@ -23,7 +23,7 @@ export class ColorfulCircle extends Drawable {
|
|||
return minDistance;
|
||||
}
|
||||
`,
|
||||
distanceFunctionName: 'circleMinDistance',
|
||||
distanceFunctionName: 'colorfulCircleMinDistance',
|
||||
},
|
||||
propertyUniformMapping: {
|
||||
center: 'colorfulCircleCenters',
|
||||
|
|
|
|||
|
|
@ -36,7 +36,12 @@ export const InvertedTunnelFactory = (
|
|||
uniform float fromRadii[INVERTED_TUNNEL_COUNT];
|
||||
uniform float toRadii[INVERTED_TUNNEL_COUNT];
|
||||
|
||||
// Other drawables share this declaration; the include guard keeps
|
||||
// the combined shader from declaring it twice.
|
||||
#ifndef NOISE_TEXTURE_DECLARED
|
||||
#define NOISE_TEXTURE_DECLARED
|
||||
uniform sampler2D noiseTexture;
|
||||
#endif
|
||||
|
||||
#ifdef WEBGL2_IS_AVAILABLE
|
||||
float invertedTunnelTerrain(float h) {
|
||||
|
|
|
|||
|
|
@ -24,8 +24,16 @@ export const NoisyPolygonFactory = (
|
|||
uniform float noisyPolygon${vertexCount}Lengths[NOISY_POLYGON${vertexCount}_COUNT];
|
||||
uniform float noisyPolygon${vertexCount}Randoms[NOISY_POLYGON${vertexCount}_COUNT];
|
||||
|
||||
// Other drawables (and other vertex-count variants of this one)
|
||||
// share these declarations; the include guards keep the combined
|
||||
// shader from declaring them twice.
|
||||
#ifndef NOISE_TEXTURE_DECLARED
|
||||
#define NOISE_TEXTURE_DECLARED
|
||||
uniform sampler2D noiseTexture;
|
||||
#endif
|
||||
|
||||
#ifndef MY_TERRAIN_DECLARED
|
||||
#define MY_TERRAIN_DECLARED
|
||||
#ifdef WEBGL2_IS_AVAILABLE
|
||||
float myTerrain(vec2 h) {
|
||||
return texture(noiseTexture, h)[0] - 0.5;
|
||||
|
|
@ -35,6 +43,7 @@ export const NoisyPolygonFactory = (
|
|||
return texture2D(noiseTexture, h)[0] - 0.5;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
vec2 noisyPolygon${vertexCount}LineDistance(vec2 target, vec2 from, vec2 to) {
|
||||
vec2 targetFromDelta = target - from;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue