diff options
author | Charlie Jolly <charlie> | 2021-03-23 12:21:56 +0300 |
---|---|---|
committer | Charlie Jolly <mistajolly@gmail.com> | 2021-03-23 12:59:20 +0300 |
commit | d3758892987d76749fdf1211ed27ff77f39b5b3b (patch) | |
tree | 0e0b6b2a614b9829255cae77fb75f93696e7df7b /intern/cycles/util | |
parent | 4c19fcacc0b71271ca2fafc87ef5772a819e7075 (diff) |
Nodes: Add Refract and Faceforward functions to Vector Maths nodes
Cycles, Eevee, OSL, Geo, Attribute
Based on outdated refract patch D6619 by @cubic_sloth
`refract` and `faceforward` are standard functions in GLSL, OSL and Godot shader languages.
Adding these functions provides Blender shader artists access to these standard functions.
Reviewed By: brecht
Differential Revision: https://developer.blender.org/D10622
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); |