This piece is driving me nuts! it's simple and im prolly overlooking something utterly trivial but after hours of staring i cant seem to find it.
The deal, simple lighting using HLSL lit function.
The problem, when I transform the object the lighting isnt right(as though the object still is at (0,0,0). I am multiplying the vertex positions by the WVP matrix. Any ideas ? many thanks in advance!
Code: Select all
float4x4 mWorldViewProj ;
float4 fLightLocA;
float4 fLightLocB;
float4 fLightLocC;
float3 mCamPos;
struct transfer
{
float4 tex0 : TEXCOORD0;
float3 lightingA : TEXCOORD1;
float4 position : POSITION;
};
transfer vertexMain(
float4 position : POSITION ,
float3 normal : NORMAL ,
float4 tex0 : TEXCOORD0
)
{
transfer OUT;
float4 pos = mul( position,mWorldViewProj);
float3 pos2cam = normalize( mCamPos - pos);
float3 pos2lighta = normalize( fLightLocA - pos);
float3 halfwaya = (pos2lighta + pos2cam) / 2.0;
OUT.lightingA = lit(dot(pos2lighta,normal), dot(halfwaya,normal), 2);
OUT.position = pos;
OUT.tex0 = tex0;
return OUT;
}
float4 pixelMain(transfer IN ) : COLOR0
{
float4 color = IN.lightingA.z;
return color;
}
Code: Select all
core::matrix4 worldViewProj;
worldViewProj = driver->getTransform(video::ETS_PROJECTION);
worldViewProj *= driver->getTransform(video::ETS_VIEW);
worldViewProj *= driver->getTransform(video::ETS_WORLD);
services->setVertexShaderConstant("mWorldViewProj", reinterpret_cast<f32*>(&worldViewProj.M[0]), 16);