From d1dd360d83f02719e15791f36adf1e933d009b25 Mon Sep 17 00:00:00 2001 From: schmelczerandras Date: Sun, 4 Oct 2020 09:28:03 +0200 Subject: [PATCH] Add cutoff to flashlight --- src/drawables/lights/flashlight.ts | 5 ++++- src/graphics/rendering/shaders/shading-fs.glsl | 11 ++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/drawables/lights/flashlight.ts b/src/drawables/lights/flashlight.ts index ffeda4c..34924f8 100644 --- a/src/drawables/lights/flashlight.ts +++ b/src/drawables/lights/flashlight.ts @@ -12,6 +12,7 @@ export class Flashlight extends LightDrawable { color: 'flashlightColors', intensity: 'flashlightIntensities', direction: 'flashlightDirections', + startCutoff: 'flashlightStartCutoffs', }, uniformCountMacroName: 'FLASHLIGHT_COUNT', shaderCombinationSteps: [0, 1, 2, 4], @@ -27,7 +28,8 @@ export class Flashlight extends LightDrawable { center: vec2, color: vec3, intensity: number, - public direction: vec2 + public direction: vec2, + public startCutoff = 0 ) { super(center, color, intensity); } @@ -36,6 +38,7 @@ export class Flashlight extends LightDrawable { return { ...super.getObjectToSerialize(transform2d, transform1d), direction: vec2.normalize(vec2.create(), this.direction), + startCutoff: this.startCutoff * transform1d, }; } } diff --git a/src/graphics/rendering/shaders/shading-fs.glsl b/src/graphics/rendering/shaders/shading-fs.glsl index 3b8204b..3d69697 100644 --- a/src/graphics/rendering/shaders/shading-fs.glsl +++ b/src/graphics/rendering/shaders/shading-fs.glsl @@ -59,6 +59,7 @@ float shadowTransparency(float startingDistance, float lightCenterDistance, vec2 uniform float flashlightIntensities[FLASHLIGHT_COUNT]; uniform vec3 flashlightColors[FLASHLIGHT_COUNT]; uniform vec2 flashlightDirections[FLASHLIGHT_COUNT]; + uniform float flashlightStartCutoffs[FLASHLIGHT_COUNT]; in vec2 flashlightActualDirections[FLASHLIGHT_COUNT]; @@ -114,8 +115,16 @@ void main() { vec2 originalDirection = normalize(flashlightActualDirections[i]); float lightCenterDistance; - vec3 lightColorAtPosition = colorInPosition(i, originalDirection, lightCenterDistance); + vec3 lightColorAtPosition = colorInPosition( + i, + originalDirection, + lightCenterDistance + ); + if (lightCenterDistance < flashlightStartCutoffs[i]) { + continue; + } + vec2 direction = originalDirection / squareToAspectRatioTimes2; if (length(lightColorAtPosition) < 0.0) {