Why BasicEffect's SetProjection is required?

Jun 15, 2016 at 5:03 PM
Why basic effects requires setting projection? When using SpriteBatch or SpriteFont, I do not need to set any projection or view for it to work.

I have another two questions aside from DirectXTK. Under the DirectXTK's Simple Rendering tutorial, I have used XMMatrixOrthographicOffCenterLH(0, GAME_WIDTH, GAME_HEIGHT, 0, 0, 1); to create the matrix projection, which works.

1) I want to know if NearZ and FarZ minimum and maximum values are 0 and 1 respectively?
2) I am drawing a simple 2D quad, which means I am not going to use any Z coordinate for any 3D effects. So why is there a need to supply FarZ to 1 instead of 0?
Jun 15, 2016 at 7:26 PM
BasicEffect requires a projection matrix and non-zero far clip plane because this is a general purpose 3D rendering mechanism. You may choose to position it such that all your drawing appears in 2D, but that's just your choice and the hardware is still doing full 3D computations, therefore the 3D projection must be fully configured.

NearZ and FarZ can be whatever near and far clip plane distances you want. To be visible, all your drawing must take place somewhere between these clip planes.

SpriteBatch does not require setting a projection matrix because it is explicitly a 2D API ,therefore can internally set up the right projection matrix on your behalf.
Marked as answer by pentocrypt on 6/15/2016 at 6:59 PM
Jun 22, 2016 at 5:18 AM
Help! I set it to 0.1 to 10 but it doesn't work. Here is the code initialization for primitive drawings:
    viewPort.Width = GAME_WIDTH;
    viewPort.Height = GAME_HEIGHT;
    viewPort.TopLeftX = 0;
    viewPort.TopLeftY = 0;
    viewPort.MinDepth = 0;
    viewPort.MaxDepth = 1;
    deviceContext->RSSetViewports(1, &viewPort);

    //========================== Create Sprite ==========================//
    sprite = make_unique<SpriteBatch>(deviceContext);

    commonStates = make_unique<CommonStates>(device);
    basicEffect = make_unique<BasicEffect>(device);
    void const* shaderByteCode;
    size_t byteCodeLength;
    basicEffect->GetVertexShaderBytecode(&shaderByteCode, &byteCodeLength);
    device->CreateInputLayout(VertexPositionColor::InputElements, VertexPositionColor::InputElementCount,
        shaderByteCode, byteCodeLength, &inputLayout);

    Matrix proj = XMMatrixOrthographicOffCenterLH(0, GAME_WIDTH, GAME_HEIGHT, 0, 0.1, 10);

    primitiveBatch = make_unique<PrimitiveBatch<VertexPositionColor>>(deviceContext);
Here is the code to draw quad:
void Graphics::drawQuad(VertexPositionColor v1, VertexPositionColor v2, VertexPositionColor v3, VertexPositionColor v4)


    primitiveBatch->DrawQuad(v1, v2, v3, v4);
If i follow the simple rendering tutorial to set nearZ to 0 and farZ to 1, the quad is shown on the screen. However if I changed nearZ to 0.1 and farZ to 10 (i.e. it doesn't display any quad).

Note: I do not use any depth in my game.
Jul 4, 2016 at 2:30 PM
Jul 5, 2016 at 7:07 AM
Edited Jul 5, 2016 at 7:07 AM
Shawn already answered the question I thought. You don't list what your .z values are for the vertices you are providing? If it's 0, then they will be clipped. That's why the Simple rendering tutorial uses 0.5 for the z.
Jul 5, 2016 at 2:28 PM
Yes, he had answered me, but I need for information - will do more testing and research. Thanks for the reply!