Prechádzať zdrojové kódy

spotlight fixes: make more consistent across opengl, dx8, dx9

David Rose 19 rokov pred
rodič
commit
cca375c2f3

+ 5 - 1
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];

+ 6 - 1
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());
 

+ 1 - 1
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]);