1

現在、レイ トレーサー、反射部分の作業を行っています。影のある球を作成するなど、すべてが正しく機能しています。今、私は反射部分を実装しています。しかし、私はそれを得ることができませんでした。私のアルゴリズムは以下の通りです:

traceRay(Ray ray, int counter){
// look through the intersection between ray and list of objects
// find the final index aka the winning index, (if final index == -1, return background color)
// then calculate the intersection point

// perform reflection calculation here
if(counter > 1  && winning object's reflectivity > 1 ){
  //get the intersection normal, vector N
  //Calculate the reflection ray, R
  // let I is the inverse of direction of incoming ray
  //Calculate R = 2aN - I (a = N dotProduct I)

  // the reflection ray is origin at the point of intersection between incoming ray and sphere with the R direction
  Ray reflecRay (intersection_poisition, R);

  Color reflection = traceRay(reflecRay, counter + 1);
  // multiply by fraction ks
  reflection = reflection * ks;
}


// the color of the sphere calculated using phong formula in shadeRay function
Color prefinal = shadeRay();


// return the total color of prefinal + reflection

}

反射を取得しようとしましたが、取得できませんでした。traceRay 関数のアルゴリズムが正しいかどうか誰か教えてください。

4

1 に答える 1

4

レイを反射するときは、リフレクター自体との交差を避けるために、リフレクターの法線に沿って光線を移動する必要があります。例えば:

 const double ERR = 1e-12;
 Ray reflecRay (intersection_poisition + normal*ERR, R);
于 2014-03-05T07:39:36.553 に答える