Dev ZIWON
Dev ZIWON

Reputation: 11

Depth stencil does not work properly during DirectX12 renderer implementation

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();
}

Transformation t1 has a larger z value of 0.3f than t of 0.2f, so I expected the texture with t1 to be drawn behind t. But that's not the case.

And this is my shader code, but I can't find the problem with my shader code. So I think it's a problem setting up the pipeline or some other part, but I can't find it. I would also like to specify the problem, but I am a beginner in DirectX12.

Thank you for your interest in this question.

cbuffer TEST_B0 : register(b0)
{
    float4 offset0;
};

cbuffer TEST_B1 : register(b1)
{
    float4 offset1;
};

Texture2D tex_0 : register(t0);
SamplerState sam_0 : register(s0);

struct VS_IN
{
    float3 pos : POSITION;
    float4 color : COLOR;
    float2 uv : TEXCOORD;
};

struct VS_OUT
{
    float4 pos : SV_Position;
    float4 color : COLOR;
    float2 uv : TEXCOORD;
};

VS_OUT VS_Main(VS_IN input)
{
    VS_OUT output = (VS_OUT) 0;

    output.pos = float4(input.pos, 1.f);
    output.pos += offset0;
    output.color = input.color;
    output.uv = input.uv;

    return output;
}

float4 PS_Main(VS_OUT input) : SV_Target
{
    float4 color = tex_0.Sample(sam_0, input.uv);

    return color;
}

Upvotes: 1

Views: 36

Answers (0)

Related Questions