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:
authorJeroen Bakker <j.bakker@atmind.nl>2018-05-22 17:59:12 +0300
committerJeroen Bakker <j.bakker@atmind.nl>2018-05-22 17:59:43 +0300
commit1b164cf81e10523491ad525bc86f7ff3bbdcf4b0 (patch)
treeecab4b18a6e242361d6b505cc0026086ec0f05c7 /source/blender/draw/engines/workbench/shaders/workbench_common_lib.glsl
parent8644eef5c309ee2b28f6e6935e98e88bb6732633 (diff)
Workbench: SeeThrough
added a fresnel effect TODO: solve memory leak
Diffstat (limited to 'source/blender/draw/engines/workbench/shaders/workbench_common_lib.glsl')
-rw-r--r--source/blender/draw/engines/workbench/shaders/workbench_common_lib.glsl27
1 files changed, 27 insertions, 0 deletions
diff --git a/source/blender/draw/engines/workbench/shaders/workbench_common_lib.glsl b/source/blender/draw/engines/workbench/shaders/workbench_common_lib.glsl
index 5b646f8e911..2550f44271b 100644
--- a/source/blender/draw/engines/workbench/shaders/workbench_common_lib.glsl
+++ b/source/blender/draw/engines/workbench/shaders/workbench_common_lib.glsl
@@ -35,3 +35,30 @@ vec2 normal_encode(vec3 n)
float p = sqrt(n.z * 8.0 + 8.0);
return vec2(n.xy / p + 0.5);
}
+
+void fresnel(vec3 I, vec3 N, float ior, out float kr)
+{
+ float cosi = clamp(dot(I, N), -1.0, 1.0);
+ float etai = 1.0;
+ float etat = ior;
+ if (cosi > 0) {
+ etat = 1.0;
+ etai = ior;
+ }
+
+ // Compute sini using Snell's law
+ float sint = etai / etat * sqrt(max(0.0, 1.0 - cosi * cosi));
+ // Total internal reflection
+ if (sint >= 1) {
+ kr = 1;
+ }
+ else {
+ float cost = sqrt(max(0.0, 1.0 - sint * sint));
+ cosi = abs(cosi);
+ float Rs = ((etat * cosi) - (etai * cost)) / ((etat * cosi) + (etai * cost));
+ float Rp = ((etai * cosi) - (etat * cost)) / ((etai * cosi) + (etat * cost));
+ kr = (Rs * Rs + Rp * Rp) / 2;
+ }
+ // As a consequence of the conservation of energy, transmittance is given by:
+ // kt = 1 - kr;
+}