Fix lights
This commit is contained in:
parent
7250d164a8
commit
3725f56c78
6 changed files with 10 additions and 6 deletions
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "sdf-2d",
|
"name": "sdf-2d",
|
||||||
"version": "0.1.0-alpha",
|
"version": "0.1.1-alpha",
|
||||||
"description": "Graphics framework for efficiently rendering 2D signed distance fields.",
|
"description": "Graphics framework for efficiently rendering 2D signed distance fields.",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"webgl",
|
"webgl",
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ export class CircleLight extends LightDrawable {
|
||||||
public static readonly descriptor: DrawableDescriptor = {
|
public static readonly descriptor: DrawableDescriptor = {
|
||||||
uniformName: 'circleLights',
|
uniformName: 'circleLights',
|
||||||
uniformCountMacroName: 'CIRCLE_LIGHT_COUNT',
|
uniformCountMacroName: 'CIRCLE_LIGHT_COUNT',
|
||||||
shaderCombinationSteps: [0, 1, 2, 4],
|
shaderCombinationSteps: [0, 1, 2, 4, 8],
|
||||||
empty: new CircleLight(vec2.fromValues(0, 0), vec3.fromValues(0, 0, 0), 0),
|
empty: new CircleLight(vec2.fromValues(0, 0), vec3.fromValues(0, 0, 0), 0),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@ export class LightDrawable extends Drawable {
|
||||||
return {
|
return {
|
||||||
center: vec2.transformMat2d(vec2.create(), this.center, transform2d),
|
center: vec2.transformMat2d(vec2.create(), this.center, transform2d),
|
||||||
color: this.color,
|
color: this.color,
|
||||||
intensity: this.intensity * this.lightnessRatio,
|
intensity: this.intensity * this.lightnessRatio * transform1d * 1500,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ import { Insights } from '../insights';
|
||||||
import { RenderPass } from './render-pass';
|
import { RenderPass } from './render-pass';
|
||||||
|
|
||||||
export class LightsRenderPass extends RenderPass {
|
export class LightsRenderPass extends RenderPass {
|
||||||
public lightPhaseOutLength = 400;
|
public lightCutoffDistance = 400;
|
||||||
private drawables: Array<LightDrawable> = [];
|
private drawables: Array<LightDrawable> = [];
|
||||||
|
|
||||||
public addDrawable(drawable: LightDrawable) {
|
public addDrawable(drawable: LightDrawable) {
|
||||||
|
|
@ -33,9 +33,9 @@ export class LightsRenderPass extends RenderPass {
|
||||||
const distance =
|
const distance =
|
||||||
vec2.length([Math.max(d.x, 0), Math.max(d.y, 0)]) +
|
vec2.length([Math.max(d.x, 0), Math.max(d.y, 0)]) +
|
||||||
Math.min(Math.max(d.x, d.y), 0.0);
|
Math.min(Math.max(d.x, d.y), 0.0);
|
||||||
l.setLightnessRatio(clamp01(1 - distance / this.lightPhaseOutLength));
|
l.setLightnessRatio(clamp01(1 - distance / this.lightCutoffDistance));
|
||||||
|
|
||||||
return distance < this.lightPhaseOutLength;
|
return distance < this.lightCutoffDistance;
|
||||||
});
|
});
|
||||||
|
|
||||||
drawablesNearTile.forEach((p) =>
|
drawablesNearTile.forEach((p) =>
|
||||||
|
|
|
||||||
|
|
@ -5,5 +5,6 @@ export interface RuntimeSettings {
|
||||||
tileMultiplier: number;
|
tileMultiplier: number;
|
||||||
isWorldInverted: boolean;
|
isWorldInverted: boolean;
|
||||||
shadowLength: number;
|
shadowLength: number;
|
||||||
|
lightCutoffDistance: number;
|
||||||
ambientLight: vec3;
|
ambientLight: vec3;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -50,6 +50,9 @@ export class WebGl2Renderer implements Renderer {
|
||||||
ambientLight: (v) => {
|
ambientLight: (v) => {
|
||||||
this.uniformsProvider.ambientLight = v;
|
this.uniformsProvider.ambientLight = v;
|
||||||
},
|
},
|
||||||
|
lightCutoffDistance: (v) => {
|
||||||
|
this.lightsPass.lightCutoffDistance = v;
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
private static defaultStartupSettings: StartupSettings = {
|
private static defaultStartupSettings: StartupSettings = {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue