4
$\begingroup$

Are mirror-like reflections in computer graphics purely handled with ray-tracing/ray-casting techniques or are there some situations where they are achieved through rasterisation?

example of raytraced reflection on a sphere

$\endgroup$
  • 1
    $\begingroup$ I think that user18490 answered the question quite well, but just in case you would like to see some actual examples, here are two tutorials that do reflection without ray casting or ray tracing. They used OpenGL for it. youtube.com/watch?v=GADTasvDOX4 and youtube.com/watch?v=xutvBtrG23A basically one renders the reflection out through a camera that is positioned mirror like and the other uses cube maps for reflections. Cube maps can be rendered out for every frame to be able to get reflections of the actual dynamic scene. Hope that helped a bit! $\endgroup$ – bram0101 Jan 20 '17 at 16:07
10
$\begingroup$

There are a couple of special cases where mirror-like reflections can be rendered efficiently using rasterization techniques, and these are commonly used in games, although they don't work for the general case.

Planar reflections

If the reflecting surface is flat or reasonably close to flat, the reflected image can be rasterized in an separate rendering pass, by applying a reflection transform and clip plane to the scene. The reflection is then composited into the final image using a shader (or, in older games, stencil buffer masking). Also, a small amount of distortion or blurring might be applied to the image if the reflecting surface isn't intended to appear perfectly flat and smooth.

This is very commonly used in games for water reflection in lakes or the ocean, as long as any waves aren't too large. This page from the UE4 docs shows a number of examples of planar reflections used for water. The same technique is also often used for mirror reflections in glossy floors, or for actual mirrors.

The main strength of planar reflection is that it automatically gives you correct perspective and occlusion in the reflected image. The main limitation, aside from being limited to planar surfaces, is the performance cost of rendering an extra copy of the scene (with full lighting, etc) for each reflection plane. For instance, having multiple water surfaces at different elevations (e.g. in a boat lock) would require another rendering pass for each elevation. For this reason, usually when planar reflections are used, they're set up in such a way that only one reflection plane is visible at a time.

Cubemap reflections

Another special case is when the reflecting object is reasonably small and, ideally, not too close to other objects around it. In that case, you can approximate reflections by rasterizing a cubemap around the object. Then it can be used as an environment map during shading, by sampling the cubemap along the reflection vector calculated in the shader.

Many games use pre-rendered cubemaps to render static environment reflections on characters and dynamic objects; somewhat less commonly, you can also dynamically re-render a cubemap every frame to get dynamic reflections of other objects. This might be used on the cars in a racing game, for instance.

The advantage of cubemap reflections is that they can be applied to any shape of object, not just planar ones. However, since the cubemap is rendered from a single point, the reflections have increasingly incorrect perspective and occlusion the farther you get from that point. This can be partly addressed by parallax correction, and by blending between multiple cubemaps based on location, but ultimately cubemaps just don't give you the accuracy of either planar reflections or raytracing. Moreover, re-rendering a dynamic cubemap every frame is quite expensive, as it requires 6 extra rendering passes (one for each face of the cube).

Hybrid techniques

There are also cases where rasterization is used to build an initial data structure for ray tracing / casting to traverse into.

  • Screen-space reflection can be understood this way, as it involves first rendering the screen using ordinary rasterization techniques, then treating the Z-buffer as a heightfield and marching rays through it.
  • Voxel cone tracing is a similar case, where the scene is voxelized using rasterization, and then rays can be marched through the voxel grid. This perhaps doesn't qualify as "mirror-like" reflections since in practice the voxel grid isn't high-resolution enough for that, but it could be done in principle.

So yes, depending on what degree of approximation you can accept and what constraints you can work within, there are quite a few cases where mirror-like reflections can be achieved using rasterization, or hybrid rasterization/raytracing techniques.

