diff options
author | Eric Anholt <eric@anholt.net> | 2009-07-31 08:49:20 -0700 |
---|---|---|
committer | Eric Anholt <eric@anholt.net> | 2009-07-31 08:49:20 -0700 |
commit | 00364353873b34d9782957b29cfdb828f3d56bd6 (patch) | |
tree | 51398a4f882734b678941c67674d361b70be830c | |
parent | 72c1ef6b77eb6f4199e1fd34a452d279bce76bf4 (diff) |
Fix the light position to be outside of the bounds of the shadow casters.
-rw-r--r-- | glass.c | 2 | ||||
-rw-r--r-- | shadow_map.c | 12 |
2 files changed, 13 insertions, 1 deletions
@@ -95,7 +95,7 @@ struct revolved_object ring; GLuint normalmap_tex, heightmap_tex; static GLboolean display_shadow_map = GL_FALSE; -static const GLUvec4 light_start_world = {{0.0, 5.0, 15.0, 1.0}}; +static const GLUvec4 light_start_world = {{0.0, 10.0, 25.0, 1.0}}; static const GLUvec4 x_axis = {{1.0, 0.0, 0.0, 1.0}}; static const GLUvec4 y_axis = {{0.0, 1.0, 0.0, 1.0}}; static const GLUvec4 z_axis = {{0.0, 0.0, 1.0, 1.0}}; diff --git a/shadow_map.c b/shadow_map.c index 59e7650..a0df0ee 100644 --- a/shadow_map.c +++ b/shadow_map.c @@ -49,6 +49,8 @@ calculate_light_projection(void) { GLUvec4 light_up; GLUmat4 temp; + GLUvec4 light_to_rings; + float light_distance_to_rings; /* Wrong. So wrong. */ light_up.values[0] = 1.0; @@ -61,6 +63,16 @@ calculate_light_projection(void) print_GLUvec4("ring_center", &ring_bounding_sphere_center_world); print_GLUvec4("light_up ", &light_up); */ + + /* Our shadow mapping can't handle lights inside the frustum of the + * shadow casters. + */ + gluSub4v_4v(&light_to_rings, + &ring_bounding_sphere_center_world, &light_world); + light_distance_to_rings = gluLength4v(&light_to_rings); + + assert(light_distance_to_rings > ring_bounding_sphere_radius); + /* Transform for looking from they eye's point of view at the pile of * rings. */ |