Download

[UE4.25] A ray-tracing reflection issue on the clear coat when enabling the fog and How to fix it

We found a reflection issue on the clear coat materials that when enabling the fog, the color on the clear coat surface would be too bright and like a mirror.

Here I will offer what I found and a solution for this issue and hopefully it could help you. And I hope the Unreal Team could see it and fix the bug on the mainstream as soon as possible because there might be a lot of people are still suffering from the issue as well.

After investigating the shader code of ray-tracing reflections, I found the following code from RayTracingReflections.usf causes the issue.



// Now accumulate the radiance coming through this path segment into the full path radiance.
// In the case of clear coat material: the fog is applied once for both bottom and top layer using the main top layer refelction path.
float3 PathSegmentRadiance = TopLayerRadiance * TopLayerReflectionEventThroughput + BottomLayerRadiance;
PathSegmentRadiance = PathSegmentRadiance * HeightFogInscatteringAndTransmittance.a + HeightFogInscatteringAndTransmittance.rgb;
PathRadiance += PathSegmentRadiance * PathThroughput;
// Update the path throughput according to fog and material top layer reflection event.
PathThroughput *= HeightFogInscatteringAndTransmittance.a * TopLayerReflectionEventThroughput;


The reason why it’s wrong is that they thought every bounce of reflection likes the following schematic diagram:
ClearCoatReflection1.png
But the truth is:
ClearCoatReflection2.png

Thus, I modified the shader code as following and it solved the issue well:



// Now accumulate the radiance coming through this path segment into the full path radiance.
// In the case of clear coat material: the fog is applied once for both bottom and top layer using the main top layer refelction path.
float3 PathSegmentRadiance = TopLayerRadiance + HeightFogInscatteringAndTransmittance.rgb;
PathSegmentRadiance = PathSegmentRadiance * TopLayerReflectionEventThroughput;
PathSegmentRadiance += BottomLayerRadiance;
PathRadiance += PathSegmentRadiance * PathThroughput;
// Update the path throughput according to fog and material top layer reflection event.
PathThroughput *= HeightFogInscatteringAndTransmittance.a * TopLayerReflectionEventThroughput;


Examples after the fix:



This is really awesome, and unfortunately makes you wonder, do they even test that stuff properly before they release it? Can you report this as bug with bugfix to the support, so that it gets fixed for all, without the need of messing with code and ini files?

@MikeZheng

Someone in the Rendering sub-forum needs your help with a ray-tracing reflection issue concerning the reflection of an iceberg in water. I suggested they contact you, but don’t know if they’re going to or not. Thanks for the fixes. The one that I keep running into is flickering on translucent meshes, and at the interface between a translucent mesh and a solid or another translucent one.

Thanks for your advice. I just took a look at how to report a bug and sent the bug report to the development team.

Great @MikeZheng !

Here you are the link to submit Unreal bugs: Unreal Engine Community

Thank you again for contributing :slight_smile: