Search Unity

Different Camera Views

Discussion in 'Scripting' started by Perceive, Jan 22, 2014.

  1. Perceive

    Perceive

    Joined:
    Aug 2, 2013
    Posts:
    10
    I was experimenting with having specific cameras see GameObjects differently. I was wondering if there was a simpler (and/or cheaper) method than I was considering?

    The goal is to be able to have an overhead camera see each of the GameObjects in its camera bounds with alternate materials, and be able to update those materials on a frame-to-frame basis (switch colors, tiling of the textures, etc.). I wanted to leave the standard views unchanged.

    My current solution was to switch the materials for each of those GameObjects to an alternate duplicated set of materials on the individual camera's OnPreRender and switch it back to the original, unchanged set OnPostRender.

    Duplicating all of the GameObjects is a solution, but it would get really messy (and harder to do dynamically at runtime).

    Does anyone have any suggestions?
     
  2. TheShane

    TheShane

    Joined:
    May 26, 2013
    Posts:
    136
    Switching materials seems reasonable to me. You're going to be re-drawing the geometry anyway with a different camera so whether it's the same material or a different material won't make a huge difference. You just want to make sure you have some type of manager class that maintains a list of all objects that need material changes so you can quickly run through them and don't need to find them every frame.

    Depending on what you're doing you can look into replacement shaders. You use the same materials but change the shader underneath. It's less flexible than swapping the whole material but probably easier to manage.
     
  3. Perceive

    Perceive

    Joined:
    Aug 2, 2013
    Posts:
    10
    Replacement shaders is exactly what I was looking for, thank you!
     
unityunity