mirror of
https://github.com/cocos/cocos4.git
synced 2026-11-20 23:52:40 +08:00
0ecaa8db51
* add surface shader * remove unused item * arrange main-functions * arrange main-functions * fix compatible lighting mode
23 lines
836 B
Plaintext
23 lines
836 B
Plaintext
#include <common/lighting/attenuation>
|
|
|
|
// helper functions for lighting model-functions
|
|
|
|
float CalculateDistanceAttenuation(float distToLightSqr, float lightRadius, float lightRange)
|
|
{
|
|
float litRadiusSqr = lightRadius * lightRadius;
|
|
float attRadiusSqrInv = 1.0 / max(lightRange, 0.01);
|
|
attRadiusSqrInv *= attRadiusSqrInv;
|
|
|
|
// soft edge fading
|
|
float edgeAttenuation = litRadiusSqr / max(litRadiusSqr, distToLightSqr);
|
|
return GetDistAtt(distToLightSqr, attRadiusSqrInv) * edgeAttenuation;
|
|
}
|
|
|
|
float CalculateAngleAttenuation(vec3 spotLightDir, vec3 L, float cosAngleOuter)
|
|
{
|
|
float cosInner = max(dot(spotLightDir, L), 0.01);
|
|
float litAngleScale = 1.0 / max(0.001, cosInner - cosAngleOuter);
|
|
float litAngleOffset = -cosAngleOuter * litAngleScale;
|
|
return GetAngleAtt(L, spotLightDir, litAngleScale, litAngleOffset);
|
|
}
|