$\endgroup$
  • $\begingroup$ But you miss the fondamental point to some extent. Cube maps/planar reflections are not accurate nor are most of the "tricks" that are used with rasterisation to mimic reflections/refractions. The point is you can compute true reflections/refractions using rasterisation, not fake ones. You can use a technique similar to radiosity cube maps for instance, and I believe that's what the OP needs to know. $\endgroup$ – user18490 Jan 20 '17 at 21:48
  • 2
    $\begingroup$ @user18490 You seem to be taking a very narrow interpretation of the question, focusing purely on whether perfect reflections are theoretically possible, regardless of practicality. I'm coming at it from a different angle: techniques useful in production real-time graphics. $\endgroup$ – Nathan Reed Jan 20 '17 at 23:22
  • $\begingroup$ ]-) yes because i think this is what the OP wants to know. But I think your answer is complementary so it's good. The question is whether you can computer "accurate" reflection/refractions with a given algorithm. I would say that if it's not possible with a given visibility algorithm, unless you fake it (aka reflection look like reflections but are not correct geometrically, physically) then I would say this algorithm can not handle things such as reflection/refractions, which is the OP's questions. $\endgroup$ – user18490 Jan 22 '17 at 9:32
3
$\begingroup$

You can mimic a mirror by masking out the visible reflective surface when you first render and then mirror the world around the reflective plane and render again while only drawing where the reflective surface was.

There are some other details to worry about like not drawing stuff on the far side of the mirror when drawing the mirrored world which can be done with a second depth test (only draw stuff farther away from the camera than the mirror).

This works very well for flat mirrors, when you add curves things get a lot more complicated.

$\endgroup$
  • $\begingroup$ This is only one technique though among others. But the question is more fondamental. The fact is you can also use rasterisation to "solve" for visibility between a shaded point and the rest of the scene for reflection "rays" if you really want to. This is highly ineffective but possible. So as the OP said in his comment "they are not exclusive". $\endgroup$ – user18490 Jan 20 '17 at 18:02
3
$\begingroup$

This is one of the most common "misconceptions" on rendering, rasterisation and ray-tracing. Don't get me wrong. This is a good question, but one that should be answered once and for all.

So to answer your question:

1) it is much easier to simulate reflection and refraction with ray-tracing than with rasterisation, which is often why when you see an image produced with a ray-tracer you see spheres reflecting each other.

2) the misconception (even among people working in the CG business) is that you can NOT produce reflection or refraction with rasterisation. In fact, you can.

Generally, ray-tracing/rasterisation have nothing to do with reflection or refraction or whatever else. These are two ways of solving a single problem which is to find out (in short) if two points in space are visible to each other (the visibility problem). Ray-tracing solves this problem in one way, rasterisation in an other. Rasterisation is very efficient at solving this problem from primary rays (or camera rays) and less efficient to solve this problem for secondary rays (reflection, refraction, shadows, etc.) than ray-tracing. Ray-tracing is slower than rasterisation for primary rays but offers a simpler solution for secondary rays compared to rasterisation. Yet ray-tracing is not good for solving problems like caustics, so this is far from being a solution to every problem in computer graphics. Yet rasterisation can be used (different techniques exist) to simulate reflections and refractions.

I am sorry to repeat myself here but there are resources on the web that explain this well. I am tired of promoting the same ones all the time but Google ray-tracing vs rasterisation (I have just done it) and you will stumble upon a couple of good ones. You now just need to make the effort to read.

$\endgroup$
  • $\begingroup$ Thank you, I do understand the difference between the two and I understand how they both work, I was just curious as to whether such a thing was exclusive $\endgroup$ – Will D Jan 20 '17 at 16:00
  • $\begingroup$ So it's not))) now I hope you know. $\endgroup$ – user18490 Jan 20 '17 at 16:00
  • $\begingroup$ If they are useful and relevant to the question, feel free to include specific links. It's only link only answers that are problematic. $\endgroup$ – trichoplax Jan 21 '17 at 11:15
  • $\begingroup$ I think these 2 links to scratchapixel tutorials will be good on learning about the differences about Rasterization and Ray Tracing. scratchapixel.com/lessons/3d-basic-rendering/… scratchapixel.com/lessons/3d-basic-rendering/… $\endgroup$ – Arjan Singh Jan 21 '17 at 13:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.