Deferred Rendering with OpenSceneGraph

Hello folks! 😀

The last 3 years I was always like “I am going to make a deferred renderer soon”, but for some reason I was always postponing it! 😀 It was time to cut the BS and implement it! Because my own 3D engine is still at a very early development stage, I used OpenSceneGraph (OSG) to implement deferred shading. Why OSG? We use it a lot at work and so I am familiar with it. I did a very simple implementation with only diffuse lighting and one light. No optimizations no anything. I spent about 5 hours for reading and implementing it. I am not going to spend more time on it because it is based on OSG and not on my 3D engine.
I liked the fact that deferred shading is so easy to implement and there are no any tough maths behind it. When I will implement deferred shading in my 3D engine I might write a short tutorial for this awesome technique!

Enjoy!

5 thoughts on “Deferred Rendering with OpenSceneGraph

  1. Would you mind to share your code on this one?
    I’m currently digging into deferred rendering, and like to know how set up your render pipe for this.

    cheers
    Sebastian

    • Heya dude! Thanks for reading my blog. I am not a big fan of OSG and as a result everything I do with OSG does not stay for too long on my hard drive. I found a copy of the source but I can not guarantee that it is a working version. Here it is:
      osg_deferred.cpp
      I hope it will help you!

      Cheers,
      Bekos

      • Hey,
        Thanks a lot for sharing, the setup inside the cpp was helpful.
        Would you mind looking for the shaders you referenced inside the project?

        Thanks in advance :-)

        • Y0 dude!
          Unfortunately I didn’t keep a copy of the shaders but the whole idea is the following:

          simpleShader01 shader
          In the simpleShader01 you grab the normals and the material color and you output them into two textures like this:
          // Color texture
          gl_FragData[0] = the_material_color;
          // Normal texture
          gl_FragData[1] = vec4(the_normal_in_world_space,1.0) * 0.5 + 0.5;

          (As you can see gl_FragData is used instead of gl_FragColor)

          lightingPass shader
          This shader does the “magic”. It needs three texture sample uniforms: depth, color and normal textures.
          Let’s think now.. in order to do lighting in a forward renderer you need the following: Vertex Position, Vertex Normal, and Material Color. The normal is stored in the normal texture uniform. The material color is stored in the color texture uniform. And the position? The position can be recovered from the depth texture uniform. So.. you have all the information you need and you calculate the lighting as usual!

          I hope I was helpful! 😀
          Good luck with your deferred renderer!

          Cheers!

          • Thanks a lot. I figured out the most by myself. I just having a hard time mixing all this with the scenegraph concepts that more or less are bound to forward rendering.

            cheers
            Sebastian

Leave a Reply