2
0
Эх сурвалжийг харах

*** empty log message ***

David Rose 25 жил өмнө
parent
commit
9757ab719d

+ 8 - 0
panda/src/glgsg/config_glgsg.cxx

@@ -39,6 +39,14 @@ bool gl_force_mipmaps = config_glgsg.GetBool("gl-force-mipmaps", false);
 // colors, using mipmap_level_*.rgb if they are available.
 bool gl_show_mipmaps = config_glgsg.GetBool("gl-show-mipmaps", false);
 
+// Configure this true to cause all lighting normals to automatically
+// be normalized by the graphics hardware before rendering.  This is
+// necessary if you intend to render things under scale transforms and
+// expect lighting to work correctly.  Maybe one day there will be
+// another way to set this at runtime, instead of only as a configure
+// variable.
+bool gl_auto_normalize_lighting = config_glgsg.GetBool("auto-normalize-lighting", false);
+
 GLDecalType gl_decal_type = GDT_offset;
 
 static GLDecalType

+ 1 - 0
panda/src/glgsg/config_glgsg.h

@@ -17,6 +17,7 @@ extern bool gl_cull_traversal;
 extern bool gl_ignore_mipmaps;
 extern bool gl_force_mipmaps;
 extern bool gl_show_mipmaps;
+extern bool gl_auto_normalize_lighting;
 
 // Ways to implement decals.
 enum GLDecalType {

+ 22 - 17
panda/src/glgsg/glGraphicsStateGuardian.cxx

@@ -275,6 +275,11 @@ reset() {
   enable_line_smooth(false);
   enable_multisample(true);
 
+  // Should we normalize lighting normals?
+  if (gl_auto_normalize_lighting) {
+    glEnable(GL_NORMALIZE);
+  }
+
   // Set up the light id map
   glGetIntegerv( GL_MAX_LIGHTS, &_max_lights );
   _available_light_ids = PTA(Light*)(_max_lights);
@@ -2649,23 +2654,23 @@ void GLGraphicsStateGuardian::issue_light(const LightAttribute *attrib )
     // Check to see if this light has already been bound to an id
     for (i = 0; i < _max_lights; i++) {
       if (_available_light_ids[i] == light) {
-    // Light has already been bound to an id, we only need
-    // to enable the light, not apply it
-    _cur_light_id = -2;
-    enable_light(i, true);
-    _cur_light_enabled[i] = true;
-    break;
+	// Light has already been bound to an id, we only need
+	// to enable the light, not apply it
+	_cur_light_id = -2;
+	enable_light(i, true);
+	_cur_light_enabled[i] = true;
+	break;
       }
     }
     
     // See if there are any unbound light ids 
     if (_cur_light_id == -1) {
       for (i = 0; i < _max_lights; i++) {
-    if (_available_light_ids[i] == NULL) {
-      _available_light_ids[i] = light;
-      _cur_light_id = i;
-      break;
-    }
+	if (_available_light_ids[i] == NULL) {
+	  _available_light_ids[i] = light;
+	  _cur_light_id = i;
+	  break;
+	}
       }
     } 
     
@@ -2673,11 +2678,11 @@ void GLGraphicsStateGuardian::issue_light(const LightAttribute *attrib )
     // a currently unused but previously bound id 
     if (_cur_light_id == -1) {
       for (i = 0; i < _max_lights; i++) {
-    if (attrib->is_off(_available_light_ids[i])) {
-      _available_light_ids[i] = light;
-      _cur_light_id = i;
-      break;
-    } 
+	if (attrib->is_off(_available_light_ids[i])) {
+	  _available_light_ids[i] = light;
+	  _cur_light_id = i;
+	  break;
+	} 
       }
     }
 
@@ -2689,7 +2694,7 @@ void GLGraphicsStateGuardian::issue_light(const LightAttribute *attrib )
       light->apply(this);
     } else if (_cur_light_id == -1) {
       glgsg_cat.error()
-    << "issue_light() - failed to bind light to id" << endl;
+	<< "issue_light() - failed to bind light to id" << endl;
     }
   }