Search Unity

How can i create a water reflection lighting effect?

Discussion in 'General Graphics' started by tomer20072, Mar 21, 2017.

  1. tomer20072

    tomer20072

    Joined:
    Dec 8, 2015
    Posts:
    57
    I need to create an animated lighting effect that would look like sunlight reflection refracted through water, like this
    does anyone know a way to do this?
     
  2. LaneFox

    LaneFox

    Joined:
    Jun 29, 2011
    Posts:
    7,529
    I wonder if you could use a light from beneath with a cookie mask?
     
    bijukchheaashish92 likes this.
  3. tomer20072

    tomer20072

    Joined:
    Dec 8, 2015
    Posts:
    57
    are you sure animated light cookies are a thing?
    regardless i don't know how i would produce the animation for that cookie anyway, so is there a way it could be calculated inside unity, maybe with like a water shader or something, like in here?
     
    Last edited: Mar 22, 2017
  4. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,348
    That image is of a webgl demo which is calculating the caustics in real time, which is pretty cool. It's also almost the only thing it is doing.
    http://madebyevan.com/webgl-water/
    There's no reason you couldn't use something like that technique to create a light cookie or projector in real time, but it relies on having a plausible water simulation running at the same time. There are a ton of tutorials out there for how to do this effect with various techniques (usually using a pre-rendered texture), as well as assets on the store.
     
    Last edited: Mar 22, 2017
    theANMATOR2b likes this.
  5. jvo3dc

    jvo3dc

    Joined:
    Oct 11, 2013
    Posts:
    1,520
    There are tools that can generate an animated tiling caustics texture for you. With specific shaders you can project them onto surfaces for for example directional or point lights. (You calculate where the light hit the water surface to determine the uv coordinates for the caustics texture.)

    It looked pretty convincing in a demo we did years ago:


    No caustics simulator there, just an array of textures. (About 32 I think.)

    The key is to use a custom shader to get the projection right. A simple projector on a light won't be correct, because the caustics texture should be mapped on the water surface.
     
  6. Lost-in-the-Garden

    Lost-in-the-Garden

    Joined:
    Nov 18, 2015
    Posts:
    176
    some of these effects could be faked with time dependent 2d noise functions in the shader. There are a couple different noise functions out there and doing some math on them can yield the desired effect. Could be faster than using real animated textures, but might also not offer enough artistic control.