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. Dismiss Notice

infinite mirror effect

Discussion in 'Shaders' started by eco_bach, Feb 5, 2016.

  1. eco_bach

    eco_bach

    Joined:
    Jul 8, 2013
    Posts:
    1,601
    Any shader experts that can tell me whether its possible to create an 'infinite mirror' effect in Unity using shaders?

    Any tutorials I should check out?
     
  2. jvo3dc

    jvo3dc

    Joined:
    Oct 11, 2013
    Posts:
    1,520
    You could, but it would take an infinite time to render.

    I assume you're talking about two opposing mirrors. You could handle that with mirroring camera's, but that would lead to a large amount of draw calls. So I would advice to solve it in a model that has all the mirrored parts in it. So you get something like bdbdbdbd dbdbdbdb. And in the middle there would be the main room with b in it. This allows everything to be drawn with as few as possible draw calls. And it even allows you to (manually) optimize the reflections that are further away.

    To get it in the mirrors you can just let the mirror geometry mark the stencil buffer and then only render the mirrored geometry where the stencil buffer is marked. Usually with some "fog", so infinite actually becomes a finite number.
     
  3. hiab-x

    hiab-x

    Joined:
    Apr 14, 2013
    Posts:
    30
    Hello jvo3dc. I have similar ambitions as the previous user to achieve this effect. Something very close to this video
    is what I'd like to achieve in Unity. Making matters slightly more complicated, I'd like to get away with rendering it within a VR headset using a PC as the main gpu output. The closest video I've found to this being implemented within Unity is here
    but I've run ashore looking for a tutorial which even begins to tackle the subject.Needless to say, I found you and you seem to know what you're talking about. Can you give a few more pointers or am I looking at a world of pain?
    If this is to be achievable in VR, I would want the user to have simple 3DOF viewing ability.
     
  4. CannonWilson

    CannonWilson

    Joined:
    Sep 9, 2021
    Posts:
    1
    Sorry to revive a dead post, but I'm wondering if anyone has pursued this?
     
  5. halley

    halley

    Joined:
    Aug 26, 2013
    Posts:
    1,869
    The approach that jvo3dc described is the best way to stay performant. Model the insides and use a shader or rendertexture to show it where you want it. See any number of "making portals in Unity" tutorials, but make the twin camera look at a fake repeated geometry instead of trying to calculate multiple bounces.
     
  6. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,238