Add cutoff to flashlight
This commit is contained in:
parent
10b59a39be
commit
d1dd360d83
2 changed files with 14 additions and 2 deletions
|
|
@ -12,6 +12,7 @@ export class Flashlight extends LightDrawable {
|
||||||
color: 'flashlightColors',
|
color: 'flashlightColors',
|
||||||
intensity: 'flashlightIntensities',
|
intensity: 'flashlightIntensities',
|
||||||
direction: 'flashlightDirections',
|
direction: 'flashlightDirections',
|
||||||
|
startCutoff: 'flashlightStartCutoffs',
|
||||||
},
|
},
|
||||||
uniformCountMacroName: 'FLASHLIGHT_COUNT',
|
uniformCountMacroName: 'FLASHLIGHT_COUNT',
|
||||||
shaderCombinationSteps: [0, 1, 2, 4],
|
shaderCombinationSteps: [0, 1, 2, 4],
|
||||||
|
|
@ -27,7 +28,8 @@ export class Flashlight extends LightDrawable {
|
||||||
center: vec2,
|
center: vec2,
|
||||||
color: vec3,
|
color: vec3,
|
||||||
intensity: number,
|
intensity: number,
|
||||||
public direction: vec2
|
public direction: vec2,
|
||||||
|
public startCutoff = 0
|
||||||
) {
|
) {
|
||||||
super(center, color, intensity);
|
super(center, color, intensity);
|
||||||
}
|
}
|
||||||
|
|
@ -36,6 +38,7 @@ export class Flashlight extends LightDrawable {
|
||||||
return {
|
return {
|
||||||
...super.getObjectToSerialize(transform2d, transform1d),
|
...super.getObjectToSerialize(transform2d, transform1d),
|
||||||
direction: vec2.normalize(vec2.create(), this.direction),
|
direction: vec2.normalize(vec2.create(), this.direction),
|
||||||
|
startCutoff: this.startCutoff * transform1d,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -59,6 +59,7 @@ float shadowTransparency(float startingDistance, float lightCenterDistance, vec2
|
||||||
uniform float flashlightIntensities[FLASHLIGHT_COUNT];
|
uniform float flashlightIntensities[FLASHLIGHT_COUNT];
|
||||||
uniform vec3 flashlightColors[FLASHLIGHT_COUNT];
|
uniform vec3 flashlightColors[FLASHLIGHT_COUNT];
|
||||||
uniform vec2 flashlightDirections[FLASHLIGHT_COUNT];
|
uniform vec2 flashlightDirections[FLASHLIGHT_COUNT];
|
||||||
|
uniform float flashlightStartCutoffs[FLASHLIGHT_COUNT];
|
||||||
|
|
||||||
in vec2 flashlightActualDirections[FLASHLIGHT_COUNT];
|
in vec2 flashlightActualDirections[FLASHLIGHT_COUNT];
|
||||||
|
|
||||||
|
|
@ -114,8 +115,16 @@ void main() {
|
||||||
vec2 originalDirection = normalize(flashlightActualDirections[i]);
|
vec2 originalDirection = normalize(flashlightActualDirections[i]);
|
||||||
|
|
||||||
float lightCenterDistance;
|
float lightCenterDistance;
|
||||||
vec3 lightColorAtPosition = colorInPosition(i, originalDirection, lightCenterDistance);
|
vec3 lightColorAtPosition = colorInPosition(
|
||||||
|
i,
|
||||||
|
originalDirection,
|
||||||
|
lightCenterDistance
|
||||||
|
);
|
||||||
|
|
||||||
|
if (lightCenterDistance < flashlightStartCutoffs[i]) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
vec2 direction = originalDirection / squareToAspectRatioTimes2;
|
vec2 direction = originalDirection / squareToAspectRatioTimes2;
|
||||||
|
|
||||||
if (length(lightColorAtPosition) < 0.0) {
|
if (length(lightColorAtPosition) < 0.0) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue