/* * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ /* Dispersion Refractive Shader * by François GASTALDO * * contact me at : pressf9@free.fr * * blog (3D, shaders, photos and more) : http://vadrouillegraphique.blogspot.fr/ * * Small Documentation : This Shader does a per wavelength Dispersion in a refractive material. It is brut force dispersion shader and need a lot render samples to have a correct look. There is near no optimization, so it's not made for animation. It is made for educational purpose and should be optimized and rethink for an effective production use. Indeed, result are really good for still pictures. Transp Color = Color of the transparent material. Beware that if saturation is too high, you'll not see any dispersion. IoR = Main Index of Refraction of material. disp = Dispersion , in IoR Delta. correct value are between 0.05 and 0.2. A higher number give more rainbow in transparency, and slower rendering time. A too high value ( > 0.3 ) can lead to rendering errors or inconsistency. Roughness = surface roughness. A good value is 0.0. Higher values blur refraction and could hide dispersion effect. Full render = optimization. 1.0 = no optimization, slower render but accurate. 0.0 = no dispersion except for eye rays. You'll see no dispersion on a reflect of the object, and backface is ignored. It is about 30% to 60% faster, and the difference between realistic and optimized material isn't noticeable for rendering that doen't need pure accuracy. *This shader is made for educationnal purpose only. Use it in production at your own risk. * * Closures are for Blender/Cycles. They could need adaptation for your renderer. * * If you use this material, please credit it and me. Thank you. * * Enjoy ! * * François Gastaldo * */ #include "stdosl.h" #include "node_fresnel.h" #include "oslutil.h" shader DispersionWL( color TranspColor = color(1.0, 1.0, 1.0) , float IoR = 2.0 , float disp = 0.1 , float Roughness = 0.0 , int Fullrender = 0, output closure color Verre = color(1.0 , 0.0 , 0.0) * diffuse(N) ) { //color wavelength color (float wavelength nm) int RayonCam = raytype( "camera" ) ; if ((RayonCam) || (Fullrender) ) // { float alea = noise ("cell" , P*10000.0 ) ; //point Pp = P ; float useior = mix( (IoR - ( disp/2.0) ) , (IoR + ( disp/2.0) ) , alea) ; color usecolor = TranspColor * wavelength_color( mix ( 400.0 , 615.0 , alea ) ) ; float Kr = fresnel_dielectric(I, N , useior ); float Kt = 1.0 - Kr; if (Roughness != 0.0) { Verre = ( 5.0 * Kt * usecolor * microfacet_beckmann_refraction(N, Roughness , useior) ) + ( TranspColor * Kr * microfacet_beckmann(N, Roughness) ) ; } else { Verre = ( 5.0 * Kt * usecolor * refraction(N, useior) ) + ( TranspColor * Kr * reflection(N) ) ; } } else { Verre = TranspColor * 0.8 * transparent() ; } }