Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
3
Question by Ben 14 · Sep 23, 2010 at 06:38 PM · rendertexturemirrordeferred

Mirror reflection & deferred shading

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

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image SoBiT · Jul 14, 2013 at 09:36 PM 0
Share

Hey, did you ever find a solution for this? I have the same problem and I HAVE TO use Deferred Lighting. Would be great if you answer :)

2 Replies

· Add your reply
  • Sort: 
avatar image
4

Answer by Mikkel Gjoel · May 06, 2013 at 02:30 PM

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.

Comment
Add comment · Show 6 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image SoBiT · Jul 16, 2013 at 06:24 AM 0
Share

Hi. How does the thing with the inverse projection matrix work?

avatar image fffMalzbier · Jul 16, 2013 at 08:24 AM 0
Share

Thanks a lot for this explanation.

avatar image Benproductions1 · Jul 16, 2013 at 11:14 AM 0
Share

This is a good answer. Why is it not accepted?

avatar image SoBiT · Jul 16, 2013 at 12:06 PM 0
Share

Yes, pretty good but I'd still like to know how the projection matrix works :S

avatar image Mikkel Gjoel · Jul 16, 2013 at 01:53 PM 0
Share

SoBiT - the suggested solution of using the inverse projection-matrix requires modifications to Unity. You could possibly override Internal-PrePassLighting.shader, and set the Inverse Projection $$anonymous$$atrix as a global shader-parameter ( see http://docs.unity3d.com/Documentation/ScriptReference/Shader.SetGlobal$$anonymous$$atrix.html ). $$anonymous$$ind you, I have not really looked into this, let alone tried it, and it would certainly reduce your overall lighting-performance some.

If you need to reconstruct depth during a reflection pass, you can however use the inverse projection matrix for this (probably easiest to just grab Camera.current.cameraToWorld$$anonymous$$atrix ). We have used it to add a post-effect fog, that only adds fog from the water-plane to the reflected objects.

If you need more information about reconstructing the worldspace position from a depthbuffer in general, Google as usual has all the answers: https://www.google.dk/search?q=mjp+worldspace+reconstruction

Show more comments
avatar image
2

Answer by ILya84a · Oct 01, 2010 at 02:38 PM

Try this dirty hack:

reflectionCamera.renderingPath = RenderingPath.Forward;

I don't know why there is no way to render reflections with Deferred Lighting ((

Comment
Add comment · Show 5 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Ben 14 · Oct 02, 2010 at 01:24 PM 0
Share

I'll have to be carefull with the peformance of that, but at the very least this can be a fallback solution - thanks ILya!

avatar image SoBiT · Jul 16, 2013 at 12:07 PM 0
Share

Works for light, but there won't be any shadows in the mirror.

avatar image Mikkel Gjoel · Jul 16, 2013 at 02:12 PM 0
Share

SoBit - forward-shadows can be enabled using the fullforwardshadows keyword (for surface-shaders) - see: http://docs.unity3d.com/Documentation/Components/SL-SurfaceShaders.html . This of course requires using your own shaders.

avatar image SoBiT · Jul 16, 2013 at 06:31 PM 0
Share

So I would have to modify all shaders I use in the project?

avatar image MarkD · Oct 20, 2013 at 06:36 PM 0
Share

$$anonymous$$aybe a late answer, but no you only need to put that line for shadows in your mirror shader, so it will draw it over everything it sees in its pass. I was having the same problem while writing my advanced glass shader, I wanted to use differed/forward rendering but altough i adjusted the script, it only worked with ambient, wich sucks balls.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

RenderTexture Mirror - Camera postion and rotation 1 Answer

Sun rays don't show up in mirror reflection in deferred rendering ? 0 Answers

Performant Alternative to render texture? 1 Answer

Deferred lighting ignore viewport rect? 0 Answers

mirror effect reversed side? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges