Detect Indirect Specular in Material When Not Using Path Tracing

With Path Tracing it is possible to use the PathTracingRayTypeSwitch node to detect if the material is rendered in a reflection pass or not.

This is very useful, but we couldn’t find any way to achieve this when not using Path Tracing.

- ReflectionCapturePassSwitch only works for baked reflections.

- RayTracingQualitySwitch only affects the hardware ray tracing pass in Lumen, which breaks the effect because of other reflections method in Lumen.

- The only method we found is PathTracingRayTypeSwitch, but it only works when using Path Tracing.

In past that was possible with the old deprecated RayTracing.

Does anyone know a way to do that now?

Thank you!

You can use the surface cache switch preprocessor in a custom node instead for software raytracing but ultimately the limiting factor for things like this with Lumen is always going to be screen traces, they will always pick up how it is displayed on screen.

1 Like

Thank you for the answer,

I checked the surface cache and it seems that the value to use in the Custom node is “LUMEN_CARD_CAPTURE”.

As you mentioned, it works for software ray tracing, but screen traces override it with the wrong color, like the RayTracingQualitySwitch.

By the way, in my original post I said that RayTracingQualitySwitch only affects hardware ray tracing, but that was incorrect, it actually use LUMEN_CARD_CAPTURE in the function.

I assume that the screen traces are done directly from render and it don’t recalculate the material shaders, which would make this impossible unless screen traces are disabled?

Yep. You can disable screen traces for reflections separately from GI screen traces though, there are two settings for them in the post process volume.

The downside is that if you disable screen trace reflections, anything without surface cache will simply be black in reflections, which unless you’re confined to a small room could be a lot of meshes as Lumen aggressively culls surface cache based on the components size on screen.

It also will generally make reflections more expensive, since it now forces all reflective surfaces to traverse the BVH. Though the cost depends a lot on how well optimized your scene is for raytracing.