Jump to content

  • Log In with Google      Sign In   
  • Create Account

Depth Buffer for a 2D scene


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
No replies to this topic

#1 CirdanValen   Members   -  Reputation: 185

Like
0Likes
Like

Posted 13 January 2012 - 04:08 PM

I'm trying to create a 2D game that uses deferred lighting. I think I have everything figured out except for depth. I need to figure out a way to allow me to render lights behind or in front of objects. An example would be if I have a tree, and I want to render the light behind the tree, the ground and objects behind the tree would be light, but the tree would not. After a bit of looking around, seems like a depth buffer would be my answer but I'm not sure how to create a depth buffer in opengl for a 2D scene. I assume the way I would treat a depth buffer is using the depth of the pixel in conjunction with the z value of the light to decide which pixels get lit.

I don't have anything implemented currently, still just planning things out. I think I am going to sort objects in the scene first by their y position, then by their fake z position.

EDIT: Sorting objects by y and z, I came up with this formulate for calculating the depth clamped to 255. Just need to figure out how to write these values to a depth buffer
depth = y + z 
minDepth = objectList.front().y + objectList.front().z
maxDepth = objectList.back().y + objectList.back().z
finalDepth = (255 / maxDepth) * (depth - minDepth)


Sponsor:



Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS