00001 #define blend(a,b,x) ((a) * (1 - (x)) + (b) * (x))
00002 #define whichtile(x,freq) (floor((x) * (freq)))
00003 #define repeat(x,freq) (mod((x) * (freq), 1.0))
00004
00005
00006
00007 #include "arman/noises.h"
00008
00009 surface soapBubble(float Kd =.2;
00010 float Ka = .1;
00011 float Ks = .3;
00012 float Kr=.45, rimWidth = .3;
00013 float iridescence=1;
00014 float roughness = .001;
00015 color specularColor = .7;
00016 float transparencyGain=.35;
00017
00018 float reflmapGain=1.;
00019 float reflmapGamma=1.;
00020 float rainbowGain=1.;
00021 float rainbowGamma=1.;
00022 float colorNoiseFrequency=2.8;
00023 string reflectionEnv="";
00024
00025 )
00026 {
00027 normal Nf, n;
00028 n = normalize(N);
00029 Nf = faceforward(n, I);
00030 vector i = normalize(-I);
00031 point PP = transform ("shader", P);
00032 PP*=colorNoiseFrequency*vfBm(PP/.3*PI, 4.5, 2, 0.05, 0.5);
00033 color rainbowColor=((color(noise(2*PI*PP) - .5)) + .5);
00034
00035
00036 vector Rcurrent= reflect(I,Nf);
00037 vector Rworld=vtransform("world", Rcurrent);
00038 color Cr=color environment(reflectionEnv, Rworld);
00039 Cr = color( reflmapGain*pow(Cr[0], 1/reflmapGamma ), reflmapGain*pow(Cr[1], 1/reflmapGamma ), reflmapGain*pow(Cr[2], 1/reflmapGamma ));
00040
00041 float dot = 1 - i.Nf;
00042
00043 float iridescence1=iridescence*pow( blend(rimWidth*1.1, .9, smoothstep(0,1, dot)), 1/rainbowGamma);
00044
00045 Oi =transparencyGain*blend(rimWidth, 1, smoothstep(0,1, dot));
00046
00047 Ci = rainbowColor* rainbowGain*iridescence1 * (Ka * ambient() + Kd * diffuse (Nf) + specularColor * Ks * specular (Nf, i, roughness)) + Kr * Cr;
00048 Ci*=Oi;
00049 }