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 3 of 3

Thread: Rendering sprites with depth information

  1. #1
    Newbie Newbie
    Join Date
    Jul 2014
    Posts
    1

    Rendering sprites with depth information

    Hi all!

    I'm looking for advice on how to acheive a particular rendering technique with OpenGL. This is best illustrated by the first The Sims game.

    In The Sims, the people themselves were rendered as polygon models whereas all the furniture used pre-rendered sprites. However, the 3d models still intersected the sprites as if they had volume in 3d space. Here the sims pop through the water of the hot tub even though it is a 2d sprite:

    Click image for larger version. 

Name:	zbuffer-explain2.jpg 
Views:	41 
Size:	20.4 KB 
ID:	1355

    And here the fire (which is a textured cylinder) intersects the 2d sprite of the cooker:

    Click image for larger version. 

Name:	zbuffer-explain3.jpg 
Views:	48 
Size:	21.0 KB 
ID:	1356

    Each furniture sprite in The Sims had an accompanying image containing the depth of each pixel; something like this:

    Click image for larger version. 

Name:	zbuffer-explain.jpg 
Views:	44 
Size:	7.3 KB 
ID:	1354

    I'd like to know whether it's possible to this with OpenGL, perhaps by drawing to the depth buffer somehow. I'm having trouble searching for information on this technique, mainly because I don't even know what it's called! I suppose it's a kind of voxel rendering, but this term has many different meanings in different contexts.

    Thanks in advance!

  2. #2
    Intern Contributor
    Join Date
    Sep 2013
    Posts
    89
    I'd say this is definitely possible when you write your own shader.
    You can bind 2 textures, one with the color information, and one with the depth information.
    In your vertex shader you take the X- and Y-coordinates from the client, and the Z-coordinate from the depth texture.
    In your fragment shader you take RGBA from the color texture.

  3. #3
    Intern Contributor
    Join Date
    May 2013
    Posts
    69
    Yes you can directly write your depth value to gl_FragDepth in the fragment shader.
    But that will disable HyperZ/Hierarchical Z-Buffering. That should not be a performance problem if you create a simple 2d game.

    There also is ARB_conservative_depth. With this you can tell the driver that you only will increase/decrease the current depth value and may still get the HyperZ/Hierarchical Z-Buffering.
    More about it in the wiki: http://www.opengl.org/wiki/Fragment_Shader#Outputs

Posting Permissions

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