• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0

Depth buffer doesn't write in Direct3D9

6 posts in this topic

As the title says, my application will not write new depths to the depth buffer in D3D9. I've used PIX to confirm that the depth buffer is cleared and set to the device as it should be, and the depth test is even used- if I clear it to 0, then all the pixels are rejected against buffer. I've checked the return code of all D3D9 functions and got nothing. I even explicitly set the render states in the shader to the appropriate values to no avail. Any suggestions?

In an unfortunately unrelated issue, the Direct3D debug runtime is not functioning correctly and I don't have it's output. I am trying to solve this issue as quickly as possible.

Share this post

Link to post
Share on other sites
I'm not sure if I understood your problem... but you should be clearing your depth buffer to 1.0 (farthest value) instead of 0 (closest value).

Share this post

Link to post
Share on other sites
Yes. I only cleared it to 0 to see if the test was being performed correctly.

Share this post

Link to post
Share on other sites
[color=#282828][font=helvetica, arial, verdana, tahoma, sans-serif][size=3][left]if I clear it to 0, then all the pixels are rejected against buffer[/left][/size][/font][/color]
... that's what it is supposed to do if the depth test is less, or less or equal : Whatever is the incoming pixel, it will be rejected because its depth is greater than zéro.
[color=#5A5A5A][font=helvetica, arial, verdana, tahoma, sans-serif][left]As [/left][/font][/color][url="http://www.gamedev.net/user/193711-gfxgangsta/"]gfxgangsta[/url][color=#5A5A5A][font=helvetica, arial, verdana, tahoma, sans-serif][left] suggested, maybe can you try to clear your z-buffer with 1.0f instead?[/left][/font][/color]

Share this post

Link to post
Share on other sites

Good point about the depth test! I assumed a test of "<" or "<=" in my comment. Thanks for pointing that out.


So, when you clear to 1, are the pixels being rejected? Or are they supposedly being written but you don't get the expected results? Can you post some code?

Share this post

Link to post
Share on other sites
No. None of the pixels are being rejected- so you can see through parts of the model to parts which are supposed to be obscured. When I look at the depth buffer in PIX, it's all still got the original 1 value. I fixed the D3D Debug Runtime, found a few bugs but fixing them had no effect.

Here's my code for rendering:

void Scene3D::Render(
float dt,
IDirect3DDevice9* device,
IDirect3DVertexDeclaration9* VertexDecl,
ID3DXEffect* RenderOnlyAmbientLightEffect
) const {
bool first = true;
auto SetRenderTargetToDevice = [&] {
std::unique_ptr<IDirect3DSurface9, COMDeleter> RenderTargetSurface;
D3DCALL(RenderTarget->GetSurfaceLevel(0, PointerToPointer(RenderTargetSurface)));
D3DCALL(device->SetRenderTarget(0, RenderTargetSurface.get()));
if (first) {
D3DCALL(device->Clear(0, nullptr, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DColour(ClearColour), 1, 0));
first = false;

auto SetMeshSpecificDataToEffect = [&](ID3DXEffect* effect, const Direct3D9::Mesh* mesh) {
auto RenData = mesh->GetRenderData();
/*if (auto handle = effect->GetParameterByName(0, "ColourMap")) {
effect->SetTexture(handle, RenData.Texture);
if (auto handle = effect->GetParameterByName(0, "AmbientMaterial")) {
effect->SetVector(handle, reinterpret_cast<D3DXVECTOR4*>(&RenData.AmbientMaterial));
if (auto handle = effect->GetParameterByName(0, "DiffuseMaterial")) {
effect->SetVector(handle, reinterpret_cast<D3DXVECTOR4*>(&RenData.DiffuseMaterial));
if (auto handle = effect->GetParameterByName(0, "SpecularMaterial")) {
effect->SetVector(handle, reinterpret_cast<D3DXVECTOR4*>(&RenData.SpecularMaterial));

auto SetCameraSpecificDataToEffect = [&](ID3DXEffect* effect) {
if (auto handle = effect->GetParameterByName(0, "CameraVP")) {
D3DXMATRIX Projection;
auto lookingat = D3DVector(camera.Position + camera.LookingAt);
#pragma warning(disable : 4244)
GetDimensions().x / GetDimensions().y,
#pragma warning(default : 4244)
effect->SetMatrix(handle, &(View * Projection));

// Define a couple variables the helpers can use
auto SendAllVerticesToPipeline = [&, this](ID3DXEffect* effect, const std::unordered_map<const Direct3D9::Mesh*, std::unordered_set<Object*>>& ObjectsByMesh) {
std::for_each(ObjectsByMesh.begin(), ObjectsByMesh.end(), [&](const decltype(*ObjectsByMesh.begin())& group) {
// Set all per-mesh data - first to the pipeline
auto RenData = group.first->GetRenderData();

// then to the effect
SetMeshSpecificDataToEffect(effect, group.first);
auto handle = effect->GetTechniqueByName("PrimaryTechnique");
D3DCALL(device->SetStreamSourceFreq(0, D3DSTREAMSOURCE_INDEXEDDATA | group.second.size()));

auto bones = group.first->GetBones();
std::for_each(bones.begin(), bones.end(), [&](const decltype(*bones.begin())& bone) {
std::vector<Direct3D9::Bone*> bones;
std::for_each(group.second.begin(), group.second.end(), [&](const Wide::Direct3D9::Object* obj) {
D3DXMATRIXA16* matrices;
D3DCALL(InstanceBuffer->Lock(0, bones.size() * sizeof(D3DXMATRIXA16), reinterpret_cast<void**>(&matrices), D3DLOCK_DISCARD));
std::for_each(bones.begin(), bones.end(), [&](Direct3D9::Bone* bone) {
*matrices = bone->World;
matrices++; // Guaranteed not to overflow because we already made the size as large as we needed it
unsigned int passes;
D3DCALL(effect->Begin(&passes, 0));
for(unsigned int i = 0; i < passes; i++) {
bone->NumIndices / 3

// Save the original back buffer and depth stencil
std::unique_ptr<IDirect3DSurface9, COMDeleter> BackBuffer;
std::unique_ptr<IDirect3DSurface9, COMDeleter> DepthStencil;
D3DCALL(device->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, PointerToPointer(BackBuffer)));

// Sort the objects by mesh, and compute the world matrices whilst you're at it.
std::unordered_map<const Direct3D9::Mesh*, std::unordered_set<Object*>> ObjectsByMesh;
std::for_each(Objects.begin(), Objects.end(), [&](Wide::Render::Object* ptr) {
auto d3dptr = static_cast<Wide::Direct3D9::Object*>(ptr);

// Resize the buffer, if it's not big enough to hold what we're doin here.
unsigned int maxsize = 0;
std::for_each(ObjectsByMesh.begin(), ObjectsByMesh.end(), [&](const decltype(*ObjectsByMesh.begin())& group) {
maxsize = std::max(maxsize, group.second.size());
if (InstanceBufferSize < maxsize) {
InstanceBufferSize = maxsize;

// Set the mesh-independent stuff to the device
D3DVIEWPORT9 vp = { 0, 0, GetDimensions().x, GetDimensions().y, 0, 1 };
D3DCALL(device->SetStreamSource(1, InstanceBuffer.get(), 0, sizeof(D3DXMATRIXA16)));
D3DCALL(device->SetStreamSourceFreq(1, D3DSTREAMSOURCE_INSTANCEDATA | 1));

// If there is only ambient light, then just render directly to BB with no shadow mapping
//if (Lights.empty()) {
// Render ambient only- no shadowmapping needed
SendAllVerticesToPipeline(RenderOnlyAmbientLightEffect, ObjectsByMesh);

// Restore the previous backbuffer and depth stencil
D3DCALL(device->SetRenderTarget(0, BackBuffer.get()));

Share this post

Link to post
Share on other sites
Are you clearing the color and depth buffers only once?

[quote name='DeadMG' timestamp='1331308779' post='4920695']
[color=#000000] [/color][color=#000088]if[/color][color=#000000] [/color][color=#666600]([/color][color=#000000]first[/color][color=#666600])[/color][color=#000000] [/color][color=#666600]{[/color]
[color=#000000] D3DCALL[/color][color=#666600]([/color][color=#000000]device[/color][color=#666600]->[/color][color=#660066]Clear[/color][color=#666600]([/color][color=#006666]0[/color][color=#666600],[/color][color=#000000] [/color][color=#000088]nullptr[/color][color=#666600],[/color][color=#000000] D3DCLEAR_TARGET [/color][color=#666600]|[/color][color=#000000] D3DCLEAR_ZBUFFER[/color][color=#666600],[/color][color=#000000] D3DColour[/color][color=#666600]([/color][color=#660066]ClearColour[/color][color=#666600]),[/color][color=#000000] [/color][color=#006666]1[/color][color=#666600],[/color][color=#000000] [/color][color=#006666]0[/color][color=#666600]));[/color]
[color=#000000] first [/color][color=#666600]=[/color][color=#000000] [/color][color=#000088]false[/color][color=#666600];[/color]
[color=#000000] [/color][color=#666600]}[/color]

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  
Followers 0