• Advertisement
Sign in to follow this  

Vertex normal problem

This topic is 3582 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 i have a problem that i am not eable to fix at all i pass more than 4 full day on it but nothing. I am not eable to set up a simple light i tink it is my normal beacule i am not eable to pass normal value to HLSL shader normal value stay (0.0f,0.0f,0.0f). If i draw my sceine with a simple directional light and simple (pos,normal,texture) vertex object the light is not working corectely. If i pass these object to shader i am eable to pass only the pos and texture value normal stay 0. My normal just dont want to work here is some code.
//My FVF declaration
#define D3DFVF_WORLD_VERTEX (D3DFVF_XYZ|D3DFVF_NORMAL|D3DFVF_TEX0)

//My vertex filling
for (i=0;i<NumOfVertex;i++)
{
	x=long(X)+1;y=long(Y)+1;
	VERTEX.POS = D3DXVECTOR3(X*M,Y*M,AH[x][y]);
	VERTEX.NORMAL = D3DXVECTOR3(float(X)/BW,float(Y)/BW,0.0f);
	VERTEX.UV = D3DXVECTOR2(float(X)/BW,float(Y)/BW);
	X++;if (X>BW){X=0;Y++;};
};

//My vertex structure
struct STRUCT_WORLD_VERTEX
{
	D3DXVECTOR3 POS;
	D3DXVECTOR3 NORMAL;
	D3DXVECTOR2 UV;
};

//I my shader i simply pass UV and NORMAL truth the vertex shader
//But only UV have value NORMAL is always 0

//--------------------------------------------------------------------
// Shader HeightField1 [HF1] (return black only) this is a test!!
//--------------------------------------------------------------------
struct VertexHF1
{
        float3 Pos	         : POSITION;
        float3 Normal		 : NORMAL;
        float2 Tex0	         : TEXCOORD0;
};
struct PixelHF1
{
        float4 Pos               : POSITION;
        float2 Tex0              : TEXCOORD0;
	float3 Normal	         : TEXCOORD1;
	float3 TP		 : TEXCOORD2;
	float3 LI		 : TEXCOORD3;
};
//
PixelHF1 VertexShaderHF1( VertexHF1 In )
{
	PixelHF1 Out;
	float4 Pos;
	float3 CP = CamPos;
	float3 LP = LightPos;
	Out.TP = In.Pos.xyz;
        Pos = mul(float4(In.Pos,1.0f), MatrixObject);
        Out.Pos = mul(Pos, MatrixCamera);
        Out.Tex0 = In.Tex0;
	Out.Normal = In.Normal;
	Out.LI = 0.0f;
        return Out;
}
//
float4 PixelShaderHF1( PixelHF1 In ) : COLOR
{
	float3 TP = In.TP/128.0f;
	float4 R;
	R.x = In.Normal.x;
	R.y = In.Normal.y;
	R.z = In.Normal.z;
        R.w = 1.0f;

        return R;
}

Share this post


Link to post
Share on other sites
Advertisement

Yes. Like Khaos said, make sure your vertex decl matches your vertex format..
Don't forget to call SetVertexDeclaration.

Does it work when you don't use shaders?

Share this post


Link to post
Share on other sites
Quote:
Original post by Khaos Dragon
Maybe post what your vertex declaration looks like? (The thing you pass to SetVertexDeclaration )

The FVF is posted at the top, and looks fine.

I'd suggest two things. First, verify that the the values you give your normals in the loop are what you expect them to be. They're obviously not correct normal values, but I figure they're just for testing purposes now.

Then try running the program in PIX. Check the pixels and see how the shader was run on them. That should help yoiu find out the exact device details and what the shader got.

Share this post


Link to post
Share on other sites
Your FVF has D3DFVF_TEX0 in it, but you have 1 set of texture coordinates. If you were using the Debug Runtimes, they'd be screaming and shouting abouyt this...

Share this post


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

  • Advertisement