]> git.mxchange.org Git - simgear.git/commitdiff
Fix lights appearing three times.
authorChristian Schmitt <chris@ilovelinux.de>
Sun, 3 Aug 2014 11:13:59 +0000 (13:13 +0200)
committerThomas Geymayer <tomgey@gmail.com>
Sun, 3 Aug 2014 11:13:59 +0000 (13:13 +0200)
The 3 lights showing up are fixed by my patch. It's the old way of
calculating a normal (PLIB-style) that makes them show up.

simgear/scene/tgdb/pt_lights.cxx

index d6374b6fa98cbaa5d51bd6dd6049d77158f40806..3bf9d5bc032344ba74dbff1cf2e5921b2d79a40c 100644 (file)
@@ -152,33 +152,23 @@ SGLightFactory::getLightDrawable(const SGDirectionalLightBin::Light& light)
 {
   osg::Vec3Array* vertices = new osg::Vec3Array;
   osg::Vec4Array* colors = new osg::Vec4Array;
+  osg::Vec3Array* normals = new osg::Vec3Array;
 
-  SGVec4f visibleColor(light.color);
-  SGVec4f invisibleColor(visibleColor[0], visibleColor[1],
-                         visibleColor[2], 0);
-  SGVec3f normal = normalize(light.normal);
-  SGVec3f perp1 = perpendicular(normal);
-  SGVec3f perp2 = cross(normal, perp1);
-  SGVec3f position = light.position;
-  vertices->push_back(toOsg(position));
-  vertices->push_back(toOsg(position + perp1));
-  vertices->push_back(toOsg(position + perp2));
-  colors->push_back(toOsg(visibleColor));
-  colors->push_back(toOsg(invisibleColor));
-  colors->push_back(toOsg(invisibleColor));
+  vertices->push_back(toOsg(light.position));
+  colors->push_back(toOsg(light.color));
+  normals->push_back(toOsg(normalize(light.normal)));
 
   osg::Geometry* geometry = new osg::Geometry;
   geometry->setDataVariance(osg::Object::STATIC);
   geometry->setVertexArray(vertices);
-  geometry->setNormalBinding(osg::Geometry::BIND_OFF);
-  geometry->setColorArray(colors);
-  geometry->setColorBinding(osg::Geometry::BIND_PER_VERTEX);
+  geometry->setNormalArray(normals, osg::Array::BIND_PER_VERTEX);
+  geometry->setColorArray(colors, osg::Array::BIND_PER_VERTEX);
   // Enlarge the bounding box to avoid such light nodes being victim to
   // small feature culling.
   geometry->setComputeBoundingBoxCallback(new SGEnlargeBoundingBox(1));
 
   osg::DrawArrays* drawArrays;
-  drawArrays = new osg::DrawArrays(osg::PrimitiveSet::TRIANGLES,
+  drawArrays = new osg::DrawArrays(osg::PrimitiveSet::POINTS,
                                    0, vertices->size());
   geometry->addPrimitiveSet(drawArrays);
   return geometry;
@@ -240,32 +230,22 @@ SGLightFactory::getLights(const SGDirectionalLightBin& lights)
 
   osg::Vec3Array* vertices = new osg::Vec3Array;
   osg::Vec4Array* colors = new osg::Vec4Array;
+  osg::Vec3Array* normals = new osg::Vec3Array;
 
   for (unsigned i = 0; i < lights.getNumLights(); ++i) {
-    SGVec4f visibleColor(lights.getLight(i).color);
-    SGVec4f invisibleColor(visibleColor[0], visibleColor[1],
-                           visibleColor[2], 0);
-    SGVec3f normal = normalize(lights.getLight(i).normal);
-    SGVec3f perp1 = perpendicular(normal);
-    SGVec3f perp2 = cross(normal, perp1);
-    SGVec3f position = lights.getLight(i).position;
-    vertices->push_back(toOsg(position));
-    vertices->push_back(toOsg(position + perp1));
-    vertices->push_back(toOsg(position + perp2));
-    colors->push_back(toOsg(visibleColor));
-    colors->push_back(toOsg(invisibleColor));
-    colors->push_back(toOsg(invisibleColor));
+    vertices->push_back(toOsg(lights.getLight(i).position));
+    colors->push_back(toOsg(lights.getLight(i).color));
+    normals->push_back(toOsg(normalize(lights.getLight(i).normal)));
   }
 
   osg::Geometry* geometry = new osg::Geometry;
   geometry->setDataVariance(osg::Object::STATIC);
   geometry->setVertexArray(vertices);
-  geometry->setNormalBinding(osg::Geometry::BIND_OFF);
-  geometry->setColorArray(colors);
-  geometry->setColorBinding(osg::Geometry::BIND_PER_VERTEX);
+  geometry->setNormalArray(normals, osg::Array::BIND_PER_VERTEX);
+  geometry->setColorArray(colors, osg::Array::BIND_PER_VERTEX);
 
   osg::DrawArrays* drawArrays;
-  drawArrays = new osg::DrawArrays(osg::PrimitiveSet::TRIANGLES,
+  drawArrays = new osg::DrawArrays(osg::PrimitiveSet::POINTS,
                                    0, vertices->size());
   geometry->addPrimitiveSet(drawArrays);
   return geometry;