2023-02-25 19:03:39 +00:00
|
|
|
#ifndef LIB_WATER_FRESNEL
|
|
|
|
#define LIB_WATER_FRESNEL
|
|
|
|
|
2023-04-21 05:02:12 +00:00
|
|
|
float fresnel_dielectric(vec3 incoming, vec3 normal, float eta)
|
2023-02-25 19:03:39 +00:00
|
|
|
{
|
2023-04-21 05:02:12 +00:00
|
|
|
float c = abs(dot(incoming, normal));
|
|
|
|
float g = eta * eta - 1.0 + c * c;
|
|
|
|
float result;
|
2023-02-25 19:03:39 +00:00
|
|
|
|
2023-04-21 05:02:12 +00:00
|
|
|
if (g > 0.0)
|
|
|
|
{
|
|
|
|
g = sqrt(g);
|
|
|
|
float A =(g - c)/(g + c);
|
|
|
|
float B =(c *(g + c)- 1.0)/(c *(g - c)+ 1.0);
|
|
|
|
result = 0.5 * A * A *(1.0 + B * B);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
result = 1.0; /* TIR (no refracted component) */
|
|
|
|
}
|
2023-02-25 19:03:39 +00:00
|
|
|
|
2023-04-21 05:02:12 +00:00
|
|
|
return result;
|
2023-02-25 19:03:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|