Water, reflections, and a sewer level! - Dev Log

Discussion in 'Developers Blog' started by Chris, Apr 3, 2018.

  1. Chris

    Chris Administrator
    Staff Member

    Jul 9, 2017
    Likes Received:
    Hey everyone, I hope you're all doing well! We have some exciting updates to share about the project. We've been working on several pretty awesome levels in addition to many other components of the game.

    attackofthedead.com sewer.gif
    Player reflection in the water, subtle but there. Upon completion, the player will also be half submerged in water with splash effects.

    One of the levels we're working on is a sewer based scene. Within sewers are some green and nasty sewer water, thus, one of the features we wanted to have is murky animated water and reflections of players/mobs/items etc within the water. And here is where my several week adventure began in shader coding, where I discovered I'd have to: a) write a shader that creates murky water based on a set of texture maps, b) work with our tilemap, c) only effect certain sort-layers and blur items beneath but not above, and d) reflects items above it.

    With a 2d orthographic top-down based game, this isn't as easy as it sounds (unless you are really pro or experienced in writing shader code, which I'm not!). There are several premade assets available that sort of did what we wanted, but not quite. Likewise, there are several shader tools available to create shaders without actually coding them - but in talking with the devs of these, they advised it wouldn't quite be what we wanted - so instead I wrote our own water reflection shader system based on what I learned on a few game forums.

    The trouble with a reflective shader in 2d top-down is that sometimes a mirrored reflection doesn't display items how they would naturally look. In 2d side-scroller games it is simple, you can just mirror everything and it looks fairly decent - however, when the game is top-down, you run into other problems with world interaction and certain reflective behaviours.

    To get a bit technical, to overcome this, I created a shader that only displays certain sort-layers within Unity and combined the sprite render texture so that it also only shows the reflection on that textures where the alpha of the texture is above a given threshold. For example, a water tilemap would have the reflective shader added and only show the reflection on non-transparent pixels.

    Even more, unavoidably, I had to essentially create a dummy part of the reflection so that reflective items have a mirrored gameobject. This is done through script, working with the shader, so that the mirrored gameobject only shows on tilemaps and spriterenderers with the reflection shader.

    Anyway, we've got a lot more we're excited to show soon. We're working towards having a playable demo to release for supporters and hope to have that available in the near future.
    #1 Chris, Apr 3, 2018
    Last edited: Apr 3, 2018
    Leyla and Alexander like this.

Share This Page