<p>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.</p>

<p>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). </p>

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

CC BY-SA 3.0
2017-01-20T18:02:48.117Z
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".
user18490
CC BY-SA 3.0
2017-01-20T16:46:45.810Z
2017-01-20T16:46:45.810Z
ratchet freak
<p>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. </p>

<p>So to answer your question:</p>

<p>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.</p>

<p>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.</p>

<p>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.</p>

<p>I am sorry to repeat myself <a href="https://computergraphics.stackexchange.com/questions/4573/refraction-in-a-ray-tracer">here</a> but there are resources on the web that explain this well. I am tired of promoting the same ones all the time but Google <code>ray-tracing vs rasterisation</code> (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.</p>

CC BY-SA 3.0
2017-01-20T16:00:09.673Z
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
Will D
CC BY-SA 3.0
2017-01-20T16:00:35.163Z
So it's not))) now I hope you know.
user18490
CC BY-SA 3.0
2017-01-21T11:15:37.290Z
If they are useful and relevant to the question, feel free to include specific links. It's only [link only answers](http://meta.stackexchange.com/a/8259/258647) that are problematic.
trichoplax is on Codidact now
CC BY-SA 3.0
2017-01-21T13:22:33.673Z
I think these 2 links to scratchapixel tutorials will be good on learning about the differences about Rasterization and Ray Tracing. https://www.scratchapixel.com/lessons/3d-basic-rendering/rasterization-practical-implementation https://www.scratchapixel.com/lessons/3d-basic-rendering/ray-tracing-overview
Arjan Singh
CC BY-SA 3.0
2017-01-20T15:57:10.400Z
2017-01-21T10:53:32.483Z
2017-04-13T13:00:43.660Z
user18490
<p>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.</p>

<h3>Planar reflections</h3>

<p>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.</p>

<p>This is very commonly used in games for water reflection in lakes or the ocean, as long as any waves aren't too large. <a href="https://docs.unrealengine.com/latest/INT/Engine/Rendering/LightingAndShadows/PlanarReflections/">This page from the UE4 docs</a> 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 <a href="https://i.sstatic.net/KgrG1.png">actual mirrors</a>.</p>

<p>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.</p>

<h3>Cubemap reflections</h3>

<p>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.</p>

<p>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.</p>

<p>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 <a href="https://seblagarde.wordpress.com/2012/09/29/image-based-lighting-approaches-and-parallax-corrected-cubemap/">parallax correction</a>, 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).</p>

<h3>Hybrid techniques</h3>

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

<ul>
<li>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. </li>
<li>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.</li>
</ul>

<p>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.</p>

CC BY-SA 3.0
2017-01-20T21:48:12.960Z
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.
user18490
CC BY-SA 3.0
2017-01-20T23:22:04.947Z
@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.
Nathan Reed
CC BY-SA 3.0
2017-01-22T09:32:51.783Z
]-) 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.
user18490
CC BY-SA 3.0
2017-01-20T20:36:32.873Z
2017-01-20T20:36:32.873Z
Nathan Reed
<p>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?</p>

<p><img src="https://i.sstatic.net/IYlur.jpg" alt="example of raytraced reflection on a sphere"></p>

CC BY-SA 3.0
2017-01-20T16:07:00.340Z
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.   https://www.youtube.com/watch?v=GADTasvDOX4     and    https://www.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!
bram0101
<raytracing><rasterizer><reflection>
Mirror Reflections: Ray Tracing or Rasterisation?
Will D
# Mirror Reflections: Ray Tracing or Rasterisation?

(Asked by: username_0 on 2017-01-20)

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](https://i.sstatic.net/IYlur.jpg)

**Tags:** raytracing, rasterizer, reflection

> **Comments:**
> **username_1**: I think that username_3 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.   https://www.youtube.com/watch?v=GADTasvDOX4     and    https://www.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!  

---

## 3 answers

### Answer by username_6 on 2017-01-20. Score: 12 | Accepted answer

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](https://docs.unrealengine.com/latest/INT/Engine/Rendering/LightingAndShadows/PlanarReflections/) 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](https://i.sstatic.net/KgrG1.png).

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](https://seblagarde.wordpress.com/2012/09/29/image-based-lighting-approaches-and-parallax-corrected-cubemap/), 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.

> **Comments:**
> **username_3**: 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.  
> **username_6**: @username_3 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.  
> **username_3**: ]-) 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.  

---

### Answer by username_2 on 2017-01-20. Score: 3

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.

> **Comments:**
> **username_3**: 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".  

---

### Answer by username_3 on 2017-01-20. Score: 3

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](https://computergraphics.stackexchange.com/questions/4573/refraction-in-a-ray-tracer) 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 username_0 stumble upon a couple of good ones. You now just need to make the effort to read.

> **Comments:**
> **username_0**: 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  
> **username_3**: So it's not))) now I hope you know.  
> **username_4**: If they are useful and relevant to the question, feel free to include specific links. It's only [link only answers](http://meta.stackexchange.com/a/8259/258647) that are problematic.  
> **username_5**: I think these 2 links to scratchapixel tutorials username_0 be good on learning about the differences about Rasterization and Ray Tracing. https://www.scratchapixel.com/lessons/3d-basic-rendering/rasterization-practical-implementation https://www.scratchapixel.com/lessons/3d-basic-rendering/ray-tracing-overview  

---

