Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I begin to learning direct3d10 and stuck with multiple passes. As input I have a triangle(that stored in vb/ib) and effect file:

//some vertex shader and globals goes there. skip them to preserve simplicity

float4 ColorPixelShader(PixelInputType input) : SV_Target
{
    return float4(1,0,0,0);
}

float4 ColorPixelShader1(PixelInputType input) : SV_Target
{
    return float4(0,1,0,0);
}

technique10 ColorTechnique
{
    pass pass0
    {
        SetVertexShader(CompileShader(vs_4_0, ColorVertexShader()));
        SetPixelShader(CompileShader(ps_4_0, ColorPixelShader()));
        SetGeometryShader(NULL);
    }
    pass pass1
    {
        SetVertexShader(CompileShader(vs_4_0, ColorVertexShader()));
        SetPixelShader(CompileShader(ps_4_0, ColorPixelShader1()));
        SetGeometryShader(NULL);
    }
}

And some render code:

pass1->Apply(0);
device->DrawIndexed(indexCount, 0, 0);

pass2->Apply(0);
device->DrawIndexed(indexCount, 0, 0);

What I'd expect to see is the green triangle, but it always shows me red triangle. What am I doing wrong?

Also, I've got another question - should I set vertex shader in every pass?

I've added ColorVertexShader1 that translates vertex position by some delta, and 've got following picture: http://imgur.com/Oe7Qj

share|improve this question
1  
Do you have a depth buffer, and in that case, is the depth func set to something that keeps fragments rendered to the exact same depth? It won't do with "less" as that rejects fragments with the same depth, you need "less-or-equal". –  Lars Viklund Mar 17 '12 at 19:30
1  
Not to mention blending mode, probably something like this in your second pass? alphablendenable = true; srcBlend = srcAlpha; destBlend= invSrcAlpha; –  Patrick Hughes Mar 17 '12 at 21:56
    
@Lars Viklund thank you. The problem was in depthStencilDesc.DepthFunc = D3D10_COMPARISON_LESS_EQUAL;//D3D10_COMPARISON_LESS; –  innochenti Mar 18 '12 at 0:22
add comment

1 Answer 1

up vote 2 down vote accepted

When rendering any geometry, any fragments that fail the depth test against the content of the depth buffer will be discarded.

A common depth testing function is the "less" compare, which allows a fragment if the depth for the fragment is strictly closer than the value in the depth buffer. This is so similiar to the function "less-or-equal" that in most cases, it's not noticeable.

When you're rendering the exact same geometry with the exact same vertex shader and transformations, you will get fragments with the exact same depth value in both passes.

In those cases, "less" and "less-or-equal" differ in semantics, and the difference is that "less" will reject your fragment, while "less-or-equal" will not.

As @Patrick Hughes mentions, there is also the possibility that you've got blending modes set such that if any fragment is generated in the second pass, it has no visible effect, but as the common default blending parameters are to keep the new fragment completely, this rarely tends to be a root cause.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.