From cca375c2f39021a2ea30755e6a6baff35fe3cccf Mon Sep 17 00:00:00 2001 From: David Rose Date: Fri, 30 Mar 2007 23:23:27 +0000 Subject: [PATCH] spotlight fixes: make more consistent across opengl, dx8, dx9 --- panda/src/dxgsg8/dxGraphicsStateGuardian8.cxx | 6 +++++- panda/src/dxgsg9/dxGraphicsStateGuardian9.cxx | 7 ++++++- panda/src/glstuff/glGraphicsStateGuardian_src.cxx | 2 +- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/panda/src/dxgsg8/dxGraphicsStateGuardian8.cxx b/panda/src/dxgsg8/dxGraphicsStateGuardian8.cxx index 6c1c4acf54..1573cb3207 100644 --- a/panda/src/dxgsg8/dxGraphicsStateGuardian8.cxx +++ b/panda/src/dxgsg8/dxGraphicsStateGuardian8.cxx @@ -2306,7 +2306,11 @@ bind_light(PointLight *light_obj, const NodePath &light, int light_id) { alight.Position = *(D3DVECTOR *)pos.get_data(); alight.Range = __D3DLIGHT_RANGE_MAX; - alight.Falloff = 1.0f; + + // Not sure why this factor of 60.0f is necessary; I determined it + // empirically. It seems to successfully approximate the OpenGL + // spotlight equation, at least for reasonably smallish FOV's. + alight.Falloff = light_obj->get_exponent() / 60.0f; const LVecBase3f &att = light_obj->get_attenuation(); alight.Attenuation0 = att[0]; diff --git a/panda/src/dxgsg9/dxGraphicsStateGuardian9.cxx b/panda/src/dxgsg9/dxGraphicsStateGuardian9.cxx index d53de0a0a4..5ab598fd11 100755 --- a/panda/src/dxgsg9/dxGraphicsStateGuardian9.cxx +++ b/panda/src/dxgsg9/dxGraphicsStateGuardian9.cxx @@ -3456,7 +3456,12 @@ bind_light(Spotlight *light_obj, const NodePath &light, int light_id) { alight.Direction = *(D3DVECTOR *)dir.get_data(); alight.Range = __D3DLIGHT_RANGE_MAX; - alight.Falloff = 1.0f; + + // Not sure why this factor of 60.0f is necessary; I determined it + // empirically. It seems to successfully approximate the OpenGL + // spotlight equation, at least for reasonably smallish FOV's. + alight.Falloff = light_obj->get_exponent() / 60.0f; + alight.Theta = 0.0f; alight.Phi = deg_2_rad(lens->get_hfov()); diff --git a/panda/src/glstuff/glGraphicsStateGuardian_src.cxx b/panda/src/glstuff/glGraphicsStateGuardian_src.cxx index fe196fe796..2aa4289525 100644 --- a/panda/src/glstuff/glGraphicsStateGuardian_src.cxx +++ b/panda/src/glstuff/glGraphicsStateGuardian_src.cxx @@ -3989,7 +3989,7 @@ bind_light(Spotlight *light_obj, const NodePath &light, int light_id) { GLP(Lightfv)(id, GL_SPOT_DIRECTION, dir.get_data()); GLP(Lightf)(id, GL_SPOT_EXPONENT, light_obj->get_exponent()); - GLP(Lightf)(id, GL_SPOT_CUTOFF, lens->get_hfov()); + GLP(Lightf)(id, GL_SPOT_CUTOFF, lens->get_hfov() * 0.5f); const LVecBase3f &att = light_obj->get_attenuation(); GLP(Lightf)(id, GL_CONSTANT_ATTENUATION, att[0]);