Created
July 16, 2018 13:34
-
-
Save andybak/577988ee944050f4794d93604a99a650 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
float3 ShadeVertexLightsAtten ( | |
float4 lightPosX, float4 lightPosY, float4 lightPosZ, | |
float3 lightColor0, float3 lightColor1, float3 lightColor2, float3 lightColor3, | |
float4 lightAttenSq, | |
float3 pos) | |
{ | |
// to light vectors | |
float4 toLightX = lightPosX - pos.x; | |
float4 toLightY = lightPosY - pos.y; | |
float4 toLightZ = lightPosZ - pos.z; | |
// squared lengths | |
float4 lengthSq = 0; | |
lengthSq += toLightX * toLightX; | |
lengthSq += toLightY * toLightY; | |
lengthSq += toLightZ * toLightZ; | |
// attenuation | |
float4 atten = 1.0 / (1.0 + lengthSq * lightAttenSq); | |
float4 diff = ndotl * atten; | |
// final color | |
float3 col = 0; | |
col += lightColor0 * diff.x; | |
col += lightColor1 * diff.y; | |
col += lightColor2 * diff.z; | |
col += lightColor3 * diff.w; | |
return col; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment