[UE5] Use a box relection capture volume's cubemap with a custom reflection vector

Hi,

I’m currently working on a material with a custom reflection vector. For now, I’m using the default CubeMap’s UV to map the reflection onto my surface’s base color. I can’t just use the default reflection methods because my liquid’s surface isn’t generated with geometry but is “simulated” only inside the shader.

But the problem is that this solution is quite limiting, because I can’t modify the scene without recreating an entirely new cube map. In addition to that, the object wouldn’t be able to move across distances because the reflection wouldn’t match anymore.

To address those issues, I tried replacing my cubemap with a cube capture component to update the cubemap when the player moves from one volume to another. But this solution is really performance heavy and wouldn’t allow the game to have bottles at multiple locations.

This video explains how Valve managed to fake the liquid’s reflections and translucency using reflection capture volumes and I would like to do the same.

Is there a way to access the current box reflection capture (the one in which the object is currently located) texture and to use it from a material (in place of the default cubemap) ?

Any advice would be nice :slight_smile:.

Thanks in advance.

1 Like

I stumbled on his node a while back, maybe it’s helpful.

1 Like

Thanks for your help.

I tried it but it doesn’t seem to work, it looks like I still only have the default cubemap (because it looks like it is samplling the cubemap from the HDRbackdrop location).

I need a way to access the closest box reflection’s cubemap inside my material.

I see your problem, as you mentioned the only solution would be to use a low-resolution cube map render target and sample it every time the player moves a certain distance, or limit it to a grid system that represents rooms like the example from Valve. No node gets you the reflection capture sample in the material, but it is implemented in the shader. Looks like a lot of digging in the source code to get it exposed separately.

1 Like

I followed your advice and managed to achieve a cool-looking result, but it came with a significant performance cost, even with a 256x256 texture.

1 Like

Looks great :star2:. Is it that expensive even if you capture the scene only every few seconds once?

You can also try lowering resolution even further.
Or maybe you find a more manual solution? E.g. setting up cube captures/textures beforehand for each location , then going the blueprint route. Crawl for the closest one in BP, then push it into the shader.

Not much on average, but I still experienced significant spikes in render time for a few frames occasionally. However, I think this solution might work way better if you’re not using ray tracing (I was using Lumen).

Yes, it might work, but I feel like this solution would be more of a workaround than a “clean solution”. As I understand it, the reflection capture volumes are pre-baked in the engine, therefore I believe that it won’t cost any more performance than using a regular texture.