rendering - Depth stencil does not work properly during DirectX12 renderer implementation - Stack Overflow

admin2025-04-18  2

I've fixed all the possible issues I could in the implementation process, but I still can't figure it out, so I'm sharing my repo.

Looking at the code, objects with larger Z values are not being drawn behind as expected. I even asked ChatGPT and tried fixing potential problem areas, but I still can't find the reason. Could you help identify the issue?

So far, I've noticed that even when setting values between 0 and 1, they are all recorded as either 0 or 1. I understand what is the problem, but I don't know how to solve it.

render code

pix image

I changed the shader code and checked the pipeline. I hope the depth stencil is working properly.


(updated) I changed the z position value in the Render() function to draw it.

void ApplicationContext::Render()
{
    RenderBegin();

    defaultShader->Bind();
    {
        Transform t1;
        t1.offset = ZNVector4(0.25f, 0.25f, 0.3f, 0.f);
        defaultMesh->SetTransform(t1);
        defaultMesh->SetTexture(defaultTexture);
        defaultMesh->Render();
    }
    {
        Transform t;
        t.offset = ZNVector4(0.0f, 0.f, 0.2f, 0.f);
        defaultMesh->SetTransform(t);
        defaultMesh->SetTexture(defaultTexture);
        defaultMesh->Render();
    }


    RenderEnd();
}
转载请注明原文地址:http://anycun.com/QandA/1744910691a89355.html