Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


problems with shader matrices


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 directx user   Members   -  Reputation: 154

Like
0Likes
Like

Posted 03 June 2012 - 06:59 AM

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, 03 June 2012 - 08:01 AM.


Sponsor:

#2 Ripiz   Members   -  Reputation: 529

Like
0Likes
Like

Posted 03 June 2012 - 09:49 AM

Matrices might be different than you expect.
Try column_major and/or change transformation order to mul(matrix, vector).

#3 directx user   Members   -  Reputation: 154

Like
0Likes
Like

Posted 03 June 2012 - 10:20 AM

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 Posted Image.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS