## ## float Cloth Slim template v. 1.1 ## 2003 © Alexander Krasovsky ## mail: kraz@krasovsky.net ## http://www.krasovsky.net ## slim 1 extensions pixardb { extensions pixar pxsl { template float Cloth { description {Mimics Maya cloth node} parameter float Freq { description "Frequency of cloth" default 4 detail varying } parameter float Thickness { description "Width Spread" default 0.4 detail varying } parameter float Flatness { description "creation method" subtype selector range { "Min" 0 "Max" 1 "Double" 2} default 0 } collection manifold Manifold { detail mustvary "pixar,ST" state locked description "By default, we use ST coordinates, however you might consider plugging in the Tile generator to test your resistance to the dreaded repetitive stress disorder." parameter point Q { detail mustvary } parameter vector duQ { detail mustvary } parameter vector dvQ { detail mustvary } } parameter float result { access output display hidden } RSLFunction { void pxslCloth( float freq; float thickness; float flatness; point Q; vector duQ; vector dvQ; output float result; ) { float surface_float, layer_float; float layer_opac, temp_opac; float a, b; float fuzz; float ss, tt; float thick; float row, col; float clampLow; float clampHi; varying float x, y; if (flatness) {clampLow = 0.2; clampHi = 0.7;} else {clampLow = 0.4; clampHi = 1;} thick = (clamp(thickness, clampLow, clampHi))/2; x = xcomp(Q); y = ycomp(Q); a = 0.5 - thick; b = 0.5 + thick; fuzz = (b - a) / 2; ss = mod(x * freq, 1); tt = mod(y * freq, 1); row = floor(((y) * (freq))); col = floor(((x) * (freq))); /* layer #1 */ if (flatness==2) layer_opac = smoothstep(a - fuzz, a, ss) - smoothstep(0.5 - clamp (fuzz/2, 0, 0.1), 0.5, ss) + smoothstep(0.5, 0.5 + clamp (fuzz/2, 0, 0.1), ss) - smoothstep(b, b + fuzz, ss); if (flatness==1) layer_opac = smoothstep(a - fuzz, a, ss) - smoothstep(b, b + fuzz, ss); if (flatness==0) layer_opac = smoothstep(a, a + fuzz, ss) - smoothstep(b - fuzz, b, ss); /* else layer_opac = smoothstep(a, a + fuzz, ss) - smoothstep(0.3, 0.3 + fuzz, ss) + smoothstep(0.7 - fuzz, 0.7, ss)- smoothstep(b - fuzz, b, ss); */ if (((mod((row), 2)== 0) && (mod((col), 2) ==0)) || ((mod((col), 2) ==1) && (mod((row), 2)== 1))) {layer_float = 2*pow((tt-0.5), 2);} else layer_float = 1 - (2*pow((tt-0.5), 2)); surface_float = layer_opac - (layer_opac*layer_float); /* layer #2 */ if (flatness==2) layer_opac = smoothstep(a - fuzz, a, tt) - smoothstep(0.5 - clamp (fuzz/2, 0, 0.1), 0.5, tt) + smoothstep(0.5, 0.5 + clamp (fuzz/2, 0, 0.1), tt) - smoothstep(b, b + fuzz, tt); if (flatness==1) layer_opac = smoothstep(a - fuzz, a, tt) - smoothstep(b, b + fuzz, tt); if (flatness==0) layer_opac = smoothstep(a, a + fuzz, tt) - smoothstep(b - fuzz, b, tt); if (((mod((col), 2)== 0) && (mod((row), 2) ==1)) || ((mod((row), 2) ==0) && (mod((col), 2)== 1))) {layer_float = 2*pow((ss-0.5), 2);} else layer_float = 1 - (2*pow((ss-0.5), 2)); layer_float = layer_opac - (layer_opac*layer_float); surface_float = max (surface_float, layer_float); result = surface_float; } } } } }