52 lines
1.6 KiB
Plaintext
52 lines
1.6 KiB
Plaintext
#pragma once
|
|
|
|
float3 MRUKHighlights(float3 TranslatedWorldPosition, MaterialFloat TotalLights, MaterialFloat3 PixelNormal, inout MaterialFloat TotalLightAlpha)
|
|
{
|
|
float3 TotalLight = 0;
|
|
TotalLightAlpha = 0;
|
|
|
|
UNROLL_N(2)
|
|
for (int i = 0; i < TotalLights; i++)
|
|
{
|
|
int groupID = 2 + i * 3;
|
|
half4 PositionParam = MaterialCollection0.Vectors[groupID];
|
|
half4 DataParam = MaterialCollection0.Vectors[groupID + 1];
|
|
half4 ColorParam = MaterialCollection0.Vectors[groupID + 2];
|
|
|
|
// LightWorldPosition = float3(PositionParam.xyz);
|
|
// float LightColor = float3(ColorParam.xyz);
|
|
// float LightInvRadius = DataParam.x;
|
|
// float LightIntensity = DataParam.y;
|
|
// float LightFalloffExponent = DataParam.z;
|
|
// bool LightInverseSquared = DataParam.w;
|
|
|
|
half3 ToLight = PositionParam.xyz - TranslatedWorldPosition;
|
|
|
|
half DistanceSqr = dot(ToLight, ToLight);
|
|
half3 L = ToLight * rsqrt(DistanceSqr);
|
|
|
|
float LightMask = 0;
|
|
|
|
FLATTEN
|
|
if (DataParam.w > 0.0)
|
|
{
|
|
LightMask = Square(saturate(1 - Square(DistanceSqr * Square(DataParam.x))));
|
|
DataParam.y *= 0.0001; //fake intensity multiplier, dividing by 0.0001 because Inverse Squared Falloff require really high intensity
|
|
}
|
|
else
|
|
{
|
|
half3 WorldLightVector = ToLight * DataParam.x;
|
|
half NormalizeDistanceSquared = dot(WorldLightVector, WorldLightVector);
|
|
LightMask = pow(1.0f - saturate(NormalizeDistanceSquared), DataParam.z);
|
|
}
|
|
|
|
half angle = saturate(dot(L, PixelNormal));
|
|
LightMask *= angle;
|
|
|
|
TotalLight += LightMask * ColorParam.xyz * DataParam.y;
|
|
TotalLightAlpha += LightMask;
|
|
}
|
|
|
|
return TotalLight;
|
|
}
|