slim 1 extensions pixardb { extensions pixar pxsl { template shadingmodel amboccR { description "Raytraced ambient occlusion." parameter string subset { label "Trace Subset" description { The name of a set of objects which are visible to indirectdiffuse rays. } default {} } parameter float maxdist { label "Max Distance" description { Bypassed when does reflection occlusion.The maximum distance to consider when calculating ray intersections. Setting this parameter to a negative number is effectively equivalent to setting the distance to infinity. (And a lot easier). } default -1 subtype vslider range {0 1000000 100} } parameter float samples { default 16 } collection shadingmodel shadingmodel { access output display hidden parameter color CI { detail varying default "0 0 0" access output } parameter color OI { detail varying default "0 0 0" access output } } RSLFunction { void pxslamboccR(uniform string subset; float maxdist,samples; output color CI; output color OI; ) { extern point P; extern normal N; extern vector I; normal Nf = faceforward (normalize(N), I); float res,hits,switch=1; if( samples > 0 ) res = occlusion(P, Nf, samples, "maxdist", maxdist, "subset", subset); else res=1; CI=1-res; OI = 1; } } } template shadingmodel amboccD { description "Depth-based ambient occlusion." parameter float bias { detail uniform default 0.05 } parameter float dobent { label "Do bentNormal" detail uniform subtype switch default 0 } collection shadingmodel shadingmodel { access output display hidden parameter color CI { detail varying default "0 0 0" access output } parameter color OI { detail varying default "0 0 0" access output } } RSLFunction { void pxslamboccD(uniform float bias,dobent; output color CI; output color OI;) { color vector2color(vector v) { return ((color v) + 1) / 2; } extern point P; extern normal N; extern vector I; normal Nf = faceforward (normalize(N), I); normal Nn = normalize(N); matrix shadNDCSpace,shadcamSpace; float NDCs,NDCt; float shd=0; float Ddata; point NDCP,cameraP; string shdname; float occlSum = 0; vector dirSum = 0; float dotSum = 0; float dot; color shdC=0; illuminance( "domelight",P, Nn, PI/2 ) { extern vector L; vector Ln = normalize( L ); if (lightsource("__shdname", shdname) != 0) { textureinfo(shdname, "projectionmatrix", shadNDCSpace); textureinfo(shdname, "viewingmatrix", shadcamSpace); NDCP = transform (shadNDCSpace,P); NDCs = 0.5*(1+xcomp(NDCP)); NDCt = 0.5*(1-ycomp(NDCP)); Ddata = float texture(shdname, NDCs, NDCt, NDCs, NDCt, NDCs, NDCt, NDCs, NDCt, "samples", 1); cameraP = transform(shadcamSpace, P); shd = step(-bias, Ddata - zcomp(cameraP) ); } dot = Ln.Nn; occlSum += dot * shd; dirSum += Ln * shd * dot; dotSum +=dot; } if(dotSum>0) occlSum/=dotSum; vector bent = normalize(dirSum) - Nf; if(dobent == 0) CI = occlSum; else CI = vector2color(bent); OI = 1; } } } template light domeSpot { lighttype spot parameter string shdname { description "Tell the surfaces filenames of shadow maps to use." provider variable subtype shadow default "" } parameter float __nonspecular { display hidden access output detail varying provider variable default 1 } parameter float __nondiffuse { access output display hidden detail varying provider variable default 1 } parameter string __shdname { access output display hidden detail uniform provider variable default "" } parameter string __category { description "Illuminance statements will be excuted only if those shaders match particular categories. Reload after any change." access output provider primitive detail uniform default "domelight" } RSLMain { output "point from = point \"shader\"(0,0,0);" output "vector axis = normalize(vector \"shader\"(0,0,1));" output "illuminate(from, axis, PI/2) {" indent generate output "__nondiffuse = 1 ;" output "__nonspecular = 1 ;" output "__shdname = [getvar shdname];" exdent output "}" } } template shadingmodel shd { parameter color SurfaceColor { label "Surface Color" detail varying default "0 .25 1" } parameter color SurfaceOpacity { label "Opacity" detail varying default "1 1 1" } collection shadingmodel shadingmodel { access output display hidden parameter color CI { detail varying default "0 .25 1" access output } parameter color OI { detail varying default "1 1 1" access output } } RSLFunction { void pxslshd(color SurfaceColor; color SurfaceOpacity; output color CI; output color OI; ) { extern point P; extern normal N; extern vector I; normal Nf = faceforward (normalize(N), I); normal Nn = normalize(N); color shd = 0; illuminance( P, Nf, PI ) { lightsource( "__inShadowC", shd ); } CI = SurfaceOpacity * (1 - shd); OI = SurfaceOpacity; } } } template light occamb { label "OccAmbient" lighttype ambient parameter color LightColor { detail varying default "1 1 1" } parameter float Intensity { subtype slider range {0 1} detail varying default 1 } parameter string occpass { label "occlusion data" subtype texture default "" } parameter string bentpass { label "bent normal data" subtype texture default "" } parameter string EnvMap { label "Environment Map" default {} subtype environment provider variable } parameter float weight { subtype slider range {0 1} default .75 detail uniform provider variable } parameter float blur { default .25 detail uniform provider variable } parameter float __nonspecular { access output provider primitive detail uniform display hidden default 1 } parameter float __nondiffuse { access output provider primitive detail uniform display hidden default 1 } RSLMain { output "uniform string occname=[getvar occpass];" output "uniform string bentname=[getvar bentpass];" output "uniform string envname=[getvar EnvMap];" output "point NDCP = transform (\"NDC\",Ps);" output "float NDCs = xcomp(NDCP);" output "float NDCt = ycomp(NDCP);" output "float occ=1;" output "color bentc=0;" output "color env=1;" output "vector bentv = 0;" output "if(occname!=\"\")" output "{" output "occ = texture(occname\[0\],NDCs,NDCt,\"swidth\", 1,\"twidth\", 1);" output "}" output "if(bentname!=\"\")" output "{" output "bentc = texture(bentname,NDCs,NDCt,\"swidth\", 1,\"twidth\", 1);" output "bentv = vector (bentc * 2 - color (1));" output "}" output "vector bentNormal = normalize(N);" output "bentNormal = normalize(bentNormal + bentv);" output "vector R = vtransform (\"_environment\",bentNormal);" output "R = normalize(R);" output "if(envname!=\"\")" output "{" output " env = environment (envname, R, \"blur\", [getvar blur]);" output "}" generate output "L = (0,0,0);" output "Cl = mix([getvar LightColor],env,[getvar weight])* [getvar Intensity]*occ;" } } } }