2013-12-05 14:56:34 +01:00
|
|
|
#include "Defines.hlsli"
|
|
|
|
|
|
|
|
DiffSpec LightCalc(PointLight pl, float3 pos, int2 texCoord)
|
|
|
|
{
|
|
|
|
DiffSpec output;
|
|
|
|
float4 normalSpec = NormalSpec[texCoord];
|
2013-12-18 20:36:41 +01:00
|
|
|
float4 LPos = mul(View, float4(pl.Pos, 1));
|
|
|
|
float3 lightVec = LPos.xyz - pos.xyz;
|
2013-12-05 14:56:34 +01:00
|
|
|
float d = length(lightVec);
|
|
|
|
lightVec = lightVec/d;
|
|
|
|
|
|
|
|
float diffFactor = max(dot(lightVec, normalSpec.xyz), 0.0f);
|
|
|
|
float3 v = reflect(-lightVec, normalSpec.xyz);
|
|
|
|
float specFactor = pow(max(dot(v,normalize(-pos)), 0.0f),normalSpec.w);
|
|
|
|
//Check att later
|
2013-12-18 20:28:06 +01:00
|
|
|
float att = max( 0, 1 - (d / pl.Radius));
|
2013-12-05 14:56:34 +01:00
|
|
|
//fix Ilum calcs instead of PhongBlinn
|
2014-01-08 07:01:59 +01:00
|
|
|
output.Diffuse = pl.Bright * att * diffFactor * pl.Color;
|
2013-12-18 20:28:06 +01:00
|
|
|
output.Specular = pl.Bright * att * specFactor * pl.Color;
|
2013-12-05 14:56:34 +01:00
|
|
|
if(diffFactor == 0)
|
|
|
|
output.Specular * 0;
|
2013-12-18 20:28:06 +01:00
|
|
|
if(d > pl.Radius)
|
|
|
|
{
|
2014-01-28 13:48:15 +01:00
|
|
|
output.Diffuse = float3(0,0,0);
|
|
|
|
output.Specular = float3(0,0,0);
|
2013-12-18 20:28:06 +01:00
|
|
|
}
|
2014-02-12 13:53:52 +01:00
|
|
|
float SpecCo = normalSpec.w < 1 ? 0.0f : 1.0f;
|
|
|
|
output.Specular = output.Specular * SpecCo;
|
2013-12-05 14:56:34 +01:00
|
|
|
return output;
|
|
|
|
}
|