Shaders
colornoise shader
/*-______________________________________________________________________
**
** colornoise shader... dsward@webnation.com
** VIDI Presenter 3D Repository - http://www.webnation.com
**
** offsetX, offsetY, offsetZ = offset in the noise lattice
** scaleX, scaleY, scaleZ = scale in the noise lattice
** scaleRed, scaleGreen, scaleBlue = color channel maximums
**
** shadingType = 0=constant, 1=constant, 2=plastic, 3=matte, 4=glow, 5=halo
** Ks, Kd, Ka, roughness, specularcolor - the usual meanings
** ______________________________________________________________________
*/
surface
colornoise (float noiseType = 3,
offsetX = 0.0,
offsetY = 0.0,
offsetZ = 0.0,
scaleX = 1.0,
scaleY = 1.0,
scaleZ = 1.0,
scaleRed = 1.0,
scaleGreen = 1.0,
scaleBlue = 1.0,
shadingType = 0,
Ks = 0.5,
Kd = 0.5,
Ka = 1.0,
roughness= 0.1,
attenuation = 2;
color specularcolor = 1;)
{
point Nf, V;
point NN, II;
float falloff;
point noiseAt;
color noisy = 0;
if (noiseType <= 0) noiseAt = (t, 0, 0);
if (noiseType == 1) noiseAt = (s, 0, 0);
if (noiseType == 2) noiseAt = (s, t, 0);
if (noiseType >= 3) noiseAt = transform("object", P);
setxcomp(noiseAt, (xcomp(noiseAt) + offsetX) * scaleX);
setycomp(noiseAt, (ycomp(noiseAt) + offsetY) * scaleY);
setzcomp(noiseAt, (zcomp(noiseAt) + offsetZ) * scaleZ);
noisy = color noise (noiseAt);
setcomp(noisy, 0, comp(noisy, 0) * scaleRed);
setcomp(noisy, 1, comp(noisy, 1) * scaleGreen);
setcomp(noisy, 2, comp(noisy, 2) * scaleBlue);
if (shadingType == 0)
{
/* constant */
Oi = 1;
Ci = noisy;
}
if (shadingType == 1)
{
/* constant */
Oi = Os;
Ci = Os * noisy;
}
if (shadingType == 2)
{
/* plastic shading */
Nf = faceforward( normalize(N), I );
V = -normalize(I);
Oi = Os;
Ci = Os * ( noisy * (Ka*ambient() + Kd*diffuse(Nf)) +
specularcolor * Ks * specular(Nf, V, roughness) );
}
if (shadingType == 3)
{
/* matte shading */
Nf = faceforward(normalize(N),I);
Oi = Os;
Ci = Os * noisy * ( 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 = noisy * falloff;
Oi = 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 = noisy * falloff;
Oi = falloff;
}
else
{
Oi = 0;
}
}
}
Copyright © 1997 by
WebNation
All trademarks are the property of their respective holders