Add more substitutions
This commit is contained in:
parent
4369cf1770
commit
79bb7a64a2
6 changed files with 23 additions and 11 deletions
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
}
|
||||
);
|
||||
|
||||
|
|
|
|||
|
|
@ -91,11 +91,14 @@ export class WebGl2Renderer implements IRenderer {
|
|||
throw new Error('WebGl2 is not supported');
|
||||
}
|
||||
|
||||
const distanceScale = 64;
|
||||
|
||||
this.distanceFieldFrameBuffer = new IntermediateFrameBuffer(this.gl, [
|
||||
new UniformArrayAutoScalingProgram(
|
||||
this.gl,
|
||||
shaderSources[0][0],
|
||||
shaderSources[0][1],
|
||||
{ distanceScale },
|
||||
{
|
||||
getValueFromUniforms: (v) => (v.lines ? v.lines.length / 2 : 0),
|
||||
uniformArraySizeName: 'lineCount',
|
||||
|
|
@ -111,6 +114,7 @@ export class WebGl2Renderer implements IRenderer {
|
|||
this.gl,
|
||||
shaderSources[1][0],
|
||||
shaderSources[1][1],
|
||||
{ distanceScale },
|
||||
{
|
||||
getValueFromUniforms: (v) => (v.lights ? v.lights.length : 0),
|
||||
uniformArraySizeName: 'lightCount',
|
||||
|
|
|
|||
|
|
@ -54,6 +54,7 @@ export class Game {
|
|||
this.objects.addObject(new InfoText());
|
||||
createCharacter(this.objects);
|
||||
createDungeon(this.objects);
|
||||
createDungeon(this.objects);
|
||||
}
|
||||
|
||||
private handleVisibilityChange() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue