Jump to content
  • Advertisement
Sign in to follow this  
Trigves

Per pixel sprite depth

This topic is 1059 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi,

I'm trying to find available methods for using per pixel sprite depth in 3D engine with isometric (ortho) camera.

 

The Sims 1 used the depth texture for each sprite. That's ok. But how they actually used it? You just can't "blit" it directly do depth buffer, because the sprite depth is in range [0,1] for the given tile. But the camera depth buffer range [0,1] is used for whole camera frustrum. So you must therefor somehow adjust the depth texture so it will have right depth values when being written to depth buffer. What I meas is, if I have a sprite and put it somewhere to the "bottom of the camera" (the nearest place), the depth values should be around 0, but when I place the sprite "near the top" of the camera (that is way from camera) the depth values shoud be around 1. But if I just blindy transfer the depth, in each case the depth values would be same, which is wrong. Or am I completely off? (this is probably the case)

 

Pillars of Eternity use prerenderd backgroun with height map pass which is used for per pixel sorting. From the forums I found the the map is composed of the world height position of each pixel. But, how can one reconstruct the position only from the height? You will need at least height (y) and z position to reconstruct the each pixel. Or am I missing something? If they used the rendered depth map, then the problem will be same as described earlier. That is if the camera move, the whole depth map need to be adjusted somehow to reflect the movement.

 

The only solution that works for me is something like Pillars Of Eternity, where for each object I render the Y and Z per pixel values. These values are then used in the fragment shader to reconstruct the pixel position (the X position is taken from the vertex of the sprite) in space and compute the depth. The only problem is that I need to encode the float values to RGB to be able to use them in shader, which is extra step I would rather not to do. And don't know if there could be performance problem.

 

It is possible that I'm all wrong so please correct me.

 

I would be grateful for any comment explaining the situation in both games.

 

Thank You

 

Trigve

Share this post


Link to post
Share on other sites
Advertisement

 

because the sprite depth is in range [0,1] for the given tile. But the camera depth buffer range [0,1] is used for whole camera frustrum.

If you are exporting 2d images with a depth of 0 to 1, we will call this reference sprite relative depth.

Camera space will use 0 to 1, yes.

 

So the obvious solution is given a sprite's depth location, we add (or subtract) depth from the sprite location in the camera. So we need a way to translate sprite relative depth into the world.  You need to scale the relative sprite depth by the real world depth of the 2d sprite.

 

If you are rendering a couch and it is spanning 3 tiles in depth, which equates to the orthographic depth range .5 to .7, then obviously your 2d sprite is going to make between .5 and .7

OutputDepth = .5 + (.5 - .7)*pixelSpriteDepth

 

So the couch is .2 in the depth dimension in length. Your 2d sprite then represents a .2 range in depth values.

 

.........seems pretty simple, not sure what else you would be asking.

Share this post


Link to post
Share on other sites
Thank you for the quick reply.
 

If you are exporting 2d images with a depth of 0 to 1, we will call this reference sprite relative depth.
Camera space will use 0 to 1, yes.
 
So the obvious solution is given a sprite's depth location, we add (or subtract) depth from the sprite location in the camera. So we need a way to translate sprite relative depth into the world.  You need to scale the relative sprite depth by the real world depth of the 2d sprite.

Yes, that's what I thought.
 

If you are rendering a couch and it is spanning 3 tiles in depth, which equates to the orthographic depth range .5 to .7, then obviously your 2d sprite is going to make between .5 and .7

OutputDepth = .5 + (.5 - .7)*pixelSpriteDepth
 
So the couch is .2 in the depth dimension in length. Your 2d sprite then represents a .2 range in depth values.
 
.........seems pretty simple, not sure what else you would be asking.

But how do I know the ortho depth range of my sprite? I think I'm missing something or simply not getting it it. I would like to see the shader code how it would be done

I also want to note that my scene is setup similar as in Pillars Of Eternity, that is the sprites are lay out on XZ plane (Y is up), and 3D objects are moving also on XZ plane.

Thank You

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!