因此,在我正在建造的射線追蹤器中,我已經獲得折射以便與球體效應一起工作,但玻璃球體看起來並不特別好。我相信被折射的數學是正確的,因爲光看起來是按照你期望的方式反轉,但它看起來不像玻璃,它看起來像紙或其他東西。射線痕跡折射看起來「假」
我已經讀過全內反射是造成玻璃看起來像它的大部分原因,然而當我測試了我的折射光線是否超出臨界角度時,它們都沒有,所以我的玻璃球沒有全內反射。我不確定這是否正常,或者我做錯了什麼。我已經在下面張貼了我的折射代碼,所以如果有人有任何建議,我很樂意聽到他們。
/*
* 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->mat->GetRefract(); }
if(dir == 1){ n1 = hit->mat->GetRefract(); n2 = 1.0; }
STVector3 N = hit->normal/hit->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->point; //Starting point
D = Rr; //Direction
}
我的主要射線追蹤法光線追跡()它運行遞歸過程中,此方法被調用。下面是它的一小部分低於負責折射:
if (hit->mat->IsRefractive())
{
temp.Refract(hit, dir); //Temp is my ray that is being refracted
dir++;
result += RayTrace(temp, dir); //Result is the return RGB value.
}
謝謝!我嘗試實施施裏克的逼近,我仍然有錯誤,但即使如此,我的球體看起來更像玻璃! =) – user1855952