I want to add lightning to my application.
I tried to do it in this way, but only ambient lightning is working:
float4 PS_INS (PS_INS_INPUT input) : SV_Target{
float4 diffuse = txDiffuse.Sample( samLinear, input.Tex ) * input.Light_S + KolorL;
float4 PosD = (0, 1, 0, 0);
float4 LighD = (0.5f, 0.5f, 0.5f, 0.5f);
float4 LighA = (0.2f, 0.2f, 0.2f, 0.2f);
float4 FK;
FK = diffuse * LighA;
FK += saturate(dot(PosD, input.Nor) * LighD * diffuse);
return FK;
}
I tried found what is wrong and I found that dot function doesn't work correct.
float4 diffuse = txDiffuse.Sample( samLinear, input.Tex ) * input.Light_S + KolorL;
float4 PosD = (0, 1, 0, 0);
float4 PosW = (0, 1, 0, 0);
float4 LighD = (0.5f, 0.5f, 0.5f, 0.5f);
float4 LighA = (0.2f, 0.2f, 0.2f, 0.2f);
float4 FK;
FK = diffuse * LighA;
FK += dot(PosD, PosW) * LighD * diffuse; //LighD * diffuse is not added
FK += 1 * LighD * diffuse; //LighD * diffuse is added
Dot function should return something like this: Ax*Bx+Ay*By+Az*Bz, so dot (PosD, PosW) should return 1 (0*0+1*1+0*0+0*0).
Why doesn't dot return 1?