Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 6 of 6

Thread: OpenGL, offscreen hard shadows calculation with stencil

  1. #1
    Intern Contributor
    Join Date
    Dec 2011
    Posts
    56

    OpenGL, offscreen hard shadows calculation with stencil

    I am trying to figure it out if and how would be possible to calculate hard shadows from multiple light-sources off-screen.

    preamble: scene is very complex, up to several million of triangles, up to hundred different light-sources, lights, material and depth enabled and maximum precision (at least 10kx10k pixel ground resolution). Shadows are nothing else than planar projected shadow, that is I am rendering the objects themselves by pre-multiplying by a shadow matrix (given a light-source position and a plane). Multiple objects, multiple light-sources but just a single plane.

    For this reason real-time is impossible. Also impossible is to think about an incremental stencil value, since I have only one byte (255 useful values) and I may have more than 255 light-sources.

    Therefore my idea was to render off-screen (to texture or render-buffer image).

    For each light source, I calculate my shadow matrix and apply it. Then I render my first object with a specific stencil number (i.e. 1). Then I render my second object. I need to render it only where the stencil number is 1 and I need to zero all the other pixels, because I am interested in the hard shadow only. Then the third object and so on. At the end I repeat all the process for the second light source and so on.

    Is it possible? Better texture or render-buffer image? Once hard shadow is calculated I need to retrieve it back on the cpu to analyze it and render it also on the ground in my scene.

    Ideally I would need only the stencil buffer attached to my FBO but they say here https://www.opengl.org/wiki/Framebuffer_Object_Examples:

    Stencil NEVER EVER MAKE A STENCIL buffer. All GPUs and all drivers do not support an independent stencil buffer. If you need a stencil buffer, then you need to make a Depth=24, Stencil=8 buffer, also called D24S8. Please search for the example about GL_EXT_packed_depth_stencil on this age.

    Is this still valid today?

    Looking around, I found here http://stackoverflow.com/questions/7570215/opengl-es-stencil-operations a way of zeroing all the other pixels by render a full screen polygon between each object, but I wonder if there is anything more efficient..?
    Last edited by elect; 03-12-2013 at 12:19 AM.

  2. #2
    Senior Member OpenGL Pro
    Join Date
    Jan 2012
    Location
    Australia
    Posts
    1,105
    Once hard shadow is calculated I need to retrieve

    A texture buffer will be easier to work with

    All GPUs and all drivers do not support an independent stencil buffer

    In general this is true but if you only need to run the application on 1 machines you can code accordingly.


  3. #3
    Intern Contributor
    Join Date
    Dec 2011
    Posts
    56
    Quote Originally Posted by tonyo_au View Post

    A texture buffer will be easier to work with


    Ok, thanks

    Quote Originally Posted by tonyo_au View Post

    In general this is true but if you only need to run the application on 1 machines you can code accordingly.

    Unfortunately this is not the case... However for my purpose could I have a texture with just stencil and color attachment?

  4. #4
    Intern Contributor
    Join Date
    Dec 2011
    Posts
    56
    Quote Originally Posted by tonyo_au View Post

    A texture buffer will be easier to work with


    Wait... http://www.songho.ca/opengl/gl_fbo.html
    Renderbuffer Object

    In addition, renderbuffer object is newly introduced for offscreen rendering. It allows to render a scene directly to a renderbuffer object, instead of rendering to a texture object. Renderbuffer is simply a data storage object containing a single image of a renderable internal format. It is used to store OpenGL logical buffers that do not have corresponding texture format, such as stencil or depth buffer.
    This means I must use necessarily the renderbuffer image..right?

  5. #5
    Senior Member OpenGL Guru
    Join Date
    May 2009
    Posts
    4,948
    That's the danger of using outdated information. Try the OpenGL Wiki; it's at least trying to stay up to date.

    Textures can have depth and stencil image formats in GL 3.x.

  6. #6
    Intern Contributor
    Join Date
    Dec 2011
    Posts
    56
    Quote Originally Posted by Alfonse Reinheart View Post
    That's the danger of using outdated information. Try the OpenGL Wiki; it's at least trying to stay up to date.

    Textures can have depth and stencil image formats in GL 3.x.
    Thanks for the useful link, Alfonse, but since I am using GL2 I guess renderbuffer images are my only way..

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •