Original Post
first of all, yes i did try the search, that is how i have gotten this far. i have a basic ray tracer, and just added reflection and refraction. the reflection works great, but the refraction seems to leave little "ripples" on the surface if i use any color other than clear: http://hometown.aol.com/donate52/images/1.jpg http://hometown.aol.com/donate52/images/2.jpg in the first image, the sphere being reflected is behind the camera. in the second image, the blue sphere is transparent, and the red sphere is behind the blue sphere. you can see teh little "ripples" i'm talking about on there, but i cannot figure out what is causing that (it only happens with refraction). here is some of my code: any input/help/ideas at all are welcome, i've been at it for a while now and i have no idea where the problem is. thanks! [Edited by - Turo on October 12, 2004 1:27:34 AM]
//Returns reflect vector
//P = point if intersection, V = ray direction, N = surface normal
Point calcReflect(Point P, Point N, Point V) {
return P - N*2*(Dot(V, N));
}
//returns refract vector
//V = ray direction, N = surface normal, k = refraction value
Point calcTrans(Point V, Point N, double k) {
V = Normalize(V);
double NdV = Dot(N, V);
Point S = V - N*NdV;
if(NdV>0){ return S*k + N*sqrt(1 - k*k*Dot(S, S)); }
else{ return S*(1/k) - N*sqrt(1 - (1/(k*k))*Dot(S, S)); }
}
color trace(Ray R, int step) {
if(step > MAX_STEPS) { return BACKGROUND; }
color& local = color(0, 0, 0);
color& reflect = color(0, 0, 0);
color& trans = color(0, 0, 0);
double t = 100000;
double dist = 0;
int obj = 0;
for(int n=0; n<NUM_OBJ; n++) {
dist = world[n]->intersection(R);
if(dist>0 && dist<t) { t = dist; obj = n; }
}
t = world[obj]->intersection(R);
if(t>0) {
//Pi = Point of intersection
//Pnorm = Surface normal at Pi
Point Pi, Pnorm;
Pi.x = Round(R.getOrigin().x + R.getDirection().x*t, 3);
Pi.y = Round(R.getOrigin().y + R.getDirection().y*t, 3);
Pi.z = Round(R.getOrigin().z + R.getDirection().z*t, 3);
Pnorm = world[obj]->getSurfaceNormal(Pi);
Point Pref = calcReflect(Pi, Pnorm, R.getDirection());
Point Ptra = calcTrans(Pi, Pnorm, 1.666);
Ray Rref = Ray(Pi, Pref-Pi);
Ray Rtra = Ray(Pi, Ptra);
if(world[obj]->getShade() == LAMBERT) { local = lambert(Pi, obj); }
if(world[obj]->getShade() == PHONG) { local = phong(obj); }
if(world[obj]->isReflective()) { reflect = trace(Rref, step+1); }
if(world[obj]->isTransparent()) { trans = trace(Rtra, step+1); }
return (local+reflect+trans);
}
return BACKGROUND;
}