I was wondering how my vertex shader is causing my cube to be render weirdly? I am using the Visual Studio graphics tool and see that my input assembler is correctly receiving the cube and I can only guess my issue is within my shader. I did enable device creation flags but nothing related to the issue.

//Constant Buffer Variables
cbuffer constantObjects : register (b0)
    matrix World;
    matrix View;
    matrix Projection;

// Input Structure
struct VS_INPUT
    float3 inputPosition : POSITION0;
    float4 inputColor: COLOR0;

// Output Structure
struct VS_OUTPUT
    float4 position : SV_POSITION;
    float4 color : COLOR;

    // Create Pixel Shader output
    VS_OUTPUT output;

    float4 pos = float4(input.inputPosition, 1.0f);

    // Multiple to get worldViewProject for object position
    output.position = mul(pos, World);
    output.position = mul(output.position, View);
    output.position = mul(output.position, Projection);

    // Simply set color to color;
    output.color = input.inputColor;

    // Return position and color to PS
    return output;

// Create World View
worldMatrix = DirectX::XMMatrixIdentity();

// Create view matrix
DirectX::XMVECTOR eyePosition = DirectX::XMVectorSet(0.0f, 1.0f, -5.0f, 0.0f);
DirectX::XMVECTOR targetPosition = DirectX::XMVectorSet(0.0f, 1.0f, 0.0f, 0.0f);
DirectX::XMVECTOR upDirection = DirectX::XMVectorSet(0.0f, 1.0f, 0.0f, 0.0f);

// Store View Matrix
viewMatrix = DirectX::XMMatrixLookAtLH(eyePosition, targetPosition, upDirection);

// Create Projection Matrix
projectionMatrix = DirectX::XMMatrixPerspectiveFovLH(DirectX::XM_PIDIV2, (float)getHeight(), 0.01f, 100.0f);

It might be an issue with my world, view, and projection matrix but I don't really understand why that might be the issue. Here is the debug information. As you can see it goes to the input assembler correctly and has an issue with the vertex shader. Any help will be appreciated. enter image description here

  • \$\begingroup\$ Already found one error. Was giving correct aspect ratio to XMMatrixPerspectiveFovLH. I was simply giving height of application. \$\endgroup\$ – Haval May 13 '16 at 5:08

Fixed!!!!! Forgot to transpose world, view, and projection matrix. So fixing the aspect ratio and making sure to transpose the matrices fixed the issue. I have to remember that HLSL is column-major rather than row major.

| improve this answer | |
  • \$\begingroup\$ You can change HLSL to use row major as well with /Zpr or #pragma pack_matrix, and you can explicit mark matrix types with the row_major keyword. See MSDN. \$\endgroup\$ – Chuck Walbourn May 16 '16 at 17:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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