Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!wuarchive!udel!rochester!kodak!uupsi!pixar!markv From: markv@pixar.com (Mark VandeWettering) Newsgroups: comp.graphics Subject: Re: How do YOU compute refraction vectors? Message-ID: <1991May22.181534.219@pixar.com> Date: 22 May 91 18:15:34 GMT References: <9105210459.AA01904@enuxha.eas.asu.edu> Sender: news@pixar.com (Usenet Newsmaster) Organization: Pixar -- Point Richmond, California Lines: 51 Nntp-Posting-Host: woody In article <9105210459.AA01904@enuxha.eas.asu.edu> hollasch@enuxha.eas.asu.edu (Steve Hollasch) writes: > > About a month ago I posted a request for a reference on the particular >refraction equation I used, but no one responded. Could have been >disinterest, but perhaps there are people who haven't heard of it, >either. _ _ > P1 | | > The equation I use is R = (D.N)N + -- | D - (D.N)N |, where P1 is the > P2 |_ _| > >index of refraction of the material containing the ray origin, P2 is >the index of refraction of the intersected object, N is the surface >normal, and D is the ray direction vector TOWARDS the surface. Note that >the resulting vector is NOT a unit vector. Whenever I need a refraction formula, I refer back to Heckbert's way of calculating it. He did a study of how to compute this and wrote up a small paper that was reproduced in some Siggraph course notes which I could not find immediately. The code for it is reproduced in the simple framework that he has in "Intro to Ray Tracing" by Glassner. For those of you who just want the answer.... /* this slightly differs from his code in the book, but is (in principle) * the same */ TransmissionDirection(m1, m2, I, N, T) double m1, m2 ; /* the index of refraction */ Vector3 I, N, T ; /* incoming, normal and Transmitted */ { double eta, c1, cs2 ; eta = n1 / n2 ; c1 = -VecDot(I, N) ; cs2 = 1 - eta * eta * (1 - c1 * c1) ; if (cs2 < 0) return 0 ; /* total internal reflection */ /* * VecComb(a, v1, b, v2, v3) * computes v3 = a * v1 + b * v2, * where a & b are scalars, and v1, v2, v3 are vectors */ VecComb(eta, I, eta * c1 - sqrt(cs2), N, T) ; return 1 ; } Hope this helps mark