Add minor improvements
This commit is contained in:
parent
4f726ddac2
commit
8ca8f0ed70
12 changed files with 20 additions and 69 deletions
|
|
@ -29,7 +29,9 @@ export class Insights {
|
|||
const targetFunction = descriptor.value;
|
||||
|
||||
descriptor.value = function (...values: Array<any>) {
|
||||
return Insights.measureFunction(key, () => targetFunction(...values));
|
||||
return Insights.measureFunction(key, () =>
|
||||
targetFunction.bind(target)(...values)
|
||||
);
|
||||
};
|
||||
return descriptor;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import { vec2 } from 'gl-matrix';
|
||||
import { Drawable } from '../../drawables/drawable';
|
||||
import { RuntimeSettings } from './runtime-settings';
|
||||
import { RuntimeSettings } from './settings/runtime-settings';
|
||||
|
||||
export interface Renderer {
|
||||
readonly canvasSize: vec2;
|
||||
|
|
|
|||
|
|
@ -4,5 +4,6 @@ export interface RuntimeSettings {
|
|||
enableHighDpiRendering: boolean;
|
||||
tileMultiplier: number;
|
||||
isWorldInverted: boolean;
|
||||
shadowLength: number;
|
||||
ambientLight: vec3;
|
||||
}
|
||||
3
src/graphics/rendering/settings/startup-settings.ts
Normal file
3
src/graphics/rendering/settings/startup-settings.ts
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
export interface StartupSettings {
|
||||
shadowTraceCount: string;
|
||||
}
|
||||
|
|
@ -1,4 +0,0 @@
|
|||
export interface StartupSettings {
|
||||
softShadowTraceCount: string;
|
||||
hardShadowTraceCount: string;
|
||||
}
|
||||
|
|
@ -2,6 +2,7 @@ import { mat2d, vec2, vec3 } from 'gl-matrix';
|
|||
|
||||
export class UniformsProvider {
|
||||
public ambientLight = vec3.fromValues(0.25, 0.15, 0.25);
|
||||
public shadowLength = 150;
|
||||
|
||||
private scaleWorldLengthToNDC = 1;
|
||||
private transformWorldToNDC = mat2d.create();
|
||||
|
|
@ -11,21 +12,19 @@ export class UniformsProvider {
|
|||
private squareToAspectRatio = vec2.create();
|
||||
private uvToWorld = mat2d.create();
|
||||
|
||||
public softShadowsEnabled?: boolean;
|
||||
|
||||
public constructor(private gl: WebGL2RenderingContext) {}
|
||||
|
||||
public getUniforms(uniforms: any): any {
|
||||
return {
|
||||
...uniforms,
|
||||
ambientLight: this.ambientLight,
|
||||
shadowLength: this.shadowLength,
|
||||
uvToWorld: this.uvToWorld,
|
||||
worldAreaInView: this.worldAreaInView,
|
||||
squareToAspectRatio: this.squareToAspectRatio,
|
||||
scaleWorldLengthToNDC: this.scaleWorldLengthToNDC,
|
||||
transformWorldToNDC: this.transformWorldToNDC,
|
||||
squareToAspectRatioTimes2: vec2.scale(vec2.create(), this.squareToAspectRatio, 2),
|
||||
softShadowsEnabled: this.softShadowsEnabled,
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -12,12 +12,12 @@ import { Insights } from './insights';
|
|||
import { Renderer } from './renderer';
|
||||
import { RenderingPass } from './rendering-pass';
|
||||
import { RenderingPassName } from './rendering-pass-name';
|
||||
import { RuntimeSettings } from './runtime-settings';
|
||||
import { RuntimeSettings } from './settings/runtime-settings';
|
||||
import { StartupSettings } from './settings/startup-settings';
|
||||
import distanceFragmentShader from './shaders/distance-fs.glsl';
|
||||
import distanceVertexShader from './shaders/distance-vs.glsl';
|
||||
import lightsFragmentShader from './shaders/shading-fs.glsl';
|
||||
import lightsVertexShader from './shaders/shading-vs.glsl';
|
||||
import { StartupSettings } from './startup-settings';
|
||||
import { UniformsProvider } from './uniforms-provider';
|
||||
|
||||
type Passes = { [key in keyof typeof RenderingPassName]: RenderingPass };
|
||||
|
|
@ -46,14 +46,16 @@ export class WebGl2Renderer implements Renderer {
|
|||
this.passes[RenderingPassName.distance].isWorldInverted = v;
|
||||
this.passes[RenderingPassName.pixel].isWorldInverted = v;
|
||||
},
|
||||
shadowLength: (v) => {
|
||||
this.uniformsProvider.shadowLength;
|
||||
},
|
||||
ambientLight: (v) => {
|
||||
this.uniformsProvider.ambientLight = v;
|
||||
},
|
||||
};
|
||||
|
||||
private static defaultStartupSettings: StartupSettings = {
|
||||
softShadowTraceCount: '128',
|
||||
hardShadowTraceCount: '32',
|
||||
shadowTraceCount: '16',
|
||||
};
|
||||
|
||||
setRuntimeSettings(overrides: Partial<RuntimeSettings>): void {
|
||||
|
|
@ -83,8 +85,6 @@ export class WebGl2Renderer implements Renderer {
|
|||
distanceRenderScale: (v) =>
|
||||
(this.distanceFieldFrameBuffer.renderScale = v as number),
|
||||
finalRenderScale: (v) => (this.lightingFrameBuffer.renderScale = v as number),
|
||||
softShadowsEnabled: (v) =>
|
||||
(this.uniformsProvider.softShadowsEnabled = v as boolean),
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -124,8 +124,7 @@ export class WebGl2Renderer implements Renderer {
|
|||
this.descriptors.filter((d) => !WebGl2Renderer.hasSdf(d)),
|
||||
{
|
||||
palette: this.generatePaletteCode(palette),
|
||||
hardShadowTraceCount: settings.hardShadowTraceCount,
|
||||
softShadowTraceCount: settings.softShadowTraceCount,
|
||||
shadowTraceCount: settings.shadowTraceCount,
|
||||
}
|
||||
)
|
||||
);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue