1
votes

Hy everyone. I started re-coding my engine to convert it to directx 11. I'm now trying to get the basics working, but this error is really stoping me. I created a basic shader, a simple dot product of the normal and the view. I got it to compile without errors, but it dosnt works. It just totaly deforms the input mesh. I started debugging in vs2012, and found out that the pixel shader was getting as input all NaNs. I attached two screens and the shader code, if someone can provide any ideas, it would be really apriciated.

VS2012 Debugging info 1 VS2012 Debugging info 2

Vertex Shader

//----------------------------------------------------------------------------   
// Constant Buffer Variables
//----------------------------------------------------------------------------
cbuffer ConstantBuffer : register( b0 )
{
matrix World;
matrix View;
matrix Projection;
//float3 CameraPos;
float Power;
}

//--------------------------------------------------------------------------- 
struct VS_INPUT
{
   float4 Pos : POSITION;
   float3 Normal : NORMAL;
};
struct VS_OUTPUT
{
    float4 Pos : SV_POSITION;
float3 Normal : TEXCOORD0;
};

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

   output.Pos = mul( input.Pos, World );
   output.Pos = mul( output.Pos, View );
   output.Pos = mul( output.Pos, Projection );
   output.Normal = mul( float4( input.Normal, 1 ), World ).xyz;
   //output.wNormal = input.Normal;
   return output;
 }

And here the Pixel Shader

//------------------------------------------------------------------------------
// Constant Buffer Variables
//------------------------------------------------------------------------------
cbuffer ConstantBuffer : register( b0 )
{
matrix World;
matrix View;
matrix Projection;
float Power;
}

//------------------------------------------------------------------------------
struct VS_OUTPUT
{
    float4 Pos : SV_POSITION;
float3 wNormal : TEXCOORD0;
};


//-----------------------------------------------------------------------------
// Pixel Shader
//-----------------------------------------------------------------------------
float4 PS( VS_OUTPUT input) : SV_Target
{
    //return pow(dot(input.wNormal,float3(0,0,0)),Power); // fixed camera, just for now
return float4(0.1,0.6,0.1,1);
}

And at last, i created a xml file structure for my shaders, that i then parse, dont know if it relevant, but

<?xml version="1.0" encoding="utf-8"?>
<vs path = "D:\\Documentos\\Visual Studio 2012\\Projects\\Fusion Engine\\Tests\\ConstantLighting_VS.hlsl" name ="VS" target = "vs_4_0">
</vs>
<ps path = "D:\\Documentos\\Visual Studio 2012\\Projects\\Fusion Engine\\Tests\\ConstantLighting_PS.hlsl" name ="PS" target = "ps_4_0">
  <val1 type = "scalar" value = "0.456645" name = "Power"/>
</ps>
4

4 Answers

1
votes

You could just use #pragma pack_matrix(row_major) in your shader instead of tranposing matrices on the cpu side

0
votes

Try simply concatenating the WorldViewProjection matrices into one, before calling the vertex function. Hopefully all of those compnenets were okay, not, say, all zero's? You might also want to explicitly set the matrix type in your HLSL code as "matrix <float, 4, 4>" or just declare the transform(s) as "float4x4".

0
votes

Ok, i solved it. You MUST use DirectX::XMMatrixTranspose() when you pass any matrix to the shader. Tricky DirectX ;)

0
votes

Only in DirectX 11 you have to transpose the matrices berfore sending them to shader. They changed the way you keep and work with structures in shaders