# How can one access the depth buffer for Unreal Tournament 2004?

I'm looking for a way of getting depth buffer data for a virtual 3D sensor.

Currently the method used is raycasting (implemented in UnrealScript), but I want to use the depth buffer data instead for faster output of the sensor in FPS.

One complete frame of data takes many seconds to generate currently, which is bad for my application which must parse this 3D depth data and also control a vehicle with it.

I'd like to get the data from D3D but don't know if it's possible.

• Wouldn't this require you to render the scene from the point of view of the sensor? It would seem like that would be more costly to do than the way you have it already implemented. Oct 14 '11 at 18:33
• Don't know if the scene would have to be rendered from that point of view. But depth would have to be calculated in relation to the sensor position, direction and orientation. If the cost of doing this in the rendering or through modding is not great in implementation and if there's a way to do it, i'd give a try. Oct 21 '11 at 18:53

I'm not sure it's possible via the modding APIs exposed by UT2004. If it is, the information is likely on the UnrealWiki or someplace similar -- perhaps ask in the IRC channels listed on that wiki's main page, as well?

Likely the information you will be found under information for framebuffer access or post-processing graphics mods, but I'm not sure if the particular flavor of Unreal Engine used for UT2004 (2, I think?) exposed this kind of thing.

There is another option though. This question about accessing another process's device context deals with API hooking, and has a few answers that may be helpful. With this approach, rather than write a mod, you write an external program that hooks UT2004's Present() call (or similar), does the normal presentation work, and rejiggers the scene setup to re-render it with depth pass into a texture you've created and can write out to your sensor.

Unfortunately this is an exceedingly complicated process relative to simply using something in the UT2004 mod arsenal. Perhaps instead you could post another question detailing the requirements and implementation of your raycasting technique, and ask if there's a more efficient way to achieve your ultimate goals?

• I don't know if it would be easier to do these things in UDK. Maybe Physx SDK has some methods to enable these sort of things? Using Hooks into UT2004 really seems too complicated for what i want. The implementation of the raycast technique is not mine. I'm using a open source simulator, and there was suggested to find a way of accessing the depth buffer directly instead of getting the distance for each point through a trace method. Anyway, i'll post this question in the UnrealWiki and see what happens. Oct 17 '11 at 18:52

The simplest option in D3D9 is to use an extra render target (either via MRT or re-rendering the scene) and appropriate pixel shader to output depth to a D3DFMT_R32F texture.

I'm not sure how easy that would be to integrate with Unreal 2004 though.