Jump to content
  • Advertisement
Sign in to follow this  
korvax

Help with WorldViewProjection

This topic is 1484 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

Hi, Im having some problem with moving out my Position Clip space calculation out of the shader and in to cpu space. That is creating a WorldViewProjection matrix and use that in the shaders.

 

 

The following shader code works fine 

PS Shader.

struct PS_INPUT
{
	float4 PositionSS : SV_POSITION;
	float2 TexCoord : TEXCOORD0;	
};
//--------------------------------------------------------------------------------------
// Pixel Shader
//--------------------------------------------------------------------------------------
PSOutput main(in PS_INPUT input)
{
	PSOutput output;
	if (isTextured)
		output.Color = txDiffuse.Sample(samLinear, input.TexCoord);
	else
		output.Color = diffuse;
	
	return output;
}
cbuffer VSConstants : register(cb0 )
{
	matrix World;
	matrix View;
	matrix Projection;	
	matrix WordViewProjection;
}
//--------------------------------------------------------------------------------------
struct VS_INPUT
{
    float3 Position	: POSITION;
    float2 TexCoord	: TEXCOORD0;
		float3 Normal	: NORMAL;		
};

struct VS_OUTPUT
{
	float4 PositionCS : SV_POSITION;
	float2 TexCoord : TEXCOORD0;	
};

//--------------------------------------------------------------------------------------
// Vertex Shader
//--------------------------------------------------------------------------------------
VS_OUTPUT main(in VS_INPUT input)
{  
	VS_OUTPUT output = (VS_OUTPUT)0;
	float4 position = float4(input.Position, 1.0f);		
	output.PositionCS = mul(position, World);		
	output.PositionCS = mul(output.PositionCS, View);              
	output.PositionCS = mul(output.PositionCS, Projection);	
	output.TexCoord = input.TexCoord;	  
  return output;
}

But I want to replace 

output.PositionCS = mul(output.PositionCS, View);
output.PositionCS = mul(output.PositionCS, Projection);	

with 

output.PositionCS = mul(position, WordViewProjection);

and my calculations for ConstantBuffer is

VSC_WORLD PipelineManagerDX11::CalculateModelSpace(const IRenderable3D &renderble)
{	
	XMMATRIX model_matrix = renderble.World.GetTransformationMatrix();
	VSC_WORLD vsS;	
	vsS.mWorld = XMMatrixTranspose(model_matrix);
	vsS.mView = XMMatrixTranspose(this->m_View);
	vsS.mProjection = XMMatrixTranspose(this->m_Projection);
	XMMATRIX WorldView = model_matrix*this->m_View;
	XMMATRIX ViewProjection = this->m_View*this->m_Projection;
	vsS.mWordViewProjection = XMMatrixTranspose(WorldView*ViewProjection);;
	return vsS;
}

Im not sure what I'm doing wrong here. But its not working, my output is completely black so something is going badly wrong with the PositionCS Calc. Im pretty sure I'm missing something basic, not sure what though.

 

All the help is much appreciated. 

Share this post


Link to post
Share on other sites
Advertisement

It appears you're calculating model_matrix * view * view * projection.

 

WorldView = model_matrix * view;

ViewProjection = view * projection; // another view matrix

mWord(sp?)ViewProjection = Transpose( WorldView * ViewProjection);

 

EDIT: You can save a little calculation by just XMMatrixTranspose( model_matrix * view * projection ), rather than having all the intermediate variables.

Edited by Buckeye

Share this post


Link to post
Share on other sites
Hi, thx, but even if I change to vsS.mWordViewProjection = XMMatrixTranspose(model_matrix*this->m_View*this->m_Projection); Im still getting same black output. I think it has to be with my WVP matrix, because it works when im doing the calculation on the shader.

Share this post


Link to post
Share on other sites

You might not have to do all those XMMatrixTranspose's on your matrices. Check if you're compiling your shaders with D3DCOMPILE_PACK_MATRIX_COLUMN_MAJOR vs D3DCOMPILE_PACK_MATRIX_ROW_MAJOR...

Share this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!