0

OpenGLを使用せずにc/c++で球体レイトレーサーを作成する必要があります。gl関数を使用せずに、シーンに球やライトを配置する方法については混乱しています。誰かがこれを行う方法を説明できますか?

4

1 に答える 1

1

レイトレーシングはopenglとは何の関係もありません。卓上電卓でできます。

ポイントは、基本的に 3 つの浮動小数点変数であるベクトルで行われる純粋なジオメトリであるということです。(または整数)。

カメラを原点に「配置」します: ox=0, oy=0, oz=0.

球を 5 "メートル" または単位で z 軸に "置きます": sx=0,sy=0,sz=5;

z 軸に向かって 90 度の視野で光線をキャストし始めます。

for (i=-1;i<1; i+=0.01) {
   for (j=-1;j<1; j+=0.01) {
       dx=i; dy=j;dz=1;  // perhaps you then need to normalize the "vector" dx,dy,dz
       // check if the ray hits the sphere with radius 2.3 (located at 0,0,5)

       // if it does, calculate the angle of the normal of the hit point and
       // the light source at position lx=1,ly=-0.5;lz=-2.33;

       // if normal dot lightray is positive, calculate angle, apply Phong model

       // add lambertian model, distance attenuation, fog, texturemapping

  }
 }

最後に、〜 200 x 200 の画像のピクセル強度または色の値を計算しました。この例では、90 度の FoV を使用しています。

于 2012-11-06T19:22:28.663 に答える