Game Development

Shadows in Unity is something that in most cases is a given through the use of surface shaders, but sometimes you don’t want to use a surface shader for whatever reason and create your own vertex/fragment shader. The biggest advantage is that everything is in your hands now, but this is also one of the drawbacks because you now have to handle a lot of stuff that Unity conveniently handled for you in a surface shader. Among such things are support for multiple lights and shadows.

Luckily, Unity provides you the means to get this working! The catch? Documentation on this is lacking or even non-existent. I was in the same position as most people and somewhat clueless on how to get shadows in my vertex/fragment shader, I did my fair share of googling and found some clues that didn’t quit do the trick, but gave me a good impression on where to search. I also went through a compiled surface shader to see if I could figure out how they did it. All of the research combined and some trying out finally gave me the results I needed: Shadows! And now I will share it with whoever is interested.

Before I begin, I want to make note that as mentioned earlier, Unity solves a lot of cases for you when you are using surface shaders, among such things are the inner workings when you are using deferred or forward rendering. With your own vertex/fragment shaders, you will need to take that into account yourself for some cases. Truth is, I only needed to get this to work with forward rendering and only briefly tested how this works with deferred rendering and although I did not notice

It’s been a while since I posted an update about the progress of my specialization project. Last time I added depth of field, but more has been added in the meanwhile!

I added a particle system that handles the floating of some small debris, it’s just floating around, rotating randomly, doing it’s thing. It’s just one texture for now made by me to test it, but it will get some variation later on.

I also, or rather redid the lightshafts, the previous implementation looked nice, but due to the fact that nothing from above (not counting the occasional fish perhaps) is blocking the light source, leaving a very overexposed scene without many shafts. So instead, I did them manually. They’re simple planes with alpha. They still need to be tweaked a lot to make a nice and convincing effect, but it’s starting to look like something!

The latest thing I added are flocking (or shoaling/schooling if you want to be precise) groups of fish. The basic behavior is implemented, but they need a lot of tweaking to becoming more convincing (not to mention implementing animation for them, which will be in soon). They’re not really bound, so they still occasionally move through the ground or above the water.

Next to the above changes, I also made a distinction between upper and lower water surface, so the depth fall off (Depth of Field) is only active when you’re below the water surface and the particles stay below the water surface. Also the models have had an update!