🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Creating Real Light Bouncing Mirrors in UE5

Started by
5 comments, last by JoeJ 1 year, 9 months ago

Hello all,

**My Problem**

I'm interested in using UE5 to simulate how light would bounce off of an array of mirrors.

I immediately hopped in and started making reflective materials, only to find that while materials don't truly "reflect" things, as in, this reflection isn't produced by bouncing rays, but only by using camera views to map what that camera sees onto the object's texture (Ex. SSR).

After a while that neither varying the kind of light (direct or spot), its type (static or moveable), and its material, I still was unable to produce a set up where a reflective material bounces a beam of light off of itself.

**My Setup**

I basically have a slightly reflective wall and floor, with a mirror between them, and direct light coming down towards the mirror at a slight angle from above.

- The mirror is circled in red

- I've placed an emissive sphere where the light beam should be landing.


- The light source does properly appear in the mirror's "reflection".

- Here is the path the light beam should be taking

- Here is what my project looks like in pre-view (it doesn't change when I start)

- This is the material I'm using for the mirror

**My Questions**

- How could I go about bouncing the beam off of the mirror onto the wall by only using the rays produced from the direct light?

- Is there a name for what I'm trying to create that I'm just completely oblivious to? I'm new to lighting and game engines.

- If implementing this functionality in UE5 would be cumbersome, are there any engines that automatically come with light bouncing mirrors?

- If this exists, is it a feature only in the Architectural pre-built projects they offer you on start up?

Thank you!!!

Advertisement

Yes this is called raytracing/path tracing and you need that to simulate this light bounces. I dont know how you would set this up in UE5 but there are several websites out there that show you how it works one of which is https://raytracing.github.io/​ but that would require you to write your own code. You could try https://www.mitsuba-renderer.org/​ which is an implementation of a ray tracer that allows you to define your own scene but you have to learn how to do that in that program.

Games in general don't use full scene ray/path tracing because its expensive, you have to do this for each pixel in the screen and usually a couple of times to get a good sample of what that pixel should look like. Games in general use aproximations of how light works wihtouth actually having to do the full ray tracing path, this is cheaper and genrerallly allows for more lights to exist in a scene. Physically based rendering starts making use of actual material properties in these aproximations but is now where near as accurate as actually tracing rays to see what they touch. In games you generally use the direction o fthe light and the normal of the surface to figure out what amount of light is reflected of the light source you are calculating this for and it doesnt go further than that single surface.

Worked on titles: CMR:DiRT2, DiRT 3, DiRT: Showdown, GRID 2, theHunter, theHunter: Primal, Mad Max, Watch Dogs: Legion

anton24 said:
- How could I go about bouncing the beam off of the mirror onto the wall by only using the rays produced from the direct light?

‘Direct’ light refers to only the first bounce. Any further bounce is called ‘indirect’ light, usually.
In games we're happy if we can calculate indirect lighting at all, which then is called ‘Global Illumination (GI)’.
However, usually we reduce this to just diffuse lighting, assuming all materials are rough. This is enough to model global light transport in realistic scenes, because mirrors are rare.
The GI term is not specified if specular indirect lighting has to be included or not. For games it's usually a no, but even for offline rendering using path tracing this is still an open problem and a matter of implementation and tweaking parameters.

Another term useful for your search might be ‘reflections of reflections’, which is often used in discussion, not so much in papers. Iirc, Battlefield V RTX could do this, but surely only for one second bounce, not more.
I also remember UE4 DXR reflections could not do it. Not sure if this has improved. There surely is little motivation to work on this, because getting GI right is so much more important in practice.

However, there is a raytracing technique which can actually do it: ‘Whitted Raytracing’. This is inferior to path tracing from a GI perspective, because it can only model mirrors, no rough surfaces.
So that's likely what you want to look up.

Quake RTX has a debug mode to demonstrate 10 mirror bounces. It can be enabled using a console command and then everything becomes a perfect mirror. They used it for performance tests.
Not sure if it's still implemented in the newest version, but it was in the early one which also was on github.

It's easy to implement, but there is little hope any engine supports it out of the box.
Why do you need it?

@NightCreature83 This makes sense, thank you for pointing me towards Mitsuba 3 and the books! I'll definitely take a look.

@JoeJ
Hey, thanks for the reply.
I'm working on a university research project called the Catoptric Surface. Basically the Catoptric Surface is an array of 650 mirrors that can be individually turned by motors. The goal is to direct sunlight into interior spaces to produce natural and controllable ambient lighting.
We're currently messing around with how we would use these mirrors to reflect light in such a way that we can make an pixelated image on the ceiling (1 mirror light spot being approximately 1 pixel). To make the image, the current approach is to use a stochastic optimization algorithm across a ton of different mirror configurations until we can find the one which best matches the image.
The current system for doing this is very inefficient, so I figured that translating it into C++ and using some pre-existing ray-tracing abstractions from UE5 might help. That being said, things in UE5 haven't really panned out the way I expected them to, (I don't have any experience with game engines), but I'm definitely going to look into what you suggested with Whitted Raytracing and Quake.

Thanks!

anton24 said:
The current system for doing this is very inefficient, so I figured that translating it into C++ and using some pre-existing ray-tracing abstractions from UE5 might help.

It depends a lot on how many mirrors one ‘ray’ of light passes until it hits the goal. The higher this number, the more likely you need a custom solution. (Quake would just serve as an example to show it can be done, i guess)
Mitsuba sounds a good idea to me if you don't need realtime results. I guess it's easy to setup the scene and Whitted tracing method for your needs by generating XML files. (Path Tracing should work too for perfect mirrors - the ‘open problem’ only shows with materials which are not perfectly smooth on their micro surface. But PT might waste most calculations on processing rays which fail to hit a mirror. You likely want to terminate such rays instantly.)
Besides, physics engines provide ray tracing too, plus simulation of motors for the mirrors. Though, i guess you need simulation only for the lighting, not for the mechanics.

You would get the fastest (realtime) results and most flexibility to implement ray tracing for your custom needs by using DXR with a GPU supporting the API. But that's quite low level. This would be an example project: https://github.com/TheRealMJP/DXRPathTracer

NVidias Optix should be an easier API to use with the same speed and flexibility. Surely worth a look as well.

This topic is closed to new replies.

Advertisement