2007년 11월 17일 토요일

slBox 사용 예제


젤리느낌을 표현

vector In = normalize(I);
normal Nn = normalize(N);

/* calculate reflection on outer displaced surface */
vector reflDir = normalize(reflect(In, Nn));
vector reflDirWorld = vtransform("world", reflDir);
color Crefl = environment("C:/rmantex/ratEnv.tex", reflDirWorld);
/* make reflection monochromatic and push up darks to make it flatter */
Crefl = pow(0.35 * comp(Crefl, 0) + 0.5 * comp(Crefl, 1) + 0.15 * comp(Crefl, 2), 0.3);
/* finally tint the reflection */
Crefl = reflTintColor * Crefl;

/* trace against the undisplaced torus and find the intersection point and normal */
point Phit;
normal Nhit;
float maxLen = 3.0;
float rayLen = maxLen;
color CDiffuse = color(0, 0, 0);
vector refrDir = normalize(refract(In, Nn, eta));
point traceP = P - 0.1 * refrDir;
gather("illuminance", traceP, refrDir, 0, 1, "hitsides", "front", "primitive:P", Phit, "primitive:N", Nhit, "ray:length", rayLen) {
CDiffuse = diffuse(normalize(Nhit));
} else {
/* incase we don't hit the front of the torus try hitting the back side.
this would happen if we essentially just go through water this is
why we set diffuse to black */
gather("illuminance", traceP, refrDir, 0, 1, "hitsides", "back", "primitive:P", Phit, "primitive:N", Nhit, "ray:length", rayLen) {
CDiffuse = color(0, 0, 0);
}
}
/* calculate depth tinting using Bier's law */
rayLen = max(0.0001, rayLen);
rayLen = min(maxLen, rayLen);
color liquidTint = color(1 - pow(comp(depthTintColor, 0), 1/rayLen),
1 - pow(comp(depthTintColor, 1), 1/rayLen),
1 - pow(comp(depthTintColor, 2), 1/rayLen));

/* color */
/* fresnel effect leads to more reflection at grazing angles and more
refraction looking straight on. However, we modulate its effect
by blending in constant amounts of both */
float Kr = 1;
float Kt = 1 - Kr;
fresnel(In, Nn, eta, Kr, Kt);
Kr = 0.25 + 0.75*Kr;
Kt = 0.35 + 0.65*Kt;

/* our diffuse and ambient terms are treated as refraction result those are
depth tinted as well */

result_c = Kr * Crefl + liquidTint * Kt * (Kd * CDiffuse + Ka) * surfaceColor;
/* vector */
result_o = (1,1,1);

댓글 없음: