Search Unity

Transparent glass shader filtering light (simulating different colours of windows glass)

Discussion in 'Shaders' started by nataliw, Jul 22, 2016.

  1. nataliw

    nataliw

    Joined:
    Jul 22, 2016
    Posts:
    6
    Hi

    I've been trying loads of shaders and nothing worked so far. What I'm after is building a room with windows of different colours where the colour of light that gets through the window into the room (shadows ON) is modified in accordance with the colours of the glass. You can open the windows and see the original colour of the directional light.

    I wanted to make it dynamic using the procedural skybox, but I'll be more that happy to get your suggestions on static solutions too.

    Thanks

    Natalia
     
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,342
    This isn't something directly supported by lighting system in Unity, instead you'll need to fake it. The most common method is either using a light with a cookie, or a projector. In Unity light cookies let you put a greyscale mask over a light so if you have a window with slats or some other shapes you could disable shadow casting on the window itself and have the light fake the shadow. You would then set the color of the light to match the color of the window. Now if you've got a window that's multiple colors like stained glass often is Unity unfortunately (to the eternal bane of Unity users) doesn't support colored light cookies so you have to use projectors instead. Projectors aren't really lights though so they don't behave the same, like they don't cast shadows at all and they just glow on top of surfaces, but they can still be a decent way of faking it.

    There's a recent thread about getting projectors to work with shadows that might help if you need it, or you can check out Alloy shader framework which has options for colored shadow cookies.