2 #include "CloudScene.h"
20 HUD(osg::ref_ptr<osg::Texture> debug_tex);
44 virtual void SetupUniform(osg::ref_ptr<osg::StateSet> states);
49 virtual void SetupTextures(osg::ref_ptr<osg::StateSet> states);
79 osg::ref_ptr<osg::Texture2D> m_scenetex;
80 osg::ref_ptr<osg::Texture2D> m_goodraytex;
81 osg::ref_ptr<osg::Texture2D> m_cloudtex;
83 osg::ref_ptr<osg::Program> sh_blur_linear;
84 osg::ref_ptr<osg::Uniform> uniform_blur_texsize;
86 osg::ref_ptr<osg::Uniform> uniform_avg_texsize;
87 osg::ref_ptr<osg::Program> sh_lum;
89 osg::ref_ptr<osg::Camera> cam_hud;
90 osg::ref_ptr<osg::StateSet> nodessP;
91 osg::ref_ptr<osg::Program> planeProg;
92 osg::ref_ptr<osg::Geode> plane;
96 osg::ref_ptr<osg::Texture> m_debug_tex;
99 static osg::ref_ptr<osg::Texture2D> fbo_lum0_texture;
100 static osg::ref_ptr<osg::Texture2D> fbo_lum1_texture;
101 static osg::ref_ptr<osg::Texture2D> fbo_lum2_texture;
102 static osg::ref_ptr<osg::Texture2D> fbo_lum3_texture;
103 static osg::ref_ptr<osg::Texture2D> fbo_lum4_texture;
104 static osg::FrameBufferObject* fbo_Lum0;
105 static osg::FrameBufferObject* fbo_Lum1;
106 static osg::FrameBufferObject* fbo_Lum2;
107 static osg::FrameBufferObject* fbo_Lum3;
108 static osg::FrameBufferObject* fbo_Lum4;
113 static osg::ref_ptr<osg::Texture2D> fbo_blurV1_texture;
114 static osg::ref_ptr<osg::Texture2D> fbo_blurV2_texture;
115 static osg::ref_ptr<osg::Texture2D> fbo_blurV3_texture;
116 static osg::ref_ptr<osg::Texture2D> fbo_blurV4_texture;
118 static osg::ref_ptr<osg::Texture2D> fbo_blurH1_texture;
119 static osg::ref_ptr<osg::Texture2D> fbo_blurH2_texture;
120 static osg::ref_ptr<osg::Texture2D> fbo_blurH3_texture;
121 static osg::ref_ptr<osg::Texture2D> fbo_blurH4_texture;
123 static osg::ref_ptr<osg::Texture2D> fbo_star1_texture;
124 static osg::ref_ptr<osg::Texture2D> fbo_star2_texture;
125 static osg::ref_ptr<osg::Texture2D> fbo_star3_texture;
126 static osg::ref_ptr<osg::Texture2D> fbo_star4_texture;
128 static osg::FrameBufferObject* fbo_V1_blur;
129 static osg::FrameBufferObject* fbo_H1_blur;
130 static osg::FrameBufferObject* fbo_V2_blur;
131 static osg::FrameBufferObject* fbo_H2_blur;
132 static osg::FrameBufferObject* fbo_V3_blur;
133 static osg::FrameBufferObject* fbo_H3_blur;
134 static osg::FrameBufferObject* fbo_V4_blur;
135 static osg::FrameBufferObject* fbo_H4_blur;
137 static osg::ref_ptr<osg::Texture2D> fbo_glare_texture;
162 osg::ref_ptr<osg::Texture2D> _fbo_scene_texture,
163 osg::ref_ptr<osg::FrameBufferObject> _fbo_Lum0,
164 osg::ref_ptr<osg::FrameBufferObject> _fbo_Lum1,
165 osg::ref_ptr<osg::FrameBufferObject> _fbo_Lum2,
166 osg::ref_ptr<osg::FrameBufferObject> _fbo_Lum3,
167 osg::ref_ptr<osg::FrameBufferObject> _fbo_Lum4,
168 osg::ref_ptr<osg::Texture2D> _fbo_lum0,
169 osg::ref_ptr<osg::Texture2D> _fbo_lum1,
170 osg::ref_ptr<osg::Texture2D> _fbo_lum2,
171 osg::ref_ptr<osg::Texture2D> _fbo_lum3,
172 osg::ref_ptr<osg::Texture2D> _fbo_lum4)
174 sh_blur_linear_vert1 = (prog_vert1);
176 fbo_scene_texture = _fbo_scene_texture;
178 fbo_Lum0 = _fbo_Lum0;
179 fbo_Lum1 = _fbo_Lum1;
180 fbo_Lum2 = _fbo_Lum2;
181 fbo_Lum3 = _fbo_Lum3,
182 fbo_Lum4 = _fbo_Lum4;
183 fbo_lum0_texture = _fbo_lum0;
184 fbo_lum1_texture = _fbo_lum1;
185 fbo_lum2_texture = _fbo_lum2;
186 fbo_lum3_texture = _fbo_lum3;
187 fbo_lum4_texture = _fbo_lum4;
202 if (_internalOptimizedGeometry.valid())
204 _internalOptimizedGeometry->drawImplementation(renderInfo);
208 osg::State& state = *renderInfo.getState();
210 bool checkForGLErrors = state.getCheckForGLErrors()==osg::State::ONCE_PER_ATTRIBUTE;
211 if (checkForGLErrors) state.checkGLErrors(
"start of Geometry::drawImplementation()");
213 bool useFastPath = areFastPathsUsed();
216 bool usingVertexBufferObjects = _useVertexBufferObjects && state.isVertexBufferObjectSupported();
217 bool handleVertexAttributes = !_vertexAttribList.empty();
219 osg::ArrayDispatchers& arrayDispatchers = state.getArrayDispatchers();
221 arrayDispatchers.reset();
222 arrayDispatchers.setUseVertexAttribAlias(useFastPath && state.getUseVertexAttributeAliasing());
223 arrayDispatchers.setUseGLBeginEndAdapter(!useFastPath);
225 arrayDispatchers.activateNormalArray(_normalData.binding, _normalData.array.get(), _normalData.indices.get());
226 arrayDispatchers.activateColorArray(_colorData.binding, _colorData.array.get(), _colorData.indices.get());
227 arrayDispatchers.activateSecondaryColorArray(_secondaryColorData.binding, _secondaryColorData.array.get(), _secondaryColorData.indices.get());
228 arrayDispatchers.activateFogCoordArray(_fogCoordData.binding, _fogCoordData.array.get(), _fogCoordData.indices.get());
230 if (handleVertexAttributes)
232 for(
unsigned int unit=0;unit<_vertexAttribList.size();++unit)
234 arrayDispatchers.activateVertexAttribArray(_vertexAttribList[unit].binding, unit, _vertexAttribList[unit].array.get(), _vertexAttribList[unit].indices.get());
239 arrayDispatchers.dispatch(BIND_OVERALL,0);
241 state.lazyDisablingOfVertexAttributes();
246 if( _vertexData.array.valid() )
247 state.setVertexPointer(_vertexData.array.get());
249 if (_normalData.binding==BIND_PER_VERTEX && _normalData.array.valid())
250 state.setNormalPointer(_normalData.array.get());
252 if (_colorData.binding==BIND_PER_VERTEX && _colorData.array.valid())
253 state.setColorPointer(_colorData.array.get());
255 if (_secondaryColorData.binding==BIND_PER_VERTEX && _secondaryColorData.array.valid())
256 state.setSecondaryColorPointer(_secondaryColorData.array.get());
258 if (_fogCoordData.binding==BIND_PER_VERTEX && _fogCoordData.array.valid())
259 state.setFogCoordPointer(_fogCoordData.array.get());
261 for(
unsigned int unit=0;unit<_texCoordList.size();++unit)
263 const osg::Array* array = _texCoordList[unit].array.get();
264 if (array) state.setTexCoordPointer(unit,array);
267 if( handleVertexAttributes )
269 for(
unsigned int index = 0; index < _vertexAttribList.size(); ++index )
271 const osg::Array* array = _vertexAttribList[index].array.get();
272 const AttributeBinding ab = _vertexAttribList[index].binding;
273 if( ab == BIND_PER_VERTEX && array )
275 state.setVertexAttribPointer( index, array, _vertexAttribList[index].normalize );
282 for(
unsigned int unit=0;unit<_texCoordList.size();++unit)
284 arrayDispatchers.activateTexCoordArray(BIND_PER_VERTEX, unit, _texCoordList[unit].array.get(), _texCoordList[unit].indices.get());
287 arrayDispatchers.activateVertexArray(BIND_PER_VERTEX, _vertexData.array.get(), _vertexData.indices.get());
290 state.applyDisablingOfVertexAttributes();
292 bool bindPerPrimitiveSetActive = arrayDispatchers.active(BIND_PER_PRIMITIVE_SET);
293 bool bindPerPrimitiveActive = arrayDispatchers.active(BIND_PER_PRIMITIVE);
295 if (checkForGLErrors) state.checkGLErrors(
"Geometry::drawImplementation() after vertex arrays setup.");
298 osg::GL2Extensions* extension = osg::GL2Extensions::Get(0,
true);
300 glClearColor(0.f, 0.f, 0.f, 0.f);
307 fbo_Lum0->apply(state, osg::FrameBufferObject::READ_DRAW_FRAMEBUFFER);
308 glViewport(0,0,256, 256);
309 glClear( GL_COLOR_BUFFER_BIT);
311 fbo_Lum1->apply(state, osg::FrameBufferObject::READ_DRAW_FRAMEBUFFER);
312 glViewport(0,0,64, 64);
313 glClear( GL_COLOR_BUFFER_BIT);
315 fbo_Lum2->apply(state, osg::FrameBufferObject::READ_DRAW_FRAMEBUFFER);
316 glViewport(0,0,16, 16);
317 glClear( GL_COLOR_BUFFER_BIT);
319 fbo_Lum3->apply(state, osg::FrameBufferObject::READ_DRAW_FRAMEBUFFER);
320 glViewport(0,0,4, 4);
321 glClear( GL_COLOR_BUFFER_BIT);
323 fbo_Lum4->apply(state, osg::FrameBufferObject::READ_DRAW_FRAMEBUFFER);
324 glViewport(0,0,1, 1);
325 glClear( GL_COLOR_BUFFER_BIT);
332 for(
unsigned int primitiveSetNum=0; primitiveSetNum!= _primitives.size() ; ++primitiveSetNum)
335 if (bindPerPrimitiveSetActive)
336 arrayDispatchers.dispatch(BIND_PER_PRIMITIVE_SET, primitiveSetNum);
338 const osg::PrimitiveSet* primitiveset = _primitives[primitiveSetNum].get();
341 glDisable(GL_DEPTH_TEST);
342 glDisable(GL_CULL_FACE);
344 osg::State& state = *renderInfo.getState();
346 osg::Depth* depth2 =
new osg::Depth(osg::Depth::ALWAYS, 0.0, 1.0,
false);
347 depth2->apply(state);
350 glViewport(0, 0, 256, 256);
351 sh_blur_linear_vert1->apply(state);
352 state.applyTextureAttribute(0, fbo_scene_texture);
353 fbo_Lum0->apply(state, osg::FrameBufferObject::READ_DRAW_FRAMEBUFFER);
354 uniform_avg_texsize->set(256.f);
355 uniform_avg_texsize->apply(extension, state.getUniformLocation(
"texsize"));
356 primitiveset->draw(state, usingVertexBufferObjects);
358 glViewport(0, 0, 64, 64);
359 sh_blur_linear_vert1->apply(state);
360 state.applyTextureAttribute(0, fbo_lum0_texture);
361 fbo_Lum1->apply(state, osg::FrameBufferObject::READ_DRAW_FRAMEBUFFER);
362 uniform_avg_texsize->set(64.f);
363 uniform_avg_texsize->apply(extension, state.getUniformLocation(
"texsize"));
364 primitiveset->draw(state, usingVertexBufferObjects);
366 glViewport(0, 0, 16, 16);
367 sh_blur_linear_vert1->apply(state);
368 state.applyTextureAttribute(0, fbo_lum1_texture);
369 fbo_Lum2->apply(state, osg::FrameBufferObject::READ_DRAW_FRAMEBUFFER);
370 uniform_avg_texsize->set(16.f);
371 uniform_avg_texsize->apply(extension, state.getUniformLocation(
"texsize"));
372 primitiveset->draw(state, usingVertexBufferObjects);
374 glViewport(0, 0, 4, 4);
375 sh_blur_linear_vert1->apply(state);
376 state.applyTextureAttribute(0, fbo_lum2_texture);
377 fbo_Lum3->apply(state, osg::FrameBufferObject::READ_DRAW_FRAMEBUFFER);
378 uniform_avg_texsize->set(4.f);
379 uniform_avg_texsize->apply(extension, state.getUniformLocation(
"texsize"));
380 primitiveset->draw(state, usingVertexBufferObjects);
382 glViewport(0, 0, 1, 1);
383 sh_blur_linear_vert1->apply(state);
384 state.applyTextureAttribute(0, fbo_lum3_texture);
385 fbo_Lum4->apply(state, osg::FrameBufferObject::READ_DRAW_FRAMEBUFFER);
386 uniform_avg_texsize->set(1.f);
387 uniform_avg_texsize->apply(extension, state.getUniformLocation(
"texsize"));
388 primitiveset->draw(state, usingVertexBufferObjects);
391 glEnable(GL_DEPTH_TEST);
395 state.unbindVertexBufferObject();
396 state.unbindElementBufferObject();
398 if (checkForGLErrors) state.checkGLErrors(
"end of Geometry::drawImplementation().");
402 osg::ref_ptr<osg::Uniform> uniform_avg_texsize;
405 osg::ref_ptr<osg::Program> sh_blur_linear_vert1;
406 osg::ref_ptr<osg::FrameBufferObject> fbo_Lum0;
407 osg::ref_ptr<osg::FrameBufferObject> fbo_Lum1;
408 osg::ref_ptr<osg::FrameBufferObject> fbo_Lum2;
409 osg::ref_ptr<osg::FrameBufferObject> fbo_Lum3;
410 osg::ref_ptr<osg::FrameBufferObject> fbo_Lum4;
411 osg::ref_ptr<osg::Texture2D> fbo_lum0_texture;
412 osg::ref_ptr<osg::Texture2D> fbo_lum1_texture;
413 osg::ref_ptr<osg::Texture2D> fbo_lum2_texture;
414 osg::ref_ptr<osg::Texture2D> fbo_lum3_texture;
415 osg::ref_ptr<osg::Texture2D> fbo_lum4_texture;
418 osg::ref_ptr<osg::Texture2D> fbo_scene_texture;
427 BlurGeometry( osg::ref_ptr<osg::Program> prog_vert1,
int mode,
428 osg::ref_ptr<osg::Texture2D> _fbo_glare_texture,
429 osg::ref_ptr<osg::Uniform> _uniform_blur_texsize,
431 osg::ref_ptr<osg::FrameBufferObject> _fbo_V1_blur, osg::ref_ptr<osg::FrameBufferObject> _fbo_H1_blur,
432 osg::ref_ptr<osg::FrameBufferObject> _fbo_V2_blur, osg::ref_ptr<osg::FrameBufferObject> _fbo_H2_blur,
433 osg::ref_ptr<osg::FrameBufferObject> _fbo_V3_blur, osg::ref_ptr<osg::FrameBufferObject> _fbo_H3_blur,
434 osg::ref_ptr<osg::FrameBufferObject> _fbo_V4_blur, osg::ref_ptr<osg::FrameBufferObject> _fbo_H4_blur,
436 osg::ref_ptr<osg::Texture2D> _fbo_blurV1_texture, osg::ref_ptr<osg::Texture2D> _fbo_blurH1_texture,
437 osg::ref_ptr<osg::Texture2D> _fbo_blurV2_texture, osg::ref_ptr<osg::Texture2D> _fbo_blurH2_texture,
438 osg::ref_ptr<osg::Texture2D> _fbo_blurV3_texture, osg::ref_ptr<osg::Texture2D> _fbo_blurH3_texture,
439 osg::ref_ptr<osg::Texture2D> _fbo_blurV4_texture, osg::ref_ptr<osg::Texture2D> _fbo_blurH4_texture
442 sh_blur_linear_vert1 = (prog_vert1);
445 fbo_glare_texture = _fbo_glare_texture;
446 uniform_blur_texsize = _uniform_blur_texsize;
448 fbo_V1_blur = _fbo_V1_blur; fbo_H1_blur = _fbo_H1_blur;
449 fbo_V2_blur = _fbo_V2_blur; fbo_H2_blur = _fbo_H2_blur;
450 fbo_V3_blur = _fbo_V3_blur; fbo_H3_blur = _fbo_H3_blur;
451 fbo_V4_blur = _fbo_V4_blur; fbo_H4_blur = _fbo_H4_blur;
453 fbo_blurV1_texture = _fbo_blurV1_texture; fbo_blurH4_texture = _fbo_blurH1_texture;
454 fbo_blurV2_texture = _fbo_blurV2_texture; fbo_blurH4_texture = _fbo_blurH2_texture;
455 fbo_blurV3_texture = _fbo_blurV3_texture; fbo_blurH4_texture = _fbo_blurH3_texture;
456 fbo_blurV4_texture = _fbo_blurV4_texture; fbo_blurH4_texture = _fbo_blurH4_texture;
471 if (_internalOptimizedGeometry.valid())
473 _internalOptimizedGeometry->drawImplementation(renderInfo);
477 osg::State& state = *renderInfo.getState();
479 bool checkForGLErrors = state.getCheckForGLErrors()==osg::State::ONCE_PER_ATTRIBUTE;
480 if (checkForGLErrors) state.checkGLErrors(
"start of Geometry::drawImplementation()");
482 bool useFastPath = areFastPathsUsed();
485 bool usingVertexBufferObjects = _useVertexBufferObjects && state.isVertexBufferObjectSupported();
486 bool handleVertexAttributes = !_vertexAttribList.empty();
488 osg::ArrayDispatchers& arrayDispatchers = state.getArrayDispatchers();
490 arrayDispatchers.reset();
491 arrayDispatchers.setUseVertexAttribAlias(useFastPath && state.getUseVertexAttributeAliasing());
492 arrayDispatchers.setUseGLBeginEndAdapter(!useFastPath);
494 arrayDispatchers.activateNormalArray(_normalData.binding, _normalData.array.get(), _normalData.indices.get());
495 arrayDispatchers.activateColorArray(_colorData.binding, _colorData.array.get(), _colorData.indices.get());
496 arrayDispatchers.activateSecondaryColorArray(_secondaryColorData.binding, _secondaryColorData.array.get(), _secondaryColorData.indices.get());
497 arrayDispatchers.activateFogCoordArray(_fogCoordData.binding, _fogCoordData.array.get(), _fogCoordData.indices.get());
499 if (handleVertexAttributes)
501 for(
unsigned int unit=0;unit<_vertexAttribList.size();++unit)
503 arrayDispatchers.activateVertexAttribArray(_vertexAttribList[unit].binding, unit, _vertexAttribList[unit].array.get(), _vertexAttribList[unit].indices.get());
508 arrayDispatchers.dispatch(BIND_OVERALL,0);
510 state.lazyDisablingOfVertexAttributes();
515 if( _vertexData.array.valid() )
516 state.setVertexPointer(_vertexData.array.get());
518 if (_normalData.binding==BIND_PER_VERTEX && _normalData.array.valid())
519 state.setNormalPointer(_normalData.array.get());
521 if (_colorData.binding==BIND_PER_VERTEX && _colorData.array.valid())
522 state.setColorPointer(_colorData.array.get());
524 if (_secondaryColorData.binding==BIND_PER_VERTEX && _secondaryColorData.array.valid())
525 state.setSecondaryColorPointer(_secondaryColorData.array.get());
527 if (_fogCoordData.binding==BIND_PER_VERTEX && _fogCoordData.array.valid())
528 state.setFogCoordPointer(_fogCoordData.array.get());
530 for(
unsigned int unit=0;unit<_texCoordList.size();++unit)
532 const osg::Array* array = _texCoordList[unit].array.get();
533 if (array) state.setTexCoordPointer(unit,array);
536 if( handleVertexAttributes )
538 for(
unsigned int index = 0; index < _vertexAttribList.size(); ++index )
540 const osg::Array* array = _vertexAttribList[index].array.get();
541 const AttributeBinding ab = _vertexAttribList[index].binding;
542 if( ab == BIND_PER_VERTEX && array )
544 state.setVertexAttribPointer( index, array, _vertexAttribList[index].normalize );
551 for(
unsigned int unit=0;unit<_texCoordList.size();++unit)
553 arrayDispatchers.activateTexCoordArray(BIND_PER_VERTEX, unit, _texCoordList[unit].array.get(), _texCoordList[unit].indices.get());
556 arrayDispatchers.activateVertexArray(BIND_PER_VERTEX, _vertexData.array.get(), _vertexData.indices.get());
559 state.applyDisablingOfVertexAttributes();
561 bool bindPerPrimitiveSetActive = arrayDispatchers.active(BIND_PER_PRIMITIVE_SET);
562 bool bindPerPrimitiveActive = arrayDispatchers.active(BIND_PER_PRIMITIVE);
564 if (checkForGLErrors) state.checkGLErrors(
"Geometry::drawImplementation() after vertex arrays setup.");
567 osg::GL2Extensions* extension = osg::GL2Extensions::Get(0,
true);
569 glClearColor(0.f, 0.1f, 0.f, 1.f);
577 fbo_V1_blur->apply(state, osg::FrameBufferObject::READ_DRAW_FRAMEBUFFER);
579 glClear( GL_COLOR_BUFFER_BIT);
581 fbo_H1_blur->apply(state, osg::FrameBufferObject::READ_DRAW_FRAMEBUFFER);
582 glClear( GL_COLOR_BUFFER_BIT);
585 fbo_V2_blur->apply(state, osg::FrameBufferObject::READ_DRAW_FRAMEBUFFER);
587 glClear( GL_COLOR_BUFFER_BIT);
589 fbo_H2_blur->apply(state, osg::FrameBufferObject::READ_DRAW_FRAMEBUFFER);
590 glClear( GL_COLOR_BUFFER_BIT);
593 fbo_V3_blur->apply(state, osg::FrameBufferObject::READ_DRAW_FRAMEBUFFER);
595 glClear( GL_COLOR_BUFFER_BIT);
597 fbo_H3_blur->apply(state, osg::FrameBufferObject::READ_DRAW_FRAMEBUFFER);
598 glClear( GL_COLOR_BUFFER_BIT);
601 fbo_V4_blur->apply(state, osg::FrameBufferObject::READ_DRAW_FRAMEBUFFER);
603 glClear( GL_COLOR_BUFFER_BIT);
605 fbo_H4_blur->apply(state, osg::FrameBufferObject::READ_DRAW_FRAMEBUFFER);
606 glClear( GL_COLOR_BUFFER_BIT);
612 for(
unsigned int primitiveSetNum=0; primitiveSetNum!= _primitives.size() ; ++primitiveSetNum)
615 if (bindPerPrimitiveSetActive)
616 arrayDispatchers.dispatch(BIND_PER_PRIMITIVE_SET, primitiveSetNum);
618 const osg::PrimitiveSet* primitiveset = _primitives[primitiveSetNum].get();
621 glDisable(GL_DEPTH_TEST);
622 glDisable(GL_CULL_FACE);
624 osg::State& state = *renderInfo.getState();
626 osg::Depth* depth2 =
new osg::Depth(osg::Depth::ALWAYS, 0.0, 1.0,
false);
627 depth2->apply(state);
632 sh_blur_linear_vert1->apply(state);
633 state.applyTextureAttribute(0, fbo_glare_texture);
634 fbo_V1_blur->apply(state, osg::FrameBufferObject::READ_DRAW_FRAMEBUFFER);
636 uniform_blur_texsize->apply(extension, state.getUniformLocation(
"texsize"));
637 primitiveset->draw(state, usingVertexBufferObjects);
640 sh_blur_linear_vert1->apply(state);
641 state.applyTextureAttribute(0, fbo_glare_texture);
642 fbo_V2_blur->apply(state, osg::FrameBufferObject::READ_DRAW_FRAMEBUFFER);
644 uniform_blur_texsize->apply(extension, state.getUniformLocation(
"texsize"));
645 primitiveset->draw(state, usingVertexBufferObjects);
648 sh_blur_linear_vert1->apply(state);
649 state.applyTextureAttribute(0, fbo_glare_texture);
650 fbo_V3_blur->apply(state, osg::FrameBufferObject::READ_DRAW_FRAMEBUFFER);
652 uniform_blur_texsize->apply(extension, state.getUniformLocation(
"texsize"));
653 primitiveset->draw(state, usingVertexBufferObjects);
656 sh_blur_linear_vert1->apply(state);
657 state.applyTextureAttribute(0, fbo_glare_texture);
658 fbo_V4_blur->apply(state, osg::FrameBufferObject::READ_DRAW_FRAMEBUFFER);
660 uniform_blur_texsize->apply(extension, state.getUniformLocation(
"texsize"));
661 primitiveset->draw(state, usingVertexBufferObjects);
666 sh_blur_linear_vert1->apply(state);
667 state.applyTextureAttribute(0, fbo_blurV1_texture);
668 state.applyTextureAttribute(1, fbo_glare_texture);
669 fbo_H1_blur->apply(state, osg::FrameBufferObject::READ_DRAW_FRAMEBUFFER);
671 uniform_blur_texsize->apply(extension, state.getUniformLocation(
"texsize"));
672 primitiveset->draw(state, usingVertexBufferObjects);
675 sh_blur_linear_vert1->apply(state);
676 state.applyTextureAttribute(0, fbo_blurV2_texture);
677 state.applyTextureAttribute(1, fbo_glare_texture);
678 fbo_H2_blur->apply(state, osg::FrameBufferObject::READ_DRAW_FRAMEBUFFER);
680 uniform_blur_texsize->apply(extension, state.getUniformLocation(
"texsize"));
681 primitiveset->draw(state, usingVertexBufferObjects);
684 sh_blur_linear_vert1->apply(state);
685 state.applyTextureAttribute(0, fbo_blurV3_texture);
686 state.applyTextureAttribute(1, fbo_glare_texture);
687 fbo_H3_blur->apply(state, osg::FrameBufferObject::READ_DRAW_FRAMEBUFFER);
689 uniform_blur_texsize->apply(extension, state.getUniformLocation(
"texsize"));
690 primitiveset->draw(state, usingVertexBufferObjects);
693 sh_blur_linear_vert1->apply(state);
694 state.applyTextureAttribute(0, fbo_blurV4_texture);
695 state.applyTextureAttribute(1, fbo_glare_texture);
696 fbo_H4_blur->apply(state, osg::FrameBufferObject::READ_DRAW_FRAMEBUFFER);
698 uniform_blur_texsize->apply(extension, state.getUniformLocation(
"texsize"));
699 primitiveset->draw(state, usingVertexBufferObjects);
703 glEnable(GL_DEPTH_TEST);
707 state.unbindVertexBufferObject();
708 state.unbindElementBufferObject();
710 if (checkForGLErrors) state.checkGLErrors(
"end of Geometry::drawImplementation().");
716 osg::ref_ptr<osg::Program> sh_blur_linear_vert1;
718 osg::ref_ptr<osg::FrameBufferObject> fbo_V1_blur; osg::ref_ptr<osg::FrameBufferObject> fbo_H1_blur;
719 osg::ref_ptr<osg::FrameBufferObject> fbo_V2_blur; osg::ref_ptr<osg::FrameBufferObject> fbo_H2_blur;
720 osg::ref_ptr<osg::FrameBufferObject> fbo_V3_blur; osg::ref_ptr<osg::FrameBufferObject> fbo_H3_blur;
721 osg::ref_ptr<osg::FrameBufferObject> fbo_V4_blur; osg::ref_ptr<osg::FrameBufferObject> fbo_H4_blur;
723 osg::ref_ptr<osg::Texture2D> fbo_blurV1_texture; osg::ref_ptr<osg::Texture2D> fbo_blurH1_texture;
724 osg::ref_ptr<osg::Texture2D> fbo_blurV2_texture; osg::ref_ptr<osg::Texture2D> fbo_blurH2_texture;
725 osg::ref_ptr<osg::Texture2D> fbo_blurV3_texture; osg::ref_ptr<osg::Texture2D> fbo_blurH3_texture;
726 osg::ref_ptr<osg::Texture2D> fbo_blurV4_texture; osg::ref_ptr<osg::Texture2D> fbo_blurH4_texture;
728 osg::ref_ptr<osg::Texture2D> fbo_glare_texture;
729 osg::ref_ptr<osg::Uniform> uniform_blur_texsize;
744 : osg::Drawable::DrawCallback()
746 , _texture2(texture2)
762 osg::FBOExtensions* fbo_ext = osg::FBOExtensions::instance(ri.getContextID(),
true);
763 ri.getState()->setActiveTextureUnit(0);
764 ri.getState()->applyTextureAttribute(0, _texture);
766 _texture->getTextureObject(ri.getContextID())->bind();
769 ri.getState()->setActiveTextureUnit(1);
770 ri.getState()->applyTextureAttribute(1, _texture2);
772 _texture2->getTextureObject(ri.getContextID())->bind();
775 dr->drawImplementation(ri);
778 osg::Texture* _texture;
779 osg::Texture* _texture2;
803 virtual void operator()(osg::Node* node, osg::NodeVisitor* nv)
806 osgUtil::CullVisitor* cv =
dynamic_cast<osgUtil::CullVisitor*
>(nv);
807 osg::ref_ptr<osg::Geode> geometry =
dynamic_cast<osg::Geode*
> (node);
811 osg::RefMatrixd* m = cv->getModelViewMatrix();
814 osg::Matrixd worldmat = invViewMatrix * (*m);
815 osg::Matrixd invWorldMatrix = osg::Matrixd::inverse(worldmat);
818 geometry->getOrCreateStateSet()->getUniform(
"ModelViewMatrix")->set(viewMatrix*worldmat);
819 geometry->getOrCreateStateSet()->getUniform(
"ViewMatrix")->set(viewMatrix);
820 if(Scene::m_skydome != 0)
822 osg::Vec3 lightpos = Scene::m_skydome->GetLightPosition();
823 geometry->getOrCreateStateSet()->getUniform(
"un_lightPos")->set(lightpos);