Thursday, January 5, 2012

DirectX Depth

As I've mentioned in previous posts, I'm currently going through the DirectX tutorials. I figure I've learned enough to actually write something and in the interest of making this blog a 'routine' for me, I think I should update as much and as soon as possible.

So the first order of business was downloading the latest DirectX SDK (June 2010). After installation you need to make sure the library and header files are properly configured in Visual Studio. Since it's been a long time since I've written any c/c++ I had to look this one up. Luckily, MSDN blogs had a blog post specifically on the matter.

At first I was following some online DirectX tutorial, but it turned out to be a pay for tutorial. So I started searching around and finally just went to the MSDN documentation. They mention that tutorials exist in the SDK installation directory so I looked them up. Well it turns out their tutorials are pretty awesome, at least for someone who is just looking to 'skim the surface.' If I wanted to actually build a game, I'd probably not like them as much as it assumes a Lot and doesn't explain some of the finer details of flags/structs being used etc. On my system they were at: C:\Program Files (x86)\Microsoft DirectX SDK (June 2010)\Documentation\DirectX9\directx_sdk.chm, which is bizarre because it's actually the DX11 documentation. I guess they never bothered updating the path?

The past few days I've been going through the first five or so chapters and figuring out the various steps necessary to get objects to be rendered. I've learned about object space, world space, view space and the necessary transformations. The graphics pipeline, the shader system and DirectX's High Level Shader Language (HLSL) which is very C like. Just now, I learned about depth rendering. Again, I don't know what the hell I'm doing but I figure this may be important, in particular for wall hacks. Basically, DirectX has a concept of a depth stencil (more here), which will automatically determine by an objects position, whether to render it to the display. Without this depth stencil, things that are 'behind' an object may show up in front, I'm assuming depending on their rendering order but I'm not entirely sure.

A smaller rotating cube properly 'behind' the larger cube

In regards to a crappy wall hack or 'cham' style hack where we want to render a player in front of wall this could be important? Maybe? I don't know, I'm still figuring things out here.

The same rotating cube without a depth stencil, clearly in front.

So yeah, maybe this is something, maybe this is nothing, that's the process of learning I guess.

1 comment:

  1. i think each pixel holds depth or Z value.
    when a point in a triangle projected in hlsl vertexshader function ,the point will be sent to pixel shader function as a parameter.the point colored-textured-fogged in pixel shader and then will be sent to screen array.

    i think far pixel values replaced with near pixel values.

    i think there is no complex structure behind that.lets suppose if there is a complex 3d structure behind that and you have 1920x1080 screen.
    you need to acces this structure 60*1920*1080 times in a second.

    i think there is a simple 2D pixel array
    struct Pixel{
    Color c,
    float Depth

    if( screen[newPixel.X][newPixel.Y].Depth<newPixel.Depth){