Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add BaGlass by Bao2

  • Loading branch information...
commit f72ae60635e0ef8c289bc152cc082368c69b9d7e 1 parent 3c160b4
SAmbler authored
View
BIN  glass/BaGlass/BaGlass.noodle.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
110 glass/BaGlass/BaGlass.osl
@@ -0,0 +1,110 @@
+/*
+ * BaGlass.osl by Bao2 (c)2012
+ * from https://github.com/sambler/osl-shaders
+ *
+ * original script from -
+ * http://blenderartists.org/forum/showthread.php?270332-OSL-Goodness/page7
+ *
+ */
+
+/*
+A Glass shader that exposes several useful values:
+
+Sharp_Beckmann_GGX can be 0, 1 or 2 to choose the mode
+
+Reflections:
+Strength: 1.0 would be the same as default cycles glass. Try higher values to give more reflection.
+FromBack: When a ray enters the glass from behind we can calculate only refractions and it renders less noisy
+and faster but darker. So to not calculate reflections in this case put this to 0.
+
+Refractions:
+Strength: 1.0 would be the cycles default glass.
+
+To be physically correct reflection strength + refraction strength must be 2.0. So you can put 1.0 and 1.0 (default cycles shader). Or if you change first one to 1.3 then the second must be 0.7 so the sum continues to be 2.0.
+
+IOR can be set to a value < 1.0 too (useful if you are creating a glass with a liquid inside and you don't want to change the direction of the normals in the liquid-glass interface and it needs a IOR < 1.0.
+
+Notes:
+- The fresnel function now is inlined but rendertime is the same,
+ that means that the compiler already was doing that inlining.
+- When Strength_Reflection is 0.0 it avoids to call the reflection functions,
+ making so the shader almost 200% faster.
+- This shader gives the same result than cycles shader when you uses Strengths = 1.0
+- The code is just a reordering of the original glass shader by Brecht and
+ some thing from the OSL shader by Imageworks.
+
+*/
+
+#include "stdosl.h"
+
+#define MIN(x, y) ((x) < (y) ? (x) : (y))
+#define MAX(x, y) ((x) > (y) ? (x) : (y))
+
+shader BaGlass(
+ int Sharp_Beckmann_GGX = 1, /* 0:Sharp 1:Beckmann 2:GGX */
+ color Reflection_Color = color(0.8, 0.8, 0.8),
+ float Reflection_Strength = 1.0, /* Strength of the reflection (0: No reflections) */
+ float Reflection_Roughness = 0.05,
+ int Reflection_FromBack = 1, /* 1:Calculate reflection for ray coming from backfaces 0:Don't */
+ color Refraction_Color = color(0.8, 0.8, 0.8),
+ float Refraction_Strength = 1.0, /* Strength of the refraction (0: No refractions) */
+ float Refraction_Roughness = 0.05,
+ float IOR = 1.52,
+ normal Normal = N,
+ output closure color BSDF = holdout() )
+{
+ float eta = backfacing() ? 1.0/IOR : IOR;
+
+ /* compute fresnel reflectance without explicitly computing the refracted direction */
+ float A, B;
+ float c = fabs(dot(I, Normal));
+ float g = eta * eta - 1 + c * c;
+ float Fr = 1.0; /* TIR (no refracted component) */
+
+ /* clamp Sharp_Beckmann_GGX between 0 and 2
+ we only seem to have float clamps so do this with macros */
+ int SharpStyle = MAX(MIN(Sharp_Beckmann_GGX,2),0);
+ /* also clamp Reflection_FromBack */
+ int BackReflect = MAX(MIN(Reflection_FromBack,1),0);
+ if (!BackReflect) SharpStyle = 0;
+
+ if (g > 0) {
+ g = sqrt(g);
+ A = (g - c) / (g + c);
+ B = (c * (g + c) - 1) / (c * (g - c) + 1);
+ Fr = 0.5 * A * A * (1 + B * B);
+ }
+
+ if ( (!backfacing() && (Reflection_Strength > 0.001)) ||
+ (backfacing() && BackReflect && (Reflection_Strength > 0.001)) )
+ {
+ if (SharpStyle == 0)
+ {
+ BSDF = Reflection_Color * Fr * Reflection_Strength * reflection(Normal) +
+ Refraction_Color * (1.0 - Fr) * Refraction_Strength * refraction(Normal, eta);
+ }
+ else if (SharpStyle == 1)
+ {
+ BSDF = Reflection_Color * Fr * Reflection_Strength *
+ microfacet_beckmann(Normal, Reflection_Roughness) +
+ Refraction_Color * (1.0 - Fr) * Refraction_Strength *
+ microfacet_beckmann_refraction(Normal, Refraction_Roughness, eta);
+ }
+ else if (SharpStyle == 2)
+ {
+ BSDF = Reflection_Color * Fr * Reflection_Strength *
+ microfacet_ggx(Normal, Reflection_Roughness) +
+ Refraction_Color * (1.0 - Fr) * Refraction_Strength *
+ microfacet_ggx_refraction(Normal, Refraction_Roughness, eta);
+ }
+ }
+ else
+ {
+ if (SharpStyle == 0)
+ {
+ BSDF = Refraction_Color * (1.0 - Fr) * Refraction_Strength *
+ refraction(Normal, eta);
+ }
+ }
+}
+
View
15 glass/BaGlass/BaGlass.osl.bcm
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<material view_color="rgb(0.80000, 0.80000, 0.80000)" sample_lamp="True">
+ <nodes>
+ <node type="OUTPUT_MATERIAL" loc="282, 304" />
+ <node type="SCRIPT" mode="INTERNAL" script="0" sharp_beckmann_ggx="2" reflection_color="rgba(0.67045, 0.74640, 0.79615, 1.0)" reflection_strength="1.0" reflection_roughness="0.05000" reflection_fromback="1" refraction_color="rgba(0.52192, 0.47381, 0.94660, 1.0)" refraction_strength="1.0" refraction_roughness="0.05000" ior="1.51999" normal="Vector(0.0, 0.0, 0.0)" loc="-40, 312" />
+ </nodes>
+ <links>
+ <link to="0" input="0" from="1" output="0" />
+ </links>
+ <scripts>
+ <script name="BaGlass.osl" id="0">
+/*<br /> * BaGlass.osl by Bao2 (c)2012<br /> * from https://github.com/sambler/osl-shaders<br /> *<br /> * original script from -<br /> * http://blenderartists.org/forum/showthread.php?270332-OSL-Goodness/page7<br /> *<br /> */<br /><br />/*<br />A Glass shader that exposes several useful values:<br /><br />Sharp_Beckmann_GGX can be 0, 1 or 2 to choose the mode<br /><br />Reflections:<br />Strength: 1.0 would be the same as default cycles glass. Try higher values to give more reflection.<br />FromBack: When a ray enters the glass from behind we can calculate only refractions and it renders less noisy<br />and faster but darker. So to not calculate reflections in this case put this to 0.<br /><br />Refractions: <br />Strength: 1.0 would be the cycles default glass. <br /><br />To be physically correct reflection strength + refraction strength must be 2.0. So you can put 1.0 and 1.0 (default cycles shader). Or if you change first one to 1.3 then the second must be 0.7 so the sum continues to be 2.0.<br /><br />IOR can be set to a value &lt; 1.0 too (useful if you are creating a glass with a liquid inside and you don't want to change the direction of the normals in the liquid-glass interface and it needs a IOR &lt; 1.0.<br /><br />Notes: <br />- The fresnel function now is inlined but rendertime is the same,<br /> that means that the compiler already was doing that inlining.<br />- When Strength_Reflection is 0.0 it avoids to call the reflection functions,<br /> making so the shader almost 200% faster.<br />- This shader gives the same result than cycles shader when you uses Strengths = 1.0<br />- The code is just a reordering of the original glass shader by Brecht and <br /> some thing from the OSL shader by Imageworks.<br /><br />*/<br /><br />#include &quot;stdosl.h&quot;<br /><br />#define MIN(x, y) ((x) &lt; (y) ? (x) : (y))<br />#define MAX(x, y) ((x) &gt; (y) ? (x) : (y))<br /><br />shader BaGlass(<br /> int Sharp_Beckmann_GGX = 1, /* 0:Sharp 1:Beckmann 2:GGX */<br /> color Reflection_Color = color(0.8, 0.8, 0.8),<br /> float Reflection_Strength = 1.0, /* Strength of the reflection (0: No reflections) */ <br /> float Reflection_Roughness = 0.05,<br /> int Reflection_FromBack = 1, /* 1:Calculate reflection for ray coming from backfaces 0:Don't */<br /> color Refraction_Color = color(0.8, 0.8, 0.8),<br /> float Refraction_Strength = 1.0, /* Strength of the refraction (0: No refractions) */ <br /> float Refraction_Roughness = 0.05,<br /> float IOR = 1.52,<br /> normal Normal = N,<br /> output closure color BSDF = holdout() )<br />{<br /> float eta = backfacing() ? 1.0/IOR : IOR;<br /><br /> /* compute fresnel reflectance without explicitly computing the refracted direction */<br /> float A, B;<br /> float c = fabs(dot(I, Normal));<br /> float g = eta * eta - 1 + c * c;<br /> float Fr = 1.0; /* TIR (no refracted component) */<br /><br /> /* clamp Sharp_Beckmann_GGX between 0 and 2 <br /> we only seem to have float clamps so do this with macros */<br /> int SharpStyle = MAX(MIN(Sharp_Beckmann_GGX,2),0);<br /> /* also clamp Reflection_FromBack */<br /> int BackReflect = MAX(MIN(Reflection_FromBack,1),0);<br /> if (!BackReflect) SharpStyle = 0;<br /><br /> if (g &gt; 0) {<br /> g = sqrt(g);<br /> A = (g - c) / (g + c);<br /> B = (c * (g + c) - 1) / (c * (g - c) + 1);<br /> Fr = 0.5 * A * A * (1 + B * B);<br /> }<br /><br /> if ( (!backfacing() &amp;&amp; (Reflection_Strength &gt; 0.001)) ||<br /> (backfacing() &amp;&amp; BackReflect &amp;&amp; (Reflection_Strength &gt; 0.001)) )<br /> {<br /> if (SharpStyle == 0)<br /> {<br /> BSDF = Reflection_Color * Fr * Reflection_Strength * reflection(Normal) +<br /> Refraction_Color * (1.0 - Fr) * Refraction_Strength * refraction(Normal, eta);<br /> }<br /> else if (SharpStyle == 1)<br /> {<br /> BSDF = Reflection_Color * Fr * Reflection_Strength *<br /> microfacet_beckmann(Normal, Reflection_Roughness) +<br /> Refraction_Color * (1.0 - Fr) * Refraction_Strength *<br /> microfacet_beckmann_refraction(Normal, Refraction_Roughness, eta);<br /> }<br /> else if (SharpStyle == 2)<br /> {<br /> BSDF = Reflection_Color * Fr * Reflection_Strength *<br /> microfacet_ggx(Normal, Reflection_Roughness) +<br /> Refraction_Color * (1.0 - Fr) * Refraction_Strength *<br /> microfacet_ggx_refraction(Normal, Refraction_Roughness, eta);<br /> }<br /> }<br /> else <br /> {<br /> if (SharpStyle == 0)<br /> {<br /> BSDF = Refraction_Color * (1.0 - Fr) * Refraction_Strength *<br /> refraction(Normal, eta);<br /> }<br /> }<br />}<br /><br />
+ </script>
+ </scripts>
+</material>
View
BIN  glass/BaGlass/BaGlass.osl.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Please sign in to comment.
Something went wrong with that request. Please try again.