Results 1 to 3 of 3

Thread: Rendering sprites with depth information

  1. #1
    Newbie Newbie
    Join Date
    Jul 2014

    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:


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


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


    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
    Senior Member Regular Contributor
    Join Date
    Sep 2013
    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
    Senior Member Regular Contributor
    Join Date
    May 2013
    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:

Similar Threads

  1. no depth information while picking objects
    By Leseratte in forum OpenGL: Advanced Coding
    Replies: 7
    Last Post: 01-18-2012, 09:42 AM
  2. Laying down depth information
    By zed in forum OpenGL: Advanced Coding
    Replies: 31
    Last Post: 05-29-2009, 07:02 PM
  3. Tool to get depth information
    By jcomp in forum OpenGL: General
    Replies: 5
    Last Post: 03-03-2008, 09:34 AM
  4. depth [min-max] accumulation information
    By Damien Marchal in forum OpenGL: Advanced Coding
    Replies: 0
    Last Post: 05-21-2004, 04:45 AM
  5. why depth buffer save to image file can not display depth information
    By victorswan in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 05-27-2001, 09:19 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
Proudly hosted by Digital Ocean