Fix flashlights
This commit is contained in:
parent
d2ae2cc489
commit
374796f398
3 changed files with 22 additions and 13 deletions
|
|
@ -19,7 +19,7 @@ export class Flashlight extends LightDrawable {
|
||||||
vec2.fromValues(0, 0),
|
vec2.fromValues(0, 0),
|
||||||
vec3.fromValues(0, 0, 0),
|
vec3.fromValues(0, 0, 0),
|
||||||
0,
|
0,
|
||||||
vec2.fromValues(0, 0)
|
vec2.fromValues(1, 0)
|
||||||
),
|
),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -35,7 +35,7 @@ export class Flashlight extends LightDrawable {
|
||||||
protected getObjectToSerialize(transform2d: mat2d, transform1d: number): any {
|
protected getObjectToSerialize(transform2d: mat2d, transform1d: number): any {
|
||||||
return {
|
return {
|
||||||
...super.getObjectToSerialize(transform2d, transform1d),
|
...super.getObjectToSerialize(transform2d, transform1d),
|
||||||
direction: this.direction,
|
direction: vec2.normalize(vec2.create(), this.direction),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -54,7 +54,11 @@ float shadowTransparency(float startingDistance, float lightCenterDistance, vec2
|
||||||
varying vec2 flashlightActualDirections[FLASHLIGHT_COUNT];
|
varying vec2 flashlightActualDirections[FLASHLIGHT_COUNT];
|
||||||
|
|
||||||
float intensityInDirection(vec2 lightDirection, vec2 targetDirection) {
|
float intensityInDirection(vec2 lightDirection, vec2 targetDirection) {
|
||||||
return smoothstep(0.0, 1.0, 10.0 * max(0.0, dot(targetDirection, lightDirection) - 0.9));
|
return smoothstep(
|
||||||
|
0.0,
|
||||||
|
1.0,
|
||||||
|
10.0 * max(0.0, dot(targetDirection, -lightDirection) - 0.9)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -92,15 +96,16 @@ void main() {
|
||||||
#ifdef FLASHLIGHT_COUNT
|
#ifdef FLASHLIGHT_COUNT
|
||||||
#if FLASHLIGHT_COUNT > 0
|
#if FLASHLIGHT_COUNT > 0
|
||||||
for (int i = 0; i < FLASHLIGHT_COUNT; i++) {
|
for (int i = 0; i < FLASHLIGHT_COUNT; i++) {
|
||||||
vec2 originalDirection = normalize(flashlightDirections[i]);
|
vec2 originalDirection = normalize(flashlightActualDirections[i]);
|
||||||
|
|
||||||
vec3 lightColorAtPosition = colorInPosition(i, originalDirection, lightCenterDistance);
|
float lightCenterDistance = distance(flashlightCenters[i], position);
|
||||||
float lightCenterDistance = intensityInDirection(flashlightDirections[i], positionDirection)
|
|
||||||
* flashlightColors[lightIndex] / pow(
|
vec3 lightColorAtPosition = intensityInDirection(flashlightDirections[i], originalDirection)
|
||||||
|
* flashlightColors[i] / pow(
|
||||||
lightCenterDistance / flashlightIntensities[i] + 1.0, 2.0
|
lightCenterDistance / flashlightIntensities[i] + 1.0, 2.0
|
||||||
);
|
);
|
||||||
|
|
||||||
vec2 direction = originalDirection / squareToAspectRatioTimes2
|
vec2 direction = originalDirection / squareToAspectRatioTimes2;
|
||||||
|
|
||||||
if (length(lightColorAtPosition) < 0.0) {
|
if (length(lightColorAtPosition) < 0.0) {
|
||||||
continue;
|
continue;
|
||||||
|
|
|
||||||
|
|
@ -63,7 +63,11 @@ float shadowTransparency(float startingDistance, float lightCenterDistance, vec2
|
||||||
in vec2 flashlightActualDirections[FLASHLIGHT_COUNT];
|
in vec2 flashlightActualDirections[FLASHLIGHT_COUNT];
|
||||||
|
|
||||||
float intensityInDirection(vec2 lightDirection, vec2 targetDirection) {
|
float intensityInDirection(vec2 lightDirection, vec2 targetDirection) {
|
||||||
return smoothstep(0.0, 1.0, 10.0 * max(0.0, dot(targetDirection, lightDirection) - 0.9));
|
return smoothstep(
|
||||||
|
0.0,
|
||||||
|
1.0,
|
||||||
|
10.0 * max(0.0, dot(targetDirection, -lightDirection) - 0.9)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
vec3 colorInPosition(int lightIndex, vec2 positionDirection, out float lightCenterDistance) {
|
vec3 colorInPosition(int lightIndex, vec2 positionDirection, out float lightCenterDistance) {
|
||||||
|
|
@ -84,7 +88,7 @@ void main() {
|
||||||
vec3 colorAtPosition = rgbaColorAtPosition.rgb;
|
vec3 colorAtPosition = rgbaColorAtPosition.rgb;
|
||||||
|
|
||||||
vec3 lighting = ambientLight;
|
vec3 lighting = ambientLight;
|
||||||
vec3 lightingInside = lighting * INTENSITY_INSIDE_RATIO;
|
vec3 lightingInside = lighting;
|
||||||
|
|
||||||
#ifdef CIRCLE_LIGHT_COUNT
|
#ifdef CIRCLE_LIGHT_COUNT
|
||||||
#if CIRCLE_LIGHT_COUNT > 0
|
#if CIRCLE_LIGHT_COUNT > 0
|
||||||
|
|
@ -107,12 +111,12 @@ void main() {
|
||||||
#ifdef FLASHLIGHT_COUNT
|
#ifdef FLASHLIGHT_COUNT
|
||||||
#if FLASHLIGHT_COUNT > 0
|
#if FLASHLIGHT_COUNT > 0
|
||||||
for (int i = 0; i < FLASHLIGHT_COUNT; i++) {
|
for (int i = 0; i < FLASHLIGHT_COUNT; i++) {
|
||||||
vec2 originalDirection = normalize(flashlightDirections[i]);
|
vec2 originalDirection = normalize(flashlightActualDirections[i]);
|
||||||
|
|
||||||
float lightCenterDistance;
|
float lightCenterDistance;
|
||||||
vec3 lightColorAtPosition = colorInPosition(i, originalDirection, lightCenterDistance);
|
vec3 lightColorAtPosition = colorInPosition(i, originalDirection, lightCenterDistance);
|
||||||
|
|
||||||
vec2 direction = originalDirection / squareToAspectRatioTimes2
|
vec2 direction = originalDirection / squareToAspectRatioTimes2;
|
||||||
|
|
||||||
if (length(lightColorAtPosition) < 0.0) {
|
if (length(lightColorAtPosition) < 0.0) {
|
||||||
continue;
|
continue;
|
||||||
|
|
@ -130,7 +134,7 @@ void main() {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
vec3 outsideColor = backgroundColor.rgb * lighting;
|
vec3 outsideColor = backgroundColor.rgb * lighting;
|
||||||
vec3 insideColor = colorAtPosition * lightingInside;
|
vec3 insideColor = colorAtPosition * lightingInside * INTENSITY_INSIDE_RATIO;
|
||||||
|
|
||||||
float edge = clamp(startingDistance / shadingNdcPixelSize, 0.0, 1.0);
|
float edge = clamp(startingDistance / shadingNdcPixelSize, 0.0, 1.0);
|
||||||
vec3 antialiasedColor = mix(insideColor, outsideColor, edge);
|
vec3 antialiasedColor = mix(insideColor, outsideColor, edge);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue