Search Unity

Water Shadowing Example

Discussion in 'Assets and Asset Store' started by forestjohnson, Aug 15, 2012.

  1. forestjohnson

    forestjohnson

    Joined:
    Oct 1, 2005
    Posts:
    1,370
    Have you ever wanted to put shadows on water? How about manipulate the part of the lightmap which is underwater?

    I've been playing around with this stuff, and this is what I came up with.

    Here is the project as a unity package: http://www.mediafire.com/?tlovf86z6lhql24



    I did 3 separate things to make this look like it does.

    First, I added a plane underneath the water which has a shader that does not write to any color channels, so its invisible, but it makes the real time shadow render in the right place.
    - disable this ShadowCollector plane when lightmapping
    - this is not an optimal solution, but I can't figure out anything better; the real time shadow system is really rigid and it's hard to manipulate it.

    Second, I added lightmap support to the water and attempted to distort it in some way that looked reasonable.
    - check out the WaterLightmapDisplace script

    Third, I played with the lightmapper a little bit. I created a plane which illuminates the underwater areas with bright pink light. This allowed me to isolate the underwater areas and blur them in photoshop as a post process.


    Here is the project as a unity package: http://www.mediafire.com/?tlovf86z6lhql24


    This was my process for marking and editing the lightmap, if you are curious.

    Put a basic material on the water so it gets lightmapped
    Put transparent material on LightmapMarker

    Render Lightmap

    Make a copy of the results

    Put bright material on LightmapMarker

    Render Lightmap

    Open marked lightmap in PS and copy it

    Make a new image with 16 bits per channel so you can edit it

    make new layer under lightmap which is bright red

    set marked lightmap to "saturation" blend mode and merge all layers

    copy red channel and paste it as a layer

    open non-marked lightmap in PS and copy it, into a new image which is 16 bits/channel

    Make a copy of the lightmap layer and blur it, then copy that result you got from the red channel a while ago and paste it into the mask of the blurred layer, then use the Levels tool to normalize it.

    Merge and copy the result into the original lightmap file, the one unity is currently using, and you are done.
     
  2. chingwa

    chingwa

    Joined:
    Dec 4, 2009
    Posts:
    3,790
    That is very interesting. Great Work! I'll download the package and test it out tonight. I assume that the secondary plane that collects the shadows on top of the water blocks shadows from being cast below it onto the bottom of the pool, which is why it also requires lightmapping?
     
  3. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,900
    hi forest,

    very nice effort and very nice to see you back on the forum!
    i have seen your name in the credits of the sprite packer project of the last ninja camp and was wondering what you have done during the last 1-2 years.

    lars
     
  4. JVaughan

    JVaughan

    Joined:
    Feb 6, 2013
    Posts:
    23
    Searching for something like this all damn day, thank you for figuring this out and sharing!