• Advertisement
Sign in to follow this  

problems with shader matrices

This topic is 2147 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello Forum,

I have currently some issues with my shader code:

cbuffer matrizen : register( b0 )
{
row_major matrix World;
row_major matrix View;
row_major matrix Projection;

};


struct VS_INPUT
{
float4 Pos : POSITION;
};

struct PS_INPUT
{
float4 Pos : SV_POSITION;
};


//--------------------------------------------------------------------------------------
// Vertex Shader
//--------------------------------------------------------------------------------------
PS_INPUT VS( VS_INPUT input )
{
PS_INPUT output = (PS_INPUT)0;

output.Pos = mul(input.Pos,World);
output.Pos = mul(output.Pos,View);
output.Pos = mul(output.Pos,Projection);

return output;
}


//--------------------------------------------------------------------------------------
// Pixel Shader
//--------------------------------------------------------------------------------------
float4 PS( PS_INPUT input) : SV_Target
{
return float4(1.0f,0.0f,0.0f,1.0f);
}


actually this code is mostly copied from the directx sample browser and should work as it also works in the sample project. The Problem is, it doesnt displays anything if i apply the matrix transformations inside the vertex shader. The Matrices are assigned over this code.


struct Mats
{
XMMATRIX World;
XMMATRIX View;
XMMATRIX Projection;
};
........................
Mats mat;
mat.World = XMMatrixIdentity(); //no geometry transformations
XMVECTOR Eye = XMVectorSet( 0.0f, 0.0f, 5.0f, 0.0f );
XMVECTOR At = XMVectorSet( 0.0f, 0.0f, 0.0f, 0.0f );
XMVECTOR Up = XMVectorSet( 0.0f, 1.0f, 0.0f, 0.0f );
mat.View = XMMatrixLookAtLH( Eye, At, Up ); //looking on the triangle
mat.Projection = XMMatrixPerspectiveFovLH( XM_PIDIV4, (FLOAT)width / (FLOAT)height, 0.01f, 100.0f ); //calculating perspective matrix


immediatecontext->UpdateSubresource( Matrixbuffer 0, NULL, &mat, 0, 0 ); //updating matrices


drawing the content:

immediatecontext->VSSetShader( vertexshader, NULL, 0 ); //using the vertexshader
immediatecontext->VSSetConstantBuffers( 0, 1, &Matrixbuffer ); //assign matrices to the vertexshader
immediatecontext->PSSetShader( pixelshader, NULL, 0 ); //using the pixelshader
immediatecontext->Draw( 3, 0 ); //drawing three vertices (one single triangle)
swapchain->Present( 0, 0 );



I guess there is a really easy solution to this problem but currently i dont know how i could fix that.

EDIT: Leaving the matrices Identity matrices doesnt solves the problem so the problem has to be inside the matrix assignment (without doing the matrix transformations it display the triangle) Edited by directx user

Share this post


Link to post
Share on other sites
Advertisement
Matrices might be different than you expect.
Try column_major and/or change transformation order to mul(matrix, vector).

Share this post


Link to post
Share on other sites
thx for your reply, but i detected the problem. The Problem was the matrix assigment, i changed the assignment to the map-unmap solution and it worked. thx anyway for telling me the fact that the shader can handle the storaging of the matrice as column major or row major i will recognize it when i will have my next transformation Issues rolleyes.gif.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement