Files
cocos4/editor/assets/chunks/common/lighting/bxdf.chunk
T
2023-03-20 17:21:02 +08:00

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;
}