Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Mirror Reflection Shader v4 in Unity 5. Any success anyone?

Discussion in 'General Discussion' started by ZiadJ, Mar 12, 2015.

  1. ZiadJ

    ZiadJ

    Joined:
    Sep 3, 2011
    Posts:
    62
    After upgrading to Unity 5 I had to switch to the new the new version of the mirror reflection shader available here:
    http://wiki.unity3d.com/index.php/MirrorReflection4

    However the new shader is giving me a 'could not find entry point' error when the older v3 worked just fine in Unity 4. Is this a bug or am I missing something? I only managed to get around it by replacing it with the 'Fx/Water' shader but I can't get a pure mirror effect from it. Has anyone had any success with the original shader yet in Unity 5?

    EDIT: The problem is now fixed as from 2015 March 20.
     
    Last edited: Apr 24, 2015
    EliasMasche likes this.
  2. Neoku

    Neoku

    Joined:
    Oct 27, 2014
    Posts:
    261
    I test this script minutes ago and have not errors.

    mirror.png
     
    ZiadJ likes this.
  3. ZiadJ

    ZiadJ

    Joined:
    Sep 3, 2011
    Posts:
    62
    Could you send me your project as a package please? That will confirm the problem does not lie in my implementation but rather from Unity 5 itself.
     
  4. Neoku

    Neoku

    Joined:
    Oct 27, 2014
    Posts:
    261
     

    Attached Files:

    cl9-2 and ZiadJ like this.
  5. ZiadJ

    ZiadJ

    Joined:
    Sep 3, 2011
    Posts:
    62
    Thanks a lot Neoku this solved my problem! Well I started out by overwriting my files with yours hoping this would work but it didn't. Turns out I had to delete the existing plane in my project as well and create a new one for the shader compiled at last. Been struggling with this for hours!!!

    Guess the problem is that older shaders are not properly cleared from the cache when new ones are used and hence the conflicting errors. I've experienced such an issue in v5 before where I switched shaders and the older shader was still kind of persisting on the new one.

    Don't hesitate to contact me anytime if you come across any issue. I'd love to help you back any way I can :p.
     
    Neoku likes this.
  6. ZiadJ

    ZiadJ

    Joined:
    Sep 3, 2011
    Posts:
    62
    I'm not done yet though. Have you noticed that the mirror image gets resized when you resize the plane? This is not the behavior we had in the previous version and I can't seem to figure out how to do it independently. Hopefully there's a workaround for it.
     
  7. HolBol

    HolBol

    Joined:
    Feb 9, 2010
    Posts:
    2,888
    I think in unity you can right-click an asset and either click 'refresh' or 'reimport' if it hasn't auto-updated.
     
    ZiadJ likes this.
  8. ZiadJ

    ZiadJ

    Joined:
    Sep 3, 2011
    Posts:
    62
    That's good to know. Thanks for the info.

    Btw do you get the same scaling issue when you resize the mirror in the project editor?
     
  9. darkhog

    darkhog

    Joined:
    Dec 4, 2012
    Posts:
    2,218
    ...

    Why just don't put a reflection probe on the plane/cube/whatever, set it to realtime and bah, you have a mirror, just like that?
     
  10. ZiadJ

    ZiadJ

    Joined:
    Sep 3, 2011
    Posts:
    62
    Thought of it but then it'll end up generating six views every frame which I'm sure most lower end machines will stagger on. Someone already blogged about it here:
    http://twiik.net/articles/realtime-reflections-in-unity-5

    Thanks for the suggestion though.
     
  11. darkhog

    darkhog

    Joined:
    Dec 4, 2012
    Posts:
    2,218
    RenderTexture then? All you need then is a camera aligned with a mirror.
     
  12. ZiadJ

    ZiadJ

    Joined:
    Sep 3, 2011
    Posts:
    62
    That's exactly what the mirror reflection shader was meant to do, much like the water shader but without the wavy effects etc. It works just fine except that I can no longer scale the mirror without scaling it's reflection as well. Kind of annoying that I have to reinvent the wheel just because of that.
     
  13. darkhog

    darkhog

    Joined:
    Dec 4, 2012
    Posts:
    2,218
    Just use render texture with standard shader and then make sure render texture has same proportions as the mirror (e.g. if mirror is1:3 in size, render texture should be too). Also you need to play with camera's fov a bit to get it right.
     
  14. ZiadJ

    ZiadJ

    Joined:
    Sep 3, 2011
    Posts:
    62
    The mirror will be used in an open world simulation and the fact that it's a VR application makes every millisecond count. The official shader seems to be using render texture too and seems to be elaborately engineered, probably for performance reasons. If that's the case then I'd rather wait for someone to fix it before I try to go for the self-implemented(and probably less optimized) route. The water shader will do the trick for now;). Thanks for the tips.

    Edit 1:
    I've notified the author of the shader about it. So hopefully he will respond soon.

    Edit 2:
    The shader seems to be working properly now after an update on 2015 March 20.
     
    Last edited: Apr 24, 2015
  15. variablestatekieran

    variablestatekieran

    Joined:
    Jun 12, 2015
    Posts:
    26
    It is drawing all the geometry correctly, but lighting in the mirrored image is very different to that in my scene.

    It seems that there are no shadows being casted, anyone have any ideas?
     
    Last edited: Oct 12, 2015
  16. LUPShow

    LUPShow

    Joined:
    Jul 6, 2015
    Posts:
    7
    i am trying to add an alpha value to the shader, to make transparent reflection planes possible (like in the version for Unity 2.x)

    but i am no shader pro at all... can someone maybe help?
    i added the properties:

    _MainAlpha("MainAlpha", Range(0, 1)) = 1
    _ReflectionAlpha("ReflectionAlpha", Range(0, 1)) = 1

    but I don't know how to compute them properly in the actual shader code...
     
  17. AkilliMum

    AkilliMum

    Joined:
    Dec 6, 2014
    Posts:
    107
    I just put a matte shadow (unvisible shadow caster) plane a little above the mirror. Not a very good solution but works :)
     
  18. shinriyo_twitter

    shinriyo_twitter

    Joined:
    Aug 12, 2011
    Posts:
    328
    warning CS0618: `UnityEngine.GL.SetRevertBackfacing(bool)' is obsolete: `Use invertCulling property'

    I'd like to contribute your unify code, but I don't edit authority.
    Please fix

    Code (csharp):
    1.  
    2. GL.SetRevertBackfacing (true);
    3.  
    to

    Code (csharp):
    1.  
    2. GL.invertCulling = true;
    3.