Add more substitutions

This commit is contained in:
schmelczerandras 2020-07-26 19:11:03 +02:00
commit 79bb7a64a2
2 changed files with 23 additions and 11 deletions

View file

@ -4,10 +4,13 @@ export const createShader = (
source: string,
substitutions: { [name: string]: string }
): WebGLShader => {
source = source.replace(
/{(.+)}/gm,
(_, name: string): string => substitutions[name]
);
source = source.replace(/{(.+)}/gm, (_, name: string): string => {
const value = substitutions[name];
if (Number.isInteger(value)) {
return `${value}.0`;
}
return value;
});
const shader = gl.createShader(type);
gl.shaderSource(shader, source);

View file

@ -13,6 +13,7 @@ export class UniformArrayAutoScalingProgram implements IProgram {
private gl: WebGL2RenderingContext,
private vertexShaderSource: string,
private fragmentShaderSource: string,
private substitutions: { [name: string]: any },
private options: {
getValueFromUniforms: (values: { [name: string]: any }) => number;
uniformArraySizeName: string;
@ -63,6 +64,7 @@ export class UniformArrayAutoScalingProgram implements IProgram {
this.fragmentShaderSource,
{
[this.options.uniformArraySizeName]: Math.floor(arraySize).toString(),
...this.substitutions,
}
);