Make lights more intuitive
This commit is contained in:
parent
7bbb5f2d96
commit
adbd933955
4 changed files with 24 additions and 43 deletions
|
|
@ -8,16 +8,11 @@ export class CircleLight extends Drawable {
|
||||||
uniformName: 'circleLights',
|
uniformName: 'circleLights',
|
||||||
uniformCountMacroName: 'CIRCLE_LIGHT_COUNT',
|
uniformCountMacroName: 'CIRCLE_LIGHT_COUNT',
|
||||||
shaderCombinationSteps: [0, 1, 2, 4],
|
shaderCombinationSteps: [0, 1, 2, 4],
|
||||||
empty: new CircleLight(vec2.fromValues(0, 0), 0, vec3.fromValues(0, 0, 0), 0),
|
empty: new CircleLight(vec2.fromValues(0, 0), vec3.fromValues(0, 0, 0), 0),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor(
|
constructor(public center: vec2, public color: vec3, public intensity: number) {
|
||||||
public center: vec2,
|
|
||||||
public lightDrop: number,
|
|
||||||
public color: vec3,
|
|
||||||
public lightness: number
|
|
||||||
) {
|
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -28,16 +23,8 @@ export class CircleLight extends Drawable {
|
||||||
protected getObjectToSerialize(transform2d: mat2d, transform1d: number): any {
|
protected getObjectToSerialize(transform2d: mat2d, transform1d: number): any {
|
||||||
return {
|
return {
|
||||||
center: vec2.transformMat2d(vec2.create(), this.center, transform2d),
|
center: vec2.transformMat2d(vec2.create(), this.center, transform2d),
|
||||||
lightDrop: this.lightDrop,
|
color: this.color,
|
||||||
value: this.value,
|
intensity: this.intensity,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public get value(): vec3 {
|
|
||||||
return vec3.scale(
|
|
||||||
vec3.create(),
|
|
||||||
vec3.normalize(this.color, this.color),
|
|
||||||
this.lightness
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,6 @@ export class Flashlight extends Drawable {
|
||||||
empty: new Flashlight(
|
empty: new Flashlight(
|
||||||
vec2.fromValues(0, 0),
|
vec2.fromValues(0, 0),
|
||||||
vec2.fromValues(0, 0),
|
vec2.fromValues(0, 0),
|
||||||
0,
|
|
||||||
vec3.fromValues(0, 0, 0),
|
vec3.fromValues(0, 0, 0),
|
||||||
0
|
0
|
||||||
),
|
),
|
||||||
|
|
@ -21,9 +20,8 @@ export class Flashlight extends Drawable {
|
||||||
public constructor(
|
public constructor(
|
||||||
public center: vec2,
|
public center: vec2,
|
||||||
public direction: vec2,
|
public direction: vec2,
|
||||||
public lightDrop: number,
|
|
||||||
public color: vec3,
|
public color: vec3,
|
||||||
public lightness: number
|
public intensity: number
|
||||||
) {
|
) {
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
|
@ -36,12 +34,8 @@ export class Flashlight extends Drawable {
|
||||||
return {
|
return {
|
||||||
center: vec2.transformMat2d(vec2.create(), this.center, transform2d),
|
center: vec2.transformMat2d(vec2.create(), this.center, transform2d),
|
||||||
direction: this.direction,
|
direction: this.direction,
|
||||||
lightDrop: this.lightDrop,
|
intensity: this.intensity,
|
||||||
value: this.value,
|
color: this.color,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public get value(): vec3 {
|
|
||||||
return vec3.scale(vec3.create(), this.color, this.lightness);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
precision lowp float;
|
precision lowp float;
|
||||||
|
|
||||||
#define INFINITY 1000.0
|
#define INFINITY 1000.0
|
||||||
#define LIGHT_DROP_INSIDE_RATIO 0.5
|
#define INTENSITY_INSIDE_RATIO 0.5
|
||||||
#define AMBIENT_LIGHT vec3(0.25, 0.15, 0.25)
|
#define AMBIENT_LIGHT vec3(0.25, 0.15, 0.25)
|
||||||
#define SHADOW_HARDNESS 150.0
|
#define SHADOW_HARDNESS 150.0
|
||||||
#define HARD_SHADOW_TRACE_COUNT {hardShadowTraceCount}
|
#define HARD_SHADOW_TRACE_COUNT {hardShadowTraceCount}
|
||||||
|
|
@ -71,23 +71,23 @@ float shadowTransparency(float startingDistance, float lightCenterDistance, vec2
|
||||||
#if CIRCLE_LIGHT_COUNT > 0
|
#if CIRCLE_LIGHT_COUNT > 0
|
||||||
uniform struct CircleLight {
|
uniform struct CircleLight {
|
||||||
vec2 center;
|
vec2 center;
|
||||||
float lightDrop;
|
float intensity;
|
||||||
vec3 value;
|
vec3 color;
|
||||||
}[CIRCLE_LIGHT_COUNT] circleLights;
|
}[CIRCLE_LIGHT_COUNT] circleLights;
|
||||||
|
|
||||||
in vec2[CIRCLE_LIGHT_COUNT] circleLightDirections;
|
in vec2[CIRCLE_LIGHT_COUNT] circleLightDirections;
|
||||||
|
|
||||||
vec3 colorInPosition(CircleLight light, out float lightCenterDistance) {
|
vec3 colorInPosition(CircleLight light, out float lightCenterDistance) {
|
||||||
lightCenterDistance = distance(light.center, position);
|
lightCenterDistance = distance(light.center, position);
|
||||||
return light.value / pow(
|
return light.color / pow(
|
||||||
lightCenterDistance / light.lightDrop + 1.0, 2.0
|
lightCenterDistance / light.intensity + 1.0, 2.0
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
vec3 colorInPositionInside(CircleLight light) {
|
vec3 colorInPositionInside(CircleLight light) {
|
||||||
float lightCenterDistance = distance(light.center, position);
|
float lightCenterDistance = distance(light.center, position);
|
||||||
return light.value / pow(
|
return light.color / pow(
|
||||||
lightCenterDistance / (light.lightDrop * LIGHT_DROP_INSIDE_RATIO) + 1.0, 2.0
|
lightCenterDistance / (light.intensity * INTENSITY_INSIDE_RATIO) + 1.0, 2.0
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -96,8 +96,8 @@ float shadowTransparency(float startingDistance, float lightCenterDistance, vec2
|
||||||
uniform struct Flashlight {
|
uniform struct Flashlight {
|
||||||
vec2 center;
|
vec2 center;
|
||||||
vec2 direction;
|
vec2 direction;
|
||||||
float lightDrop;
|
float intensity;
|
||||||
vec3 value;
|
vec3 color;
|
||||||
}[FLASHLIGHT_COUNT] flashlights;
|
}[FLASHLIGHT_COUNT] flashlights;
|
||||||
|
|
||||||
in vec2[FLASHLIGHT_COUNT] flashlightDirections;
|
in vec2[FLASHLIGHT_COUNT] flashlightDirections;
|
||||||
|
|
@ -108,15 +108,15 @@ float shadowTransparency(float startingDistance, float lightCenterDistance, vec2
|
||||||
|
|
||||||
vec3 colorInPosition(Flashlight light, vec2 positionDirection, out float lightCenterDistance) {
|
vec3 colorInPosition(Flashlight light, vec2 positionDirection, out float lightCenterDistance) {
|
||||||
lightCenterDistance = distance(light.center, position);
|
lightCenterDistance = distance(light.center, position);
|
||||||
return intensityInDirection(light.direction, positionDirection) * light.value / pow(
|
return intensityInDirection(light.direction, positionDirection) * light.color / pow(
|
||||||
lightCenterDistance / light.lightDrop + 1.0, 2.0
|
lightCenterDistance / light.intensity + 1.0, 2.0
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
vec3 colorInPositionInside(Flashlight light, vec2 positionDirection) {
|
vec3 colorInPositionInside(Flashlight light, vec2 positionDirection) {
|
||||||
float lightCenterDistance = distance(light.center, position);
|
float lightCenterDistance = distance(light.center, position);
|
||||||
return intensityInDirection(light.direction, positionDirection) * light.value / pow(
|
return intensityInDirection(light.direction, positionDirection) * light.color / pow(
|
||||||
lightCenterDistance / (light.lightDrop * LIGHT_DROP_INSIDE_RATIO) + 1.0, 2.0
|
lightCenterDistance / (light.intensity * INTENSITY_INSIDE_RATIO) + 1.0, 2.0
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -15,8 +15,8 @@ uniform vec2 squareToAspectRatio;
|
||||||
#if CIRCLE_LIGHT_COUNT > 0
|
#if CIRCLE_LIGHT_COUNT > 0
|
||||||
uniform struct CircleLight {
|
uniform struct CircleLight {
|
||||||
vec2 center;
|
vec2 center;
|
||||||
float lightDrop;
|
float intensity;
|
||||||
vec3 value;
|
vec3 color;
|
||||||
}[CIRCLE_LIGHT_COUNT] circleLights;
|
}[CIRCLE_LIGHT_COUNT] circleLights;
|
||||||
|
|
||||||
out vec2[CIRCLE_LIGHT_COUNT] circleLightDirections;
|
out vec2[CIRCLE_LIGHT_COUNT] circleLightDirections;
|
||||||
|
|
@ -26,8 +26,8 @@ uniform vec2 squareToAspectRatio;
|
||||||
uniform struct Flashlight {
|
uniform struct Flashlight {
|
||||||
vec2 center;
|
vec2 center;
|
||||||
vec2 direction;
|
vec2 direction;
|
||||||
float lightDrop;
|
float intensity;
|
||||||
vec3 value;
|
vec3 color;
|
||||||
}[FLASHLIGHT_COUNT] flashlights;
|
}[FLASHLIGHT_COUNT] flashlights;
|
||||||
|
|
||||||
out vec2[FLASHLIGHT_COUNT] flashlightDirections;
|
out vec2[FLASHLIGHT_COUNT] flashlightDirections;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue