Ray Trace Refraction看起来"虚假"

use*_*952 3 3d graphics transparency raytracing aero-glass

所以在我的光线追踪器中,我正在建造我已经得到了折射以适应球体以及腐蚀效果,但玻璃球看起来并不是特别好.我相信折射数学是正确的,因为光看起来是弯曲的,以你想象的方式反转,但它看起来不像玻璃,它看起来像纸或什么的.

我已经读到全部内部反射是导致玻璃看起来像是什么的原因所在,但是当我测试看我的折射光线是否超过临界角时,它们都没有,所以我的玻璃球没有全内反射.我不确定这是否正常或者我做错了什么.我已经在下面发布了我的折射码,所以如果有人有任何建议,我很乐意听到它们.

/*
 * 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
}
Run Code Online (Sandbox Code Playgroud)

在我的主光线跟踪方法RayTrace()中调用此方法,该方法以递归方式运行.以下是负责折射的一小部分:

    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.
    } 
Run Code Online (Sandbox Code Playgroud)

Ilm*_*nen 5

你是对的,你永远不会在球体中得到全内反射(从外面看).这是因为对称性:球体内部的光线将在两端以相同的角度撞击表面,这意味着,如果它超过一端的临界角,那么它也必须超过另一端的角度(等等)从一开始就无法从外面进入球体).

但是,根据菲涅耳定律,你仍会得到很多部分反思.它看起来不像你的代码,这可能是你的玻璃看起来像假的原因.尝试包括它,看看它是否有帮助.

(是的,这意味着当你的光线到达折射表面时,你的光线会分成两部分.这实际上发生了,所以你只需要忍受它.你可以追踪两条路径,或者,如果你使用的是无论如何,随机射线追踪算法,只需用适当的权重随机抽样其中一个.)

PS.如果您不想处理光偏振等问题,您可能只想使用Schlick对Fresnel方程的近似.