Danbias/Code/OysterGraphics/Shader/HLSL/Deffered Shaders/LightCalc.hlsli

28 lines
852 B
HLSL
Raw Normal View History

#include "Defines.hlsli"
DiffSpec LightCalc(PointLight pl, float3 pos, int2 texCoord)
{
DiffSpec output;
float4 normalSpec = NormalSpec[texCoord];
float4 LPos = mul(View, float4(pl.Pos, 1));
float3 lightVec = LPos.xyz - pos.xyz;
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
float att = max( 0, 1 - (d / pl.Radius));
//fix Ilum calcs instead of PhongBlinn
2014-01-08 07:01:59 +01:00
output.Diffuse = pl.Bright * att * diffFactor * pl.Color;
output.Specular = pl.Bright * att * specFactor * pl.Color;
if(diffFactor == 0)
output.Specular * 0;
if(d > pl.Radius)
{
2014-01-28 13:48:15 +01:00
output.Diffuse = float3(0,0,0);
output.Specular = float3(0,0,0);
}
return output;
}