Shaders
colorramp - A six-color ramp shader
/* colorramp.sl shader - dsward@webnation.com
This shader cycles through a table of colors to produce color shift effects:
colorScale - the scale, larger values increases the cycle length
colorOffset - vary this parameter to move the colors
typically 0 to 1 for a full cycle
mapType - 0=x, 1=y, 2=z, 3=s, 4=t
shadingType = 0=constant, 1=constant, 2=plastic, 3=matte, 4=glow, 5=halo
color1-color6 - the sequence of colors to shift through
Ks, Kd, Ka, roughness, specularcolor - the usual meanings
*/
surface
colorramp (
float colorScale = 1;
float colorOffset = 0;
float mapType = 0;
float shadingType = 0;
color color1 = color(0, 0, 1);
color color2 = color(0, 1, 1);
color color3 = color(0, 1, 0);
color color4 = color(1, 1, 0);
color color5 = color(1, 0, 0);
color color6 = color(1, 0, 1);
color opacity1 = color(1, 1, 1);
color opacity2 = color(1, 1, 1);
color opacity3 = color(1, 1, 1);
color opacity4 = color(1, 1, 1);
color opacity5 = color(1, 1, 1);
color opacity6 = color(1, 1, 1);
float Ks = 0.5, Kd = 0.5, Ka=1, roughness= 0.1, attenuation = 2;
color specularcolor=1;
)
{
float cmap;
point PP;
color interpColor;
color interpOpacity;
point Nf, V;
point NN, II;
float falloff;
PP = transform ("shader", P);
cmap = xcomp(PP);
if (mapType == 1) cmap = ycomp(PP);
if (mapType == 2) cmap = zcomp(PP);
if (mapType == 3) cmap = s;
if (mapType == 4) cmap = t;
cmap *= colorScale;
cmap += colorOffset;
cmap = mod(cmap, 1);
interpColor = color spline (cmap,
color1, color1, color2, color3, color4, color5, color6, color1, color1);
interpOpacity = color spline (cmap,
opacity1, opacity1, opacity2, opacity3, opacity4, opacity5, opacity6, opacity1, opacity1);
if (shadingType == 0)
{
/* constant */
Oi = interpOpacity;
Ci = interpColor * interpOpacity;
}
if (shadingType == 1)
{
/* no show-through */
Oi = interpOpacity;
Ci = interpColor;
}
if (shadingType == 2)
{
/* plastic shading */
Nf = faceforward( normalize(N), I );
V = -normalize(I);
Ci = interpOpacity * ( interpColor * (Ka*ambient() + Kd*diffuse(Nf)) +
specularcolor * Ks * specular(Nf, V, roughness) );
}
if (shadingType == 3)
{
/* matte shading */
Nf = faceforward(normalize(N),I);
Ci = interpOpacity * interpColor * ( Ka*ambient() + Kd * diffuse(Nf) ) ;
}
if (shadingType == 4)
{
/* glow shading */
NN = normalize(N);
II = normalize(I);
falloff = II.NN; /* Direct incidence has cosine closer to 1.*/
if (falloff < 0)
{ /* Back of sphere only */
/* Normalize falloff by lengths of I and N */
falloff = falloff * falloff / (II.II * NN.NN) ;
falloff = pow(falloff, attenuation);
Ci = interpColor * interpOpacity * falloff;
Oi = interpOpacity * falloff;
}
else
{
Oi = 0;
}
}
if (shadingType == 5)
{
/* halo shading */
NN = normalize(N);
II = normalize(I);
falloff = II.NN; /* Direct incidence has cosine closer to 1.*/
if (falloff < 0)
{ /* Back of sphere only */
/* Normalize falloff by lengths of I and N */
falloff = falloff * falloff / (II.II * NN.NN) ;
falloff = 1 - falloff;
falloff = pow(falloff, attenuation);
Ci = interpColor * interpOpacity * falloff;
Oi = interpOpacity * falloff;
}
else
{
Oi = 0;
}
}
}