Hi,
I have a irrigating problem in my hobby engine witch I had have for a while now, I'm not sure what I'm doing wrong and hopping that some one can explain to me whats going in. In short: I'm trying to introduce Normals to my small project, currently I'm not trying to do anything with them just be able to display an object correctly with Normals in my Vertex. Without the "Normal" part of the code everything is displaying fine, but as soon as i have Normal "support" in my vertex everything is getting twisted.
This is what I'm doing with Normals.
struct Vertex
{
XMFLOAT3 pos;
XMFLOAT2 tex;
XMFLOAT3 normal;
};
and creating an D3D11_INPUT_ELEMENT_DESC with normals "support"
D3D11_INPUT_ELEMENT_DESC layout[] =
{
{ "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 },
{ "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 },
{ "NORMAL", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 },
};
and Im creating the object with Normals (and the usual indices as well, not included here though). This object displays fine we im deleting all new "normal" code
UINT fsize =20;
UINT nPlane_Vertices=4;
Vertex plane_vertice[] =
{
{ XMFLOAT3( -1.0f*fsize,0.0f, 1.0f*fsize ), XMFLOAT2( 0.0f, 0.0f ) , XMFLOAT3(0.0f,1.0f,0.0f)},
{ XMFLOAT3( 1.0f*fsize, 0.0f,1.0f*fsize), XMFLOAT2( 1.0f*fsize, 0.0f ) , XMFLOAT3(0.0f,1.0f,0.0f)},
{ XMFLOAT3( -1.0f*fsize,0.0f, -1.0f*fsize), XMFLOAT2( 0.0f, 1.0f*fsize ) , XMFLOAT3(0.0f,1.0f,0.0f)},
{ XMFLOAT3( 1.0f*fsize, 0.0f,-1.0f*fsize ), XMFLOAT2( 1.0f*fsize, 1.0f*fsize ),XMFLOAT3(0.0f,1.0f,0.0f)},
};
last the shaders. VS:
cbuffer VSConstants : register(cb0 )
{
matrix World;
matrix View;
matrix Projection;
}
//--------------------------------------------------------------------------------------
struct VS_INPUT
{
float4 Pos : POSITION;
float2 Tex : TEXCOORD0;
float3 Normal : NORMAL;
};
struct PS_INPUT
{
float4 Pos : SV_POSITION;
float2 Tex : TEXCOORD0;
float3 Normal : NORMAL;
};
//--------------------------------------------------------------------------------------
// Vertex Shader
//--------------------------------------------------------------------------------------
PS_INPUT main( 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 );
output.Tex = input.Tex;
output.Normal = mul( input.Normal, World );
output.Normal = normalize(output.Normal);
return output;
}
and ps.
//--------------------------------------------------------------------------------------
// Constant Buffer Variables
//--------------------------------------------------------------------------------------
Texture2D txDiffuse : register( t0 );
SamplerState samLinear : register( s0 );
cbuffer cbPerObject : register(b0)
{
float4 diffuse;
bool isTextured;
}
//--------------------------------------------------------------------------------------
struct PS_INPUT
{
float4 Pos : SV_POSITION;
float2 Tex : TEXCOORD0;
float3 Normal : NORMAL;
};
//--------------------------------------------------------------------------------------
// Pixel Shader
//--------------------------------------------------------------------------------------
float4 main(PS_INPUT input) : SV_Target
{
if (isTextured==true)
return txDiffuse.Sample( samLinear, input.Tex );
else
return diffuse;
}
My feeling is that it might be a variable size between, application space and gpu space in the shader on the vertex but I'm not sure.. Out of ideas right now. Anyone pls?






