]> git.mxchange.org Git - simgear.git/blob - simgear/scene/tgdb/pt_lights.cxx
dc0c599a304cb8c47e0adf29742dc5a13f2c6c6e
[simgear.git] / simgear / scene / tgdb / pt_lights.cxx
1 // pt_lights.cxx -- build a 'directional' light on the fly
2 //
3 // Written by Curtis Olson, started March 2002.
4 //
5 // Copyright (C) 2002  Curtis L. Olson  - http://www.flightgear.org/~curt
6 //
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License as
9 // published by the Free Software Foundation; either version 2 of the
10 // License, or (at your option) any later version.
11 //
12 // This program is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 // General Public License for more details.
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
20 //
21 // $Id$
22
23 #ifdef HAVE_CONFIG_H
24 #  include <simgear_config.h>
25 #endif
26
27 #include "pt_lights.hxx"
28
29 #include <map>
30 #include <boost/tuple/tuple_comparison.hpp>
31
32 #include <osg/Array>
33 #include <osg/Geometry>
34 #include <osg/CullFace>
35 #include <osg/Geode>
36 #include <osg/MatrixTransform>
37 #include <osg/NodeCallback>
38 #include <osg/NodeVisitor>
39 #include <osg/Texture2D>
40 #include <osg/AlphaFunc>
41 #include <osg/BlendFunc>
42 #include <osg/TexEnv>
43 #include <osg/Sequence>
44 #include <osg/PolygonMode>
45 #include <osg/Fog>
46 #include <osg/FragmentProgram>
47 #include <osg/VertexProgram>
48 #include <osg/Point>
49 #include <osg/PointSprite>
50 #include <osg/Material>
51 #include <osg/Group>
52 #include <osg/StateSet>
53
54 #include <osgUtil/CullVisitor>
55
56 #include <OpenThreads/Mutex>
57 #include <OpenThreads/ScopedLock>
58
59 #include <simgear/math/sg_random.h>
60 #include <simgear/debug/logstream.hxx>
61 #include <simgear/scene/util/RenderConstants.hxx>
62 #include <simgear/scene/util/SGEnlargeBoundingBox.hxx>
63 #include <simgear/scene/util/OsgMath.hxx>
64 #include <simgear/scene/util/StateAttributeFactory.hxx>
65
66 #include <simgear/scene/material/Effect.hxx>
67 #include <simgear/scene/material/EffectGeode.hxx>
68 #include <simgear/scene/material/Technique.hxx>
69 #include <simgear/scene/material/Pass.hxx>
70
71 #include "SGVasiDrawable.hxx"
72
73 using OpenThreads::Mutex;
74 using OpenThreads::ScopedLock;
75
76 using namespace osg;
77 using namespace simgear;
78
79 static void
80 setPointSpriteImage(unsigned char* data, unsigned log2resolution,
81                     unsigned charsPerPixel)
82 {
83   int env_tex_res = (1 << log2resolution);
84   for (int i = 0; i < env_tex_res; ++i) {
85     for (int j = 0; j < env_tex_res; ++j) {
86       int xi = 2*i + 1 - env_tex_res;
87       int yi = 2*j + 1 - env_tex_res;
88       if (xi < 0)
89         xi = -xi;
90       if (yi < 0)
91         yi = -yi;
92       
93       xi -= 1;
94       yi -= 1;
95       
96       if (xi < 0)
97         xi = 0;
98       if (yi < 0)
99         yi = 0;
100       
101       float x = 1.5*xi/(float)(env_tex_res);
102       float y = 1.5*yi/(float)(env_tex_res);
103       //       float x = 2*xi/(float)(env_tex_res);
104       //       float y = 2*yi/(float)(env_tex_res);
105       float dist = sqrt(x*x + y*y);
106       float bright = SGMiscf::clip(255*(1-dist), 0, 255);
107       for (unsigned l = 0; l < charsPerPixel; ++l)
108         data[charsPerPixel*(i*env_tex_res + j) + l] = (unsigned char)bright;
109     }
110   }
111 }
112
113 static osg::Image*
114 getPointSpriteImage(int logResolution)
115 {
116   osg::Image* image = new osg::Image;
117   
118   osg::Image::MipmapDataType mipmapOffsets;
119   unsigned off = 0;
120   for (int i = logResolution; 0 <= i; --i) {
121     unsigned res = 1 << i;
122     off += res*res;
123     mipmapOffsets.push_back(off);
124   }
125   
126   int env_tex_res = (1 << logResolution);
127   
128   unsigned char* imageData = new unsigned char[off];
129   image->setImage(env_tex_res, env_tex_res, 1,
130                   GL_ALPHA, GL_ALPHA, GL_UNSIGNED_BYTE, imageData,
131                   osg::Image::USE_NEW_DELETE);
132   image->setMipmapLevels(mipmapOffsets);
133   
134   for (int k = logResolution; 0 <= k; --k) {
135     setPointSpriteImage(image->getMipmapData(logResolution - k), k, 1);
136   }
137   
138   return image;
139 }
140
141 static Mutex lightMutex;
142
143 static osg::Texture2D*
144 gen_standard_light_sprite(void)
145 {
146   // Always called from when the lightMutex is already taken
147   static osg::ref_ptr<osg::Texture2D> texture;
148   if (texture.valid())
149     return texture.get();
150   
151   texture = new osg::Texture2D;
152   texture->setImage(getPointSpriteImage(6));
153   texture->setWrap(osg::Texture::WRAP_S, osg::Texture::CLAMP);
154   texture->setWrap(osg::Texture::WRAP_T, osg::Texture::CLAMP);
155   
156   return texture.get();
157 }
158
159 namespace
160 {
161 typedef boost::tuple<float, osg::Vec3, float, float, bool> PointParams;
162 typedef std::map<PointParams, observer_ptr<Effect> > EffectMap;
163
164 EffectMap effectMap;
165
166 ref_ptr<PolygonMode> polyMode = new PolygonMode(PolygonMode::FRONT,
167                                                 PolygonMode::POINT);
168 ref_ptr<PointSprite> pointSprite = new PointSprite;
169 }
170
171 Effect* getLightEffect(float size, const Vec3& attenuation,
172                        float minSize, float maxSize, bool directional)
173 {
174     PointParams pointParams(size, attenuation, minSize, maxSize, directional);
175     ScopedLock<Mutex> lock(lightMutex);
176     EffectMap::iterator eitr = effectMap.find(pointParams);
177     if (eitr != effectMap.end())
178     {
179         ref_ptr<Effect> effect;
180         if (eitr->second.lock(effect))
181             return effect.release();
182     }
183     // Basic stuff; no sprite or attenuation support
184     Pass *basicPass = new Pass;
185     basicPass->setRenderBinDetails(POINT_LIGHTS_BIN, "DepthSortedBin");
186     basicPass->setMode(GL_LIGHTING, osg::StateAttribute::OFF);
187     StateAttributeFactory *attrFact = StateAttributeFactory::instance();
188     basicPass->setAttributeAndModes(attrFact->getStandardBlendFunc());
189     basicPass->setAttributeAndModes(attrFact->getStandardAlphaFunc());
190     if (directional) {
191         basicPass->setAttributeAndModes(attrFact->getCullFaceBack());
192         basicPass->setAttribute(polyMode.get());
193     }
194     Pass *attenuationPass = clone(basicPass, CopyOp::SHALLOW_COPY);
195     osg::Point* point = new osg::Point;
196     point->setMinSize(minSize);
197     point->setMaxSize(maxSize);
198     point->setSize(size);
199     point->setDistanceAttenuation(attenuation);
200     attenuationPass->setAttributeAndModes(point);
201     Pass *spritePass = clone(basicPass, CopyOp::SHALLOW_COPY);
202     spritePass->setTextureAttributeAndModes(0, pointSprite.get(),
203                                             osg::StateAttribute::ON);
204     Texture2D* texture = gen_standard_light_sprite();
205     spritePass->setTextureAttribute(0, texture);
206     spritePass->setTextureMode(0, GL_TEXTURE_2D,
207                                osg::StateAttribute::ON);
208     spritePass->setTextureAttribute(0, attrFact->getStandardTexEnv());
209     Pass *combinedPass = clone(spritePass, CopyOp::SHALLOW_COPY);
210     combinedPass->setAttributeAndModes(point);
211     ref_ptr<Effect> effect = new Effect;
212     std::vector<std::string> parameterExtensions;
213
214     if (SGSceneFeatures::instance()->getEnablePointSpriteLights())
215     {
216         std::vector<std::string> combinedExtensions;
217         combinedExtensions.push_back("GL_ARB_point_sprite");
218         combinedExtensions.push_back("GL_ARB_point_parameters");
219         Technique* combinedTniq = new Technique;
220         combinedTniq->passes.push_back(combinedPass);
221         combinedTniq->setGLExtensionsPred(2.0, combinedExtensions);
222         effect->techniques.push_back(combinedTniq);
223         std::vector<std::string> spriteExtensions;
224         spriteExtensions.push_back(combinedExtensions.front());
225         Technique* spriteTniq = new Technique;
226         spriteTniq->passes.push_back(spritePass);
227         spriteTniq->setGLExtensionsPred(2.0, spriteExtensions);
228         effect->techniques.push_back(spriteTniq);
229         parameterExtensions.push_back(combinedExtensions.back());
230     }
231
232     Technique* parameterTniq = new Technique;
233     parameterTniq->passes.push_back(attenuationPass);
234     parameterTniq->setGLExtensionsPred(1.4, parameterExtensions);
235     effect->techniques.push_back(parameterTniq);
236     Technique* basicTniq = new Technique(true);
237     basicTniq->passes.push_back(basicPass);
238     effect->techniques.push_back(basicTniq);
239     if (eitr == effectMap.end())
240         effectMap.insert(std::make_pair(pointParams, effect));
241     else
242         eitr->second = effect; // update existing, but empty observer
243     return effect.release();
244 }
245
246
247 osg::Drawable*
248 SGLightFactory::getLightDrawable(const SGLightBin::Light& light)
249 {
250   osg::Vec3Array* vertices = new osg::Vec3Array;
251   osg::Vec4Array* colors = new osg::Vec4Array;
252
253   vertices->push_back(toOsg(light.position));
254   colors->push_back(toOsg(light.color));
255   
256   osg::Geometry* geometry = new osg::Geometry;
257   geometry->setVertexArray(vertices);
258   geometry->setNormalBinding(osg::Geometry::BIND_OFF);
259   geometry->setColorArray(colors);
260   geometry->setColorBinding(osg::Geometry::BIND_PER_VERTEX);
261
262   // Enlarge the bounding box to avoid such light nodes being victim to
263   // small feature culling.
264   geometry->setComputeBoundingBoxCallback(new SGEnlargeBoundingBox(1));
265   
266   osg::DrawArrays* drawArrays;
267   drawArrays = new osg::DrawArrays(osg::PrimitiveSet::POINTS,
268                                    0, vertices->size());
269   geometry->addPrimitiveSet(drawArrays);
270   return geometry;
271 }
272
273 osg::Drawable*
274 SGLightFactory::getLightDrawable(const SGDirectionalLightBin::Light& light)
275 {
276   osg::Vec3Array* vertices = new osg::Vec3Array;
277   osg::Vec4Array* colors = new osg::Vec4Array;
278
279   SGVec4f visibleColor(light.color);
280   SGVec4f invisibleColor(visibleColor[0], visibleColor[1],
281                          visibleColor[2], 0);
282   SGVec3f normal = normalize(light.normal);
283   SGVec3f perp1 = perpendicular(normal);
284   SGVec3f perp2 = cross(normal, perp1);
285   SGVec3f position = light.position;
286   vertices->push_back(toOsg(position));
287   vertices->push_back(toOsg(position + perp1));
288   vertices->push_back(toOsg(position + perp2));
289   colors->push_back(toOsg(visibleColor));
290   colors->push_back(toOsg(invisibleColor));
291   colors->push_back(toOsg(invisibleColor));
292   
293   osg::Geometry* geometry = new osg::Geometry;
294   geometry->setVertexArray(vertices);
295   geometry->setNormalBinding(osg::Geometry::BIND_OFF);
296   geometry->setColorArray(colors);
297   geometry->setColorBinding(osg::Geometry::BIND_PER_VERTEX);
298   // Enlarge the bounding box to avoid such light nodes being victim to
299   // small feature culling.
300   geometry->setComputeBoundingBoxCallback(new SGEnlargeBoundingBox(1));
301   
302   osg::DrawArrays* drawArrays;
303   drawArrays = new osg::DrawArrays(osg::PrimitiveSet::TRIANGLES,
304                                    0, vertices->size());
305   geometry->addPrimitiveSet(drawArrays);
306   return geometry;
307 }
308
309 namespace
310 {
311   ref_ptr<StateSet> simpleLightSS;
312 }
313 osg::Drawable*
314 SGLightFactory::getLights(const SGLightBin& lights, unsigned inc, float alphaOff)
315 {
316   if (lights.getNumLights() <= 0)
317     return 0;
318   
319   osg::Vec3Array* vertices = new osg::Vec3Array;
320   osg::Vec4Array* colors = new osg::Vec4Array;
321
322   for (unsigned i = 0; i < lights.getNumLights(); i += inc) {
323     vertices->push_back(toOsg(lights.getLight(i).position));
324     SGVec4f color = lights.getLight(i).color;
325     color[3] = SGMiscf::max(0, SGMiscf::min(1, color[3] + alphaOff));
326     colors->push_back(toOsg(color));
327   }
328   
329   osg::Geometry* geometry = new osg::Geometry;
330   
331   geometry->setVertexArray(vertices);
332   geometry->setNormalBinding(osg::Geometry::BIND_OFF);
333   geometry->setColorArray(colors);
334   geometry->setColorBinding(osg::Geometry::BIND_PER_VERTEX);
335   
336   osg::DrawArrays* drawArrays;
337   drawArrays = new osg::DrawArrays(osg::PrimitiveSet::POINTS,
338                                    0, vertices->size());
339   geometry->addPrimitiveSet(drawArrays);
340
341   {
342     ScopedLock<Mutex> lock(lightMutex);
343     if (!simpleLightSS.valid()) {
344       StateAttributeFactory *attrFact = StateAttributeFactory::instance();
345       simpleLightSS = new StateSet;
346       simpleLightSS->setRenderBinDetails(POINT_LIGHTS_BIN, "DepthSortedBin");
347       simpleLightSS->setMode(GL_LIGHTING, osg::StateAttribute::OFF);
348       simpleLightSS->setAttributeAndModes(attrFact->getStandardBlendFunc());
349       simpleLightSS->setAttributeAndModes(attrFact->getStandardAlphaFunc());
350     }
351   }
352   geometry->setStateSet(simpleLightSS.get());
353   return geometry;
354 }
355
356
357 osg::Drawable*
358 SGLightFactory::getLights(const SGDirectionalLightBin& lights)
359 {
360   if (lights.getNumLights() <= 0)
361     return 0;
362   
363   osg::Vec3Array* vertices = new osg::Vec3Array;
364   osg::Vec4Array* colors = new osg::Vec4Array;
365
366   for (unsigned i = 0; i < lights.getNumLights(); ++i) {
367     SGVec4f visibleColor(lights.getLight(i).color);
368     SGVec4f invisibleColor(visibleColor[0], visibleColor[1],
369                            visibleColor[2], 0);
370     SGVec3f normal = normalize(lights.getLight(i).normal);
371     SGVec3f perp1 = perpendicular(normal);
372     SGVec3f perp2 = cross(normal, perp1);
373     SGVec3f position = lights.getLight(i).position;
374     vertices->push_back(toOsg(position));
375     vertices->push_back(toOsg(position + perp1));
376     vertices->push_back(toOsg(position + perp2));
377     colors->push_back(toOsg(visibleColor));
378     colors->push_back(toOsg(invisibleColor));
379     colors->push_back(toOsg(invisibleColor));
380   }
381   
382   osg::Geometry* geometry = new osg::Geometry;
383   
384   geometry->setVertexArray(vertices);
385   geometry->setNormalBinding(osg::Geometry::BIND_OFF);
386   geometry->setColorArray(colors);
387   geometry->setColorBinding(osg::Geometry::BIND_PER_VERTEX);
388   
389   osg::DrawArrays* drawArrays;
390   drawArrays = new osg::DrawArrays(osg::PrimitiveSet::TRIANGLES,
391                                    0, vertices->size());
392   geometry->addPrimitiveSet(drawArrays);
393   return geometry;
394 }
395
396 static SGVasiDrawable*
397 buildVasi(const SGDirectionalLightBin& lights, const SGVec3f& up,
398        const SGVec4f& red, const SGVec4f& white)
399 {
400   unsigned count = lights.getNumLights();
401   if ( count == 4 ) {
402     SGVasiDrawable* drawable = new SGVasiDrawable(red, white);
403
404     // PAPI configuration
405     // papi D
406     drawable->addLight(lights.getLight(0).position,
407                        lights.getLight(0).normal, up, 3.5);
408     // papi C
409     drawable->addLight(lights.getLight(1).position,
410                        lights.getLight(1).normal, up, 3.167);
411     // papi B
412     drawable->addLight(lights.getLight(2).position,
413                        lights.getLight(2).normal, up, 2.833);
414     // papi A
415     drawable->addLight(lights.getLight(3).position,
416                        lights.getLight(3).normal, up, 2.5);
417     return drawable;
418
419   } else if (count == 6) {
420     SGVasiDrawable* drawable = new SGVasiDrawable(red, white);
421
422     // probably vasi, first 3 are downwind bar (2.5 deg)
423     for (unsigned i = 0; i < 3; ++i)
424       drawable->addLight(lights.getLight(i).position,
425                          lights.getLight(i).normal, up, 2.5);
426     // last 3 are upwind bar (3.0 deg)
427     for (unsigned i = 3; i < 6; ++i)
428       drawable->addLight(lights.getLight(i).position,
429                          lights.getLight(i).normal, up, 3.0);
430     return drawable;
431
432   } else if (count == 12) {
433     SGVasiDrawable* drawable = new SGVasiDrawable(red, white);
434     
435     // probably vasi, first 6 are downwind bar (2.5 deg)
436     for (unsigned i = 0; i < 6; ++i)
437       drawable->addLight(lights.getLight(i).position,
438                          lights.getLight(i).normal, up, 2.5);
439     // last 6 are upwind bar (3.0 deg)
440     for (unsigned i = 6; i < 12; ++i)
441       drawable->addLight(lights.getLight(i).position,
442                          lights.getLight(i).normal, up, 3.0);
443     return drawable;
444
445   } else {
446     // fail safe
447     SG_LOG(SG_TERRAIN, SG_ALERT,
448            "unknown vasi/papi configuration, count = " << count);
449     return 0;
450   }
451 }
452
453 osg::Drawable*
454 SGLightFactory::getVasi(const SGVec3f& up, const SGDirectionalLightBin& lights,
455                         const SGVec4f& red, const SGVec4f& white)
456 {
457   SGVasiDrawable* drawable = buildVasi(lights, up, red, white);
458   if (!drawable)
459     return 0;
460
461   osg::StateSet* stateSet = drawable->getOrCreateStateSet();
462   stateSet->setRenderBinDetails(POINT_LIGHTS_BIN, "DepthSortedBin");
463   stateSet->setMode(GL_LIGHTING, osg::StateAttribute::OFF);
464
465   osg::BlendFunc* blendFunc = new osg::BlendFunc;
466   stateSet->setAttribute(blendFunc);
467   stateSet->setMode(GL_BLEND, osg::StateAttribute::ON);
468   
469   osg::AlphaFunc* alphaFunc;
470   alphaFunc = new osg::AlphaFunc(osg::AlphaFunc::GREATER, 0.01);
471   stateSet->setAttribute(alphaFunc);
472   stateSet->setMode(GL_ALPHA_TEST, osg::StateAttribute::ON);
473
474   return drawable;
475 }
476
477 osg::Node*
478 SGLightFactory::getSequenced(const SGDirectionalLightBin& lights)
479 {
480   if (lights.getNumLights() <= 0)
481     return 0;
482
483   // generate a repeatable random seed
484   sg_srandom(unsigned(lights.getLight(0).position[0]));
485   float flashTime = 2e-2 + 5e-3*sg_random();
486   osg::Sequence* sequence = new osg::Sequence;
487   sequence->setDefaultTime(flashTime);
488   Effect* effect = getLightEffect(10.0f, osg::Vec3(1.0, 0.0001, 0.00000001),
489                                   6.0f, 10.0f, true);
490   for (int i = lights.getNumLights() - 1; 0 <= i; --i) {
491     EffectGeode* egeode = new EffectGeode;
492     egeode->setEffect(effect);
493     egeode->addDrawable(getLightDrawable(lights.getLight(i)));
494     sequence->addChild(egeode, flashTime);
495   }
496   sequence->addChild(new osg::Group, 1 + 1e-1*sg_random());
497   sequence->setInterval(osg::Sequence::LOOP, 0, -1);
498   sequence->setDuration(1.0f, -1);
499   sequence->setMode(osg::Sequence::START);
500   sequence->setSync(true);
501   return sequence;
502 }
503
504 osg::Node*
505 SGLightFactory::getOdal(const SGLightBin& lights)
506 {
507   if (lights.getNumLights() < 2)
508     return 0;
509
510   // generate a repeatable random seed
511   sg_srandom(unsigned(lights.getLight(0).position[0]));
512   float flashTime = 2e-2 + 5e-3*sg_random();
513   osg::Sequence* sequence = new osg::Sequence;
514   sequence->setDefaultTime(flashTime);
515   Effect* effect = getLightEffect(10.0f, osg::Vec3(1.0, 0.0001, 0.00000001),
516                                   6.0, 10.0, false);
517   // centerline lights
518   for (int i = lights.getNumLights(); i > 1; --i) {
519     EffectGeode* egeode = new EffectGeode;
520     egeode->setEffect(effect);
521     egeode->addDrawable(getLightDrawable(lights.getLight(i)));
522     sequence->addChild(egeode, flashTime);
523   }
524   // runway end lights
525   osg::Group* group = new osg::Group;
526   for (unsigned i = 0; i < 2; ++i) {
527     EffectGeode* egeode = new EffectGeode;
528     egeode->setEffect(effect);
529     egeode->addDrawable(getLightDrawable(lights.getLight(i)));
530     group->addChild(egeode);
531   }
532   sequence->addChild(group, flashTime);
533
534   // add an extra empty group for a break
535   sequence->addChild(new osg::Group, 2 + 1e-1*sg_random());
536   sequence->setInterval(osg::Sequence::LOOP, 0, -1);
537   sequence->setDuration(1.0f, -1);
538   sequence->setMode(osg::Sequence::START);
539   sequence->setSync(true);
540
541   return sequence;
542 }
543
544 // Blinking hold short line lights
545 osg::Node*
546 SGLightFactory::getHoldShort(const SGDirectionalLightBin& lights)
547 {
548   if (lights.getNumLights() < 2)
549     return 0;
550
551   sg_srandom(unsigned(lights.getLight(0).position[0]));
552   float flashTime = 1 + 0.1 * sg_random();
553   osg::Sequence* sequence = new osg::Sequence;
554
555   // start with lights off
556   sequence->addChild(new osg::Group, flashTime);
557   // ...and increase the lights in steps
558   for (int i = 2; i < 7; i+=2) {
559       Effect* effect = getLightEffect(i, osg::Vec3(1, 0.001, 0.000002),
560                                       0.0f, i, true);
561       EffectGeode* egeode = new EffectGeode;
562       for (unsigned int j = 0; j < lights.getNumLights(); ++j) {
563           egeode->addDrawable(getLightDrawable(lights.getLight(j)));
564           egeode->setEffect(effect);
565       }
566       sequence->addChild(egeode, (i==6) ? flashTime : 0.1);
567   }
568
569   sequence->setInterval(osg::Sequence::SWING, 0, -1);
570   sequence->setDuration(1.0f, -1);
571   sequence->setMode(osg::Sequence::START);
572
573   return sequence;
574 }
575
576 // Alternating runway guard lights ("wig-wag")
577 osg::Node*
578 SGLightFactory::getGuard(const SGDirectionalLightBin& lights)
579 {
580   if (lights.getNumLights() < 2)
581     return 0;
582
583   // generate a repeatable random seed
584   sg_srandom(unsigned(lights.getLight(0).position[0]));
585   float flashTime = 1.0f + 1*sg_random();
586   osg::Sequence* sequence = new osg::Sequence;
587   sequence->setDefaultTime(flashTime);
588   Effect* effect = getLightEffect(10.0f, osg::Vec3(1.0, 0.001, 0.000002),
589                                   0.0f, 8.0f, true);
590   for (unsigned int i = 0; i < lights.getNumLights(); ++i) {
591     EffectGeode* egeode = new EffectGeode;
592     egeode->setEffect(effect);
593     egeode->addDrawable(getLightDrawable(lights.getLight(i)));
594     sequence->addChild(egeode, flashTime);
595   }
596   sequence->setInterval(osg::Sequence::LOOP, 0, -1);
597   sequence->setDuration(1.0f, -1);
598   sequence->setMode(osg::Sequence::START);
599   sequence->setSync(true);
600   return sequence;
601 }