[Using HLSL, an *.fx file and DirectX9]
I'm new to using shaders and have got a scenario working but don't understand why. I'm confused as to how the mesh can have one version of the vertex decleration while the shader can define another.
I create a ID3DXMesh
sphere with D3DXCreateSphere(...)
, which comes setup with D3DFVF_XYZ | D3DFVF_NORMAL
. I call ID3DXMesh::DrawSubset(0)
to render; inside BeginPass/EndPass calls.
I then have a vertex shader with the struct defined:
struct Vertex {
float4 position:POSITION;
float2 textureCoords:TEXCOORD0;
float3 lightDir:TEXCOORD1;
float3 normal:TEXCOORD2;
};
and the shader itself:
Vertex vertexShader( Vertex original, float3 _normal:NORMAL ) {
Vertex result = (Vertex)0;
float4x4 worldViewMatrix = mul( worldMatrix, viewMatrix );
float4x4 worldViewProjectionMatrix = mul( worldViewMatrix, projectionMatrix );
result.position = mul( original.position, worldViewProjectionMatrix );
result.normal = -normalize( mul(_normal, worldMatrix) );
result.textureCoords = original.textureCoords;
result.lightDir = normalize(presetLightDir);
return result;
}
While I recognize that the lightDir and textureCoords might as well be null before I set them, what data does DirectX actually give in that Vertex original
parameter?
Just the position? I notice that the float3 _normal:NORMAL
is offered as a separate parameter but is that value also inside original
at the start of the shader too?