danielepanozzo / cg-old

44 stars 16 forks source link

1.6 how to implement reflections #84

Closed peiyueY closed 5 years ago

peiyueY commented 5 years ago

Hi, I have two questions about reflections part.

The first one is that I'm not sure whether my steps of reflection part is correct because it seems too complicate and needs to for loop all triangles too many times. I generate ray from each pixel hit the mirror floor to get the floor_intersection and r. Then use floor_intersection and r to get the triangle_intersection. Finally calculate C of triangle_intersection.

Secondly, I don't quite understand the equation c = c + km * raycolor(p + sr). The c in the left hand is the final color C we need I assume. What's the c in the right hand? What is the range of km? And What is raycolor, is it the C of triangle_intersection I mentioned above?

Thanks in advance!

danielepanozzo commented 5 years ago
  1. After you compute the intersection between the ray and an object, if the object is a mirror, you compute the new ray and redo the procedure from the beginning, i.e. you consider the mirror the source of the ray. After every bounce, you will have to recheck ray intersections with the entire scene, so yes it is computationally expensive.

  2. You can optionally add a constant color (c) or a multiplicative constant (km) to customize the appearance of the reflective surface. For a perfect mirror, c = 0 and km = 1

peiyueY commented 5 years ago

Is it normal and correct that I set the mirror floor as z = -1, use perspective projection and then the reflections are both black? According to my understanding, the reflections are black is because the light_position is (-1, 1, 1) and the mirror is below the light and objects, there is no light contribution for the underneath of objects.

Thanks

danielepanozzo commented 5 years ago

If you put the mirror between the camera and your objects (I think this is what you'd described above?) it is likely that it will be all black, since the rays will be reflected back and not hit any object. You should place the mirror below the spheres, so that some of the rays reflected from the mirror will hit the spheres.