I begin to use the "instancied model" technique to draw my scene and I've got a problem with normal's vertex
I give to HLSL the MATRIX ( rotation / scale / position ) to draw each instance of model but I can't obtain the good normal after rotate them.
The 3D computation of my model works fine after MATRIX apply , but the light is really strange depending of normal orientation.
struct InstancingVSinput
{
float4 Position : SV_POSITION0;
float4 Norm : NORMAL0;
float2 TexCoord : TEXCOORD0;
};
struct InstancingVSoutput
{
float4 Position : POSITION0;
float3 Norm : NORMAL0;
float2 TexCoord : TEXCOORD0;
};
InstancingVSoutput InstancingVS(InstancingVSinput input,
float4 InstPos : POSITION1, float4 InstTexCoord : TEXCOORD1,
float4 Mat1 : POSITION2, float4 Mat2 : POSITION3, float4 Mat3 : POSITION4, float4 Mat4 : POSITION5)
{
InstancingVSoutput output;
float4x4 O = float4x4(Mat1, Mat2, Mat3, Mat4);
float4 pos = mul(input.Position,xWorld);
pos = mul(input.Position, O);
pos = InstPos + pos;
O = transpose(O);
float3 norm = normalize((float3)input.Norm);
norm = mul(norm, (float3x3)O);
pos = mul(pos, WVP);
output.Position = pos;
output.Norm = norm;
output.TexCoord = float2((input.TexCoord.x / 2.0f) + (1.0f / 2.0f * InstTexCoord.x),
(input.TexCoord.y / 2.0f) + (1.0f / 2.0f * InstTexCoord.y));
return output;
}
float4 InstancingPS(InstancingVSoutput input) : COLOR0
{
float4 C = tex2D(TextureSampler, input.TexCoord);
float3 N = input.Norm;
C.rgb *= dot(float3(0, -1, -1), N);
return C;
}
Should you suggest me a correct way to retrieve my normal after rotation ?
Thanx
Chris