diff options
Diffstat (limited to 'intern/cycles/util')
-rw-r--r-- | intern/cycles/util/util_math_float3.h | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/intern/cycles/util/util_math_float3.h b/intern/cycles/util/util_math_float3.h index 67c5c61e4c0..9673c043189 100644 --- a/intern/cycles/util/util_math_float3.h +++ b/intern/cycles/util/util_math_float3.h @@ -388,6 +388,22 @@ ccl_device_inline float3 reflect(const float3 incident, const float3 normal) return incident - 2.0f * unit_normal * dot(incident, unit_normal); } +ccl_device_inline float3 refract(const float3 incident, const float3 normal, const float eta) +{ + float k = 1.0f - eta * eta * (1.0f - dot(normal, incident) * dot(normal, incident)); + if (k < 0.0f) + return zero_float3(); + else + return eta * incident - (eta * dot(normal, incident) + sqrt(k)) * normal; +} + +ccl_device_inline float3 faceforward(const float3 vector, + const float3 incident, + const float3 reference) +{ + return (dot(reference, incident) < 0.0f) ? vector : -vector; +} + ccl_device_inline float3 project(const float3 v, const float3 v_proj) { float len_squared = dot(v_proj, v_proj); |