Note that there are some explanatory texts on larger screens.

plurals
  1. PORay Trace Refraction looks "fake"
    text
    copied!<p>So in my ray tracer that I'm building I've gotten refraction to work for spheres along with caustic effects, however the glass spheres don't look particularly good. I believe the refracted math is correct because the light appears to be bending in inverting the way you'd expect it to however it doesn't look like glass, it just looks like paper or something.</p> <p>I've read that total internal reflection is responsible for much of what makes glass look like it does, however when I tested to see if any of my refracted rays go above the critical angle, none of them do, so my glass sphere has no total internal reflection. I'm not sure if this is normal or if I've done something wrong. I've posted my refraction code below so if anyone has any suggestions I'd love to hear them. </p> <pre><code>/* * Parameter 'dir' lets you know whether the ray is starting * from outside the sphere going in (0) or from in the sphere * going back out (1). */ void Ray::Refract(Intersection *hit, int dir) { float n1, n2; if(dir == 0){ n1 = 1.0; n2 = hit-&gt;mat-&gt;GetRefract(); } if(dir == 1){ n1 = hit-&gt;mat-&gt;GetRefract(); n2 = 1.0; } STVector3 N = hit-&gt;normal/hit-&gt;normal.Length(); if(dir == 1) N = -N; STVector3 V = D/D.Length(); double c1 = -STVector3::Dot(N, V); double n = n1/n2; double c2 = sqrt(1.0f - (n*n)*(1.0f - (c1*c1))); STVector3 Rr = (n * V) + (n * c1 - c2) * N; /*These are the parameters of the current ray being updated*/ E = hit-&gt;point; //Starting point D = Rr; //Direction } </code></pre> <p>This method is called during my main ray-tracing method RayTrace() which runs recursively. Here's a small section of it below that is in charge of refraction:</p> <pre><code> if (hit-&gt;mat-&gt;IsRefractive()) { temp.Refract(hit, dir); //Temp is my ray that is being refracted dir++; result += RayTrace(temp, dir); //Result is the return RGB value. } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload