Drawing to the Depth Buffer

Sage
Posts: 1,403
Joined: 2005.07
Post: #1
I want to load a grayscale image or texture and draw that to the depth buffer, how is this possible?

Sir, e^iπ + 1 = 0, hence God exists; reply!
Quote this message in a reply
Moderator
Posts: 529
Joined: 2003.03
Post: #2
I think glDrawPixels can do that. I'm sure the gurus here will have some fancier (faster) solution.

Why are you trying to do this anyway?

"Yes, well, that's the sort of blinkered, Philistine pig-ignorance I've come to expect from you non-creative garbage."
Quote this message in a reply
Sage
Posts: 1,403
Joined: 2005.07
Post: #3
I aim to render color and depth images in a raytracer of the background scenes for a game, then setting the opengl projection matrix (or custom camera class probably) to the same as in the renders I should be able to have 3D models casting shadows and so on in a prerendered background.

Using a low poly model of the scene would also work but when shadows dont require any information about the scene's geometry, it would be great to have as high quality graphics as possible.

Draw pixels can do it, thanks! Ill see how fast I can get this to run.

Sir, e^iπ + 1 = 0, hence God exists; reply!
Quote this message in a reply
Moderator
Posts: 529
Joined: 2003.03
Post: #4
Could you not use lightmaps for the low poly models?

"Yes, well, that's the sort of blinkered, Philistine pig-ignorance I've come to expect from you non-creative garbage."
Quote this message in a reply
Sage
Posts: 1,403
Joined: 2005.07
Post: #5
Making low poly models would be quite a hassle especially considering the amount of scenes that will be made, its also a lot less detailed than a depth render and so I really want to avoid that if at all possible.

glDrawPixels works, seems to be fast enough too (at 640x480)
If there are any speed improvments though, please tell me because I want to get this to work on as slow a computer as possible while still looking great Wink

Sir, e^iπ + 1 = 0, hence God exists; reply!
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #6
DrawPixels is your only option without any OpenGL extensions, I think.

It's horribly slow, though.

I suspect you'll find that using a texture and modifying the fragment's depth based on that texture using a fragment program will be much faster on capable hardware.
Quote this message in a reply
Moderator
Posts: 1,140
Joined: 2005.07
Post: #7
Unfortunately, you have a GeForce 2 MX, right? I doubt you will be able to do anything other than glDrawPixels on your graphics card, since I don't know if you can even get the depth texture, and I know you can't use any shaders, vertex or fragment. It looks like if you want any faster method, you'll have to wait until you upgrade.
Quote this message in a reply
Moderator
Posts: 529
Joined: 2003.03
Post: #8
See? I told you a guru would be along shortly.

"Yes, well, that's the sort of blinkered, Philistine pig-ignorance I've come to expect from you non-creative garbage."
Quote this message in a reply
Member
Posts: 269
Joined: 2005.04
Sage
Posts: 1,403
Joined: 2005.07
Post: #10
Thank you all.
glDrawPixels is working nicely, I have a triangle moving around a prerendered cube.

Also I hadn't though about a dirty rect's like system for updating the background, that should be a good speed optimisation (from the star wars link).

Anyway, theres more precision close to zNear and very little close to zFar. So I need to do somthing to account for that.

Sir, e^iπ + 1 = 0, hence God exists; reply!
Quote this message in a reply
Moderator
Posts: 529
Joined: 2003.03
Post: #11
unknown Wrote:Anyway, theres more precision close to zNear and very little close to zFar. So I need to do somthing to account for that.

I think that's always the case.

"Yes, well, that's the sort of blinkered, Philistine pig-ignorance I've come to expect from you non-creative garbage."
Quote this message in a reply
Sage
Posts: 1,482
Joined: 2002.09
Post: #12
unknown Wrote:Anyway, theres more precision close to zNear and very little close to zFar. So I need to do somthing to account for that.

Especially if you are using 8bit depth values in your stored images. Make sure you are clamping those near and far planes as close as possible.

Also, what are the GL_DEPTH_COMPONENT* texture formats for? I figured they were for this type of situation.
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #13
depth textures are only available on GeForce 3+ and Radeon 9500+, so ed won't want to use them.
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  SLOW performance drawing multiple polygons per frame with stencil buffer clam61 7 3,912 Apr 27, 2013 11:53 AM
Last Post: clam61
  Depth Buffer Question AnotherJake 10 4,757 Sep 23, 2008 01:43 PM
Last Post: AnotherJake
  problems getting the depth buffer akb825 3 4,206 Jun 2, 2006 12:51 PM
Last Post: akb825
  Depth Buffer / Testing basic question... WhatMeWorry 5 6,416 Nov 18, 2005 12:50 AM
Last Post: arekkusu
  Reading from the Depth Buffer Joseph Duchesne 2 3,053 Jun 16, 2005 04:51 PM
Last Post: OneSadCookie