光线追踪 - 反思

问题描述 投票:1回答: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函数的算法是正确的?

c++ raytracing phong
1个回答
3
投票

反射光线时,需要沿反射镜的法线移动光线,以避免与反射镜本身相交。例如:

 const double ERR = 1e-12;
 Ray reflecRay (intersection_poisition + normal*ERR, R);
最新问题
© www.soinside.com 2019 - 2025. All rights reserved.