mirror of
https://github.com/cocos/cocos4.git
synced 2026-12-03 17:42:41 +08:00
24 lines
794 B
Plaintext
24 lines
794 B
Plaintext
|
|
// saturated N dot V
|
|
float CalculateFresnelCoefficient(float ior, float NoVSat)
|
|
{
|
|
float g, c, n, prev, next;
|
|
n = ior;
|
|
c = ior * NoVSat;
|
|
g = sqrt(1.0 + c * c - c);
|
|
prev = (g - c) / (g + c);
|
|
next = (c * (g+c) - n*n) / (c * (g-c) + n*n);
|
|
prev *= prev;
|
|
next *= next;
|
|
return 0.5 * prev * (1.0 + next);
|
|
}
|
|
|
|
vec3 CalculateScattering(vec3 unscatteredColor, float distance, float outScatterExtinctCoef, float inScatterExtinctCoef, float inScatterCoef, vec3 inScatterColor, vec3 outScatterColor)
|
|
{
|
|
vec2 e = vec2(outScatterExtinctCoef, inScatterExtinctCoef * inScatterCoef);
|
|
vec2 extinction = exp(-e * distance);
|
|
vec3 inScattered = (1.0 - extinction.y) * inScatterColor;
|
|
vec3 outScattered = unscatteredColor * extinction.x * outScatterColor;
|
|
return outScattered + inScattered;
|
|
}
|