Hi all,
I've been using the MirrorReflection script+shader from Unify, and it worked pretty good until I switched to deferred rendering. Now it seems the objects are not lit anymore (except for the ambient?) in the reflection image. Any idea why?
Note that :
- I've force-enabled the "use pixel lights" in the script
- I've got a couple of other render-to-texture which do work with deferred rendering
Thanks,
Ben
Just to document the technical reason for this issue:
Deferred rendering calculates the world-position as part of lighting the scene. This calculation is based on the depthbuffer of the rendered scene.
The reflection camera uses an oblique projection matrix - skewing the viewfrustum of the reflection-camera in order to create a clipplane at water-level.
As a result, the depth from a reflection cam, is different to the depth of a regular cam, causing wrong positions to be used in the deferred lighting calculations. This causes similar issues with shaders that use the depthbuffer in their rendering as well - e.g. soft-particles, and various post-effects.
A solution would be to use the inverse projection-matrix for depth-reconstruction, but this would make all lighting-calculations in Unity slower.
So far, the best solution is probably to use the forward rendering, and just reduce the number of objects reflected to account for the reduced performance.
Try this dirty hack:
reflectionCamera.renderingPath = RenderingPath.Forward;
I don't know why there is no way to render reflections with Deferred Lighting ((