/* * 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. */ /* Triple R G B Ambient Occlusion Vray compatible Version * * by François GASTALDO * * contact me at : pressf9@free.fr * * blog (3D, shaders, photos and more) : http://vadrouillegraphique.blogspot.fr/ * * V1.0 : For OSL 1.3 WITHOUT 'getmessage' implemented in renderer. This shader is a Multiple Ambient Occlusion in one shader It does three Ambient Occlusion, one on each color channel. Small Documentation : AO Angle : Occlusion search angle in RADIAN, 1.0 = 180° AO search Maxdistance : Limit of distance of occluding object. The smallest it is, the smallest scene detail are highlithed by AO. If there is Green and Blue AO, Maxdistance is for RED only. GreenAO : enable Green channel AO GreenAODistance : Limit of distance of occluding object for GREEN channel. BlueAO : enable Blue channel AO BlueAODistance : Limit of distance of occluding object for BLUE channel. BoostExposure : compensate the exposure by boosting the output. OverSampling : multiply the number AO ray rendered. doing 4 AA samples with 10 OverSampling AO rays is faster than doing 40 AA sampling with no Oversampmling. A good Value is between 4 to 16. * 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 shader, please credit it and me. Thank you. * * Enjoy ! * * François Gastaldo */ shader TriGAOVr( float AO_Angle = 0.95 , float maxDistance = 25.0 , int GreenAO = 0 [[ string widget = "checkBox" ]], float GreenAODistance = 150.0 , int BlueAO = 0 [[ string widget = "checkBox" ]], float BlueAODistance = 5.0 , float BoostExposure = 1.0 , float OverSampling = 4 , output closure color TriAO = color(1.0,1.0,1.0) * emission() ) { // Disable diffuse emission from this material int RTdiffuse = raytype ("diffuse") ; if ( RTdiffuse ) { closure color NullClosure = 0.0 ; TriAO = NullClosure ; } else { // Init color CoulOut = color(0.0,0.0,0.0) ; closure color closureIn = emission() ; // Loop init int Loopi = 0 ; float LoopShift = 0.0007 ; for( Loopi ; Loopi < OverSampling ; Loopi++ ) { LoopShift += 0.001 ; // compute vector to trace Ray = random * N + subtle variations... vector VectorAO = N + ( LoopShift * noise("perlin", P*(10000.0+Loopi) ) ) ; if ( AO_Angle != 0.0 ) { vector bruitvector = AO_Angle * noise("perlin", VectorAO*(10000.0+Loopi) ); VectorAO += bruitvector ; } // init for trace float mixageRED = 1.0 ; float mixageGreen = 1.0 ; float mixageBlue = 1.0 ; vector DirTrace = VectorAO ; // Trace the RED Ray int DoTraceRED = trace (P, DirTrace , "maxdist" , maxDistance ) ; if ( DoTraceRED ) { mixageRED = 0.0 ; } if (GreenAO) { // Trace the Green Ray int DoTraceGreen = trace (P, DirTrace , "maxdist" , GreenAODistance ) ; if ( DoTraceGreen ) { mixageGreen = 0.0 ; } }else { mixageGreen = mixageRED ; } if (BlueAO) { // Trace the BLUE Ray int DoTraceBlue = trace (P, DirTrace , "maxdist" , BlueAODistance ) ; if ( DoTraceBlue ) { mixageBlue = 0.0 ; } }else { mixageBlue = mixageRED ; } // Add 1/x of loop contribution CoulOut += color( mixageRED , mixageGreen , mixageBlue ) * (1.0/OverSampling) ; } // closure out TriAO = BoostExposure * ( (closureIn * CoulOut) ) ; } }