Results 1 to 5 of 5

Thread: Drawing in the 3D world of a modern game WITH z-depth testing

  1. #1
    Join Date
    Sep 2004
    Location
    Capital, Ism
    Posts
    321
    Thanks
    3
    Thanked 49 Times in 9 Posts
    Rep Power
    101

    Drawing in the 3D world of a modern game WITH z-depth testing

    (cross posting with UC)

    Lately D3D games tend to abandon the fixed function pipeline and do all the transform work directly in the vertex shader. They also often do tricky things with the depth/stencil buffer as they render different parts of the scene. This can make it hard to actually draw geometry in the game world, instead of merely on top of the game world. Here's what I've come up with to get it working in one example game (bad company 2), but the strategy is generalizable.



    1. Dealing with lack of fixed function pipeline usage.

    Basically if the game does world/view/proj transforms in the vertex shader, you'll need to turn off the shader and set your own matrices. How you find these will be game dependent.

    PHP Code:
    pDevice->GetPixelShader( &pixelshader );
    pDevice->GetVertexShader( &vertexshader );

    pDevice->SetPixelShaderNULL );
    pDevice->SetVertexShaderNULL );

    pDevice->SetTransform(D3DTS_VIEW, &view->m_viewMatrix);
    pDevice->SetTransform(D3DTS_PROJECTION, &view->m_projectionMatrix);
    D3DXMATRIX worldMatrix;
    D3DXMatrixIdentity(&worldMatrix);
    for (
    vector<RenderSphere>::iterator it spheres.begin(); it != spheres.end(); it++)
    {
        
    D3DXMatrixTranslation(&worldMatrixit->pos.xit->pos.yit->pos.z);
        
    worldMatrix._11 worldMatrix._22 worldMatrix._33 it->radius;
        
    pDevice->SetTransform(D3DTS_WORLD, &worldMatrix);
        
    sphereMesh->DrawSubset(0);
    }

    pDevice->SetPixelShaderpixelshader );
    pDevice->SetVertexShadervertexshader ); 
    This will get you spheres drawn in the 3D world, but (sometimes) not depth testing



    2. Saving the depthstencil surface
    If your game renders to different depth buffers, as is often the case for weapons and hud elements depending on how they are drawn, you will need to find the depth buffer you are interested in (usually the one with game world geometry in it) and save it. What does this entail?

    First, identifying the buffer. My strategy is to hook DIP and count how many calls with certain stride counts are made. Next, hook SetDepthStencilSurface. Examine the stride-call count and if enough calls were made (game-dependent), save the current surface. This is the surface you will want to set before drawing your geometry. Additionally, you may need to hook Clear, and prevent Z-buffer clears to your buffer, if the game reuses its surfaces for multiple purposes during a single frame render. If this clearing is critical to the game's functioning you may need to lock the zbuffer and copy all the bits and then restore them, but this is a significant performance hit (and is hopefully unnecessary). Alternatively you may just want to insert your own created, blank surface in lieu of allowing the game to clear the one you want.

    There you go, enjoy, and please credit. Or don't, it doesn't really matter.

  2. #2
    Join Date
    Jul 2010
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    Re: Drawing in the 3D world of a modern game WITH z-depth testing

    I'm glad to sit on the sofa!!!thank you for your share!!!!!!!!!!

  3. #3
    Join Date
    Jul 2006
    Location
    Austin, Texas
    Posts
    450
    Thanks
    95
    Thanked 30 Times in 17 Posts
    Rep Power
    96

    Re: Drawing in the 3D world of a modern game WITH z-depth testing

    By the way, this is one of the more creative hacks I've seen in a long time. Pretty awesome idea and quite extensible to other kinds of hacks(FOV/aim, drop cam placement marker are just a few off the top of my head).

  4. #4
    Join Date
    Dec 2006
    Location
    Germany
    Posts
    636
    Thanks
    57
    Thanked 50 Times in 30 Posts
    Rep Power
    86

    Re: Drawing in the 3D world of a modern game WITH z-depth testing

    Always wanted to do that, never got around to doing it.
    Great work!
    I shall live forever or die trying.

  5. #5
    Join Date
    Dec 2008
    Posts
    196
    Thanks
    87
    Thanked 24 Times in 8 Posts
    Rep Power
    53

    Re: Drawing in the 3D world of a modern game WITH z-depth testing

    Quote Originally Posted by Macpunk View Post
    By the way, this is one of the more creative hacks I've seen in a long time. Pretty awesome idea and quite extensible to other kinds of hacks(FOV/aim, drop cam placement marker are just a few off the top of my head).
    Indeed , nice Work.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Need for Speed World - Game State
    By kingorgy96 in forum Other Games
    Replies: 8
    Last Post: 02-09-2011, 11:20 AM
  2. Drawing a menu in-game
    By ReVoLT in forum Advanced
    Replies: 4
    Last Post: 07-16-2008, 10:42 AM
  3. Drawing text in game
    By redshadow in forum Beginner
    Replies: 3
    Last Post: 06-26-2006, 05:23 AM
  4. getting your xyz coordinates in the game world..
    By gfreeman1 in forum Gold Source/HL1 Engine
    Replies: 7
    Last Post: 02-12-2003, 07:21 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •