summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--chickadee/graphics/light.scm24
-rw-r--r--data/shaders/pbr-frag.glsl5
-rw-r--r--data/shaders/phong-frag.glsl5
3 files changed, 23 insertions, 11 deletions
diff --git a/chickadee/graphics/light.scm b/chickadee/graphics/light.scm
index d217f56..25fd17e 100644
--- a/chickadee/graphics/light.scm
+++ b/chickadee/graphics/light.scm
@@ -40,10 +40,12 @@
light-position
light-direction
light-color
+ light-intensity
light-cut-off
set-light-position!
set-light-direction!
set-light-color!
+ set-light-intensity!
set-light-cut-off!))
;; Maximum number of lights supported by our shaders.
@@ -57,7 +59,8 @@
(float-vec3 position light-position set-light-position!)
(float-vec3 direction light-direction set-light-direction!)
(float-vec4 color light-color set-light-color!)
- (float cut-off light-cut-off set-light-cut-off!))
+ (float intensity light-intensity set-light-intensity!)
+ (float cut-off light-cut-off %set-light-cut-off!))
(define %disabled-light (make-light #:enabled #f))
@@ -77,27 +80,34 @@
(define (spot-light? light)
(eq? (light-type light) 'spot))
+(define (set-light-cut-off! light cut-off)
+ (%set-light-cut-off! light (cos cut-off)))
+
(define* (make-point-light #:key (position (vec3 0.0 0.0 0.0))
- (color black))
+ (color black) (intensity 1.0))
(make-light #:enabled #t
#:type 0
#:position position
- #:color color))
+ #:color color
+ #:intensity intensity))
(define* (make-directional-light #:key (direction (vec3 0.0 -1.0 0.0))
- (color black))
+ (color black) (intensity 1.0))
(make-light #:enabled #t
#:type 1
#:direction direction
- #:color color))
+ #:color color
+ #:intensity intensity))
(define* (make-spot-light #:key (position (vec3 0.0 0.0 0.0))
(direction (vec3 0.0 0.0 -1.0))
(color black)
- (cut-off (/ pi 4.0)))
+ (cut-off (/ pi 4.0))
+ (intensity 1.0))
(make-light #:enabled #t
#:type 2
#:position position
#:direction direction
#:color color
- #:cut-off (cos cut-off)))
+ #:cut-off (cos cut-off)
+ #:intensity intensity))
diff --git a/data/shaders/pbr-frag.glsl b/data/shaders/pbr-frag.glsl
index fff725a..e6bcdc5 100644
--- a/data/shaders/pbr-frag.glsl
+++ b/data/shaders/pbr-frag.glsl
@@ -20,6 +20,7 @@ struct Light {
vec3 position;
vec3 direction;
vec4 color;
+ float intensity;
float cutOff;
};
@@ -210,14 +211,14 @@ vec3 lightDirection(Light light) {
vec3 lightAttenuate(Light light) {
float distance = length(light.position - fragWorldPos);
float attenuation = 1.0 / (distance * distance);
- return light.color.rgb * attenuation;
+ return light.color.rgb * light.intensity * attenuation;
}
vec3 lightRadiance(Light light, vec3 direction) {
if(light.type == 0) { // point light
return lightAttenuate(light);
} else if(light.type == 1) { // directional light
- return light.color.rgb;
+ return light.color.rgb * light.intensity;
} else if(light.type == 2) { // spot light
float theta = dot(direction, normalize(-light.direction));
// Spot lights only shine light in a specific conical area.
diff --git a/data/shaders/phong-frag.glsl b/data/shaders/phong-frag.glsl
index 9c86c83..b07c8b0 100644
--- a/data/shaders/phong-frag.glsl
+++ b/data/shaders/phong-frag.glsl
@@ -13,6 +13,7 @@ struct Light {
vec3 position;
vec3 direction;
vec4 color;
+ float intensity;
float cutOff;
};
@@ -71,14 +72,14 @@ vec3 lightDirection(Light light) {
vec3 lightAttenuate(Light light) {
float distance = length(light.position - fragWorldPos);
float attenuation = 1.0 / (distance * distance);
- return light.color.rgb * attenuation;
+ return light.color.rgb * light.intensity * attenuation;
}
vec3 lightRadiance(Light light, vec3 direction) {
if(light.type == 0) { // point light
return lightAttenuate(light);
} else if(light.type == 1) { // directional light
- return light.color.rgb;
+ return light.color.rgb * light.intensity;
} else if(light.type == 2) { // spot light
float theta = dot(direction, normalize(-light.direction));
// Spot lights only shine light in a specific conical area.