Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCharlie Jolly <charlie>2021-03-23 12:21:56 +0300
committerCharlie Jolly <mistajolly@gmail.com>2021-03-23 12:59:20 +0300
commitd3758892987d76749fdf1211ed27ff77f39b5b3b (patch)
tree0e0b6b2a614b9829255cae77fb75f93696e7df7b /source/blender/blenlib/BLI_float3.hh
parent4c19fcacc0b71271ca2fafc87ef5772a819e7075 (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 'source/blender/blenlib/BLI_float3.hh')
-rw-r--r--source/blender/blenlib/BLI_float3.hh18
1 files changed, 18 insertions, 0 deletions
diff --git a/source/blender/blenlib/BLI_float3.hh b/source/blender/blenlib/BLI_float3.hh
index 7e49cc89b52..cbc4d4ed366 100644
--- a/source/blender/blenlib/BLI_float3.hh
+++ b/source/blender/blenlib/BLI_float3.hh
@@ -191,6 +191,24 @@ struct float3 {
return result;
}
+ static float3 refract(const float3 &incident, const float3 &normal, const float eta)
+ {
+ float3 result;
+ float k = 1.0f - eta * eta * (1.0f - dot(normal, incident) * dot(normal, incident));
+ if (k < 0.0f) {
+ result = float3(0.0f);
+ }
+ else {
+ result = eta * incident - (eta * dot(normal, incident) + sqrt(k)) * normal;
+ }
+ return result;
+ }
+
+ static float3 faceforward(const float3 &vector, const float3 &incident, const float3 &reference)
+ {
+ return dot(reference, incident) < 0.0f ? vector : -vector;
+ }
+
static float3 safe_divide(const float3 &a, const float3 &b)
{
float3 result;