/* * 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. */ /* Image 2 screen Shader * by François GASTALDO * * contact me at : pressf9@free.fr * * blog (3D and photos : http://vadrouillegraphique.blogspot.fr/ * * Image 2 Screen Shader * Pixelize input image * Apply gap between pixels * RGB pattern visibility * */ #include "stdosl.h" #include "node_fresnel.h" #include "oslutil.h" shader image2screen( string texture_file = "" , //color Opt_Image = color (1.0, 0.0 , 0.0), float pixelsX = 32.0 , float pixelsY = 24.0 , float ColorBitDepth = 4.0 , float viewGrid = 1.0 , float Gridthick = 0.1 , float GridFadeRange = 20.0 , string pattern_file = "" , float RGBFadeRange = 10.0 , vector uvwmap = vector (0.5,0.5,0.5) , output color screened = color ( 1.0 , 0.0 , 0.0 ) , output vector pixeluv = vector ( 1.0 , 1.0 , 1.0 ), output vector patternuv = vector ( 1.0 , 1.0 , 1.0 ) ) { //Modification de l'UV créer les pixels vector vectwork = vector ( 0.0 , 0.0 , 0.0 ) ; vectwork[0] = ( trunc(uvwmap[0] * pixelsX) ) / pixelsX ; vectwork[1] = 1.0 - ( trunc(uvwmap[1] * pixelsY ) ) / pixelsY ; pixeluv = vectwork ; // generation de la grille color grille = color(1.0 , 1.0 , 1.0) ; float uu = mod ( uvwmap[0] * (pixelsX + 0.0) , 1.0 ) ; float vv = mod ( uvwmap[1] * (pixelsY + 0.0) , 1.0 ); patternuv = vector (uu , vv , vv) ; float thick = Gridthick * 0.5 ; int condition = ( (uu < thick ) || (vv < thick) || (uu > (1.0 - thick)) || (vv > (1.0 - thick)) ) ; if ( condition ) { grille = ( 0.0 ) ; } else { grille = ( 1.0 ) ; } // pattern RGB float ampliRGB = 3.0 ; color patternRGB = texture ( pattern_file , uu , vv ) * color ( ampliRGB , ampliRGB , ampliRGB ) ; // calcul de la distance vector poscam = transform ( "common" , "camera" , P); float zdist = distance( point(0.0 , 0.0 , 0.0) , poscam ) ; float factordist = clamp ( ((zdist / GridFadeRange) -0.9 ) , 0.0 , 1.0 ) ; float factorpattern = clamp ( ((zdist / RGBFadeRange) -0.9 ) , 0.0 , 1.0 ) ; // attenuation de la grille et la pattern RGB grille = (grille * ( 1.0 - factordist)) + ( color(1.0) * factordist ); patternRGB[0] = ( pow(patternRGB[0] , 2.2 ) * ( 1.0 - factorpattern)) + ( 1.0 * factorpattern ) ; patternRGB[1] = ( pow(patternRGB[1] , 2.2 ) * ( 1.0 - factorpattern)) + ( 1.0 * factorpattern ) ; patternRGB[2] = ( pow(patternRGB[2] , 2.2 ) * ( 1.0 - factorpattern)) + ( 1.0 * factorpattern ) ; // première génération de l'image color imagebrute = texture ( texture_file , vectwork[0] , vectwork[1] ) ; float nombrecouleurs = pow( 2.0 , ColorBitDepth ) ; float gamma = 2.2 ; imagebrute[0] = patternRGB[0] * grille[0] * ( trunc( pow(imagebrute[0], gamma ) * nombrecouleurs) ) / nombrecouleurs ; imagebrute[1] = patternRGB[1] * grille[1] * ( trunc( pow(imagebrute[1], gamma ) * nombrecouleurs) ) / nombrecouleurs ; imagebrute[2] = patternRGB[2] * grille[2] * ( trunc( pow(imagebrute[2], gamma ) * nombrecouleurs) ) / nombrecouleurs ; screened = imagebrute ; }