• Register

Wonhon: A Vengeful Spirit is a paranormal stealth action game where you play as a vengeful spirit of a girl who was killed during a bloody and cruel occupation of her country. Now, she has returned from the dead. Gifted with powers from the Jeoseung Saja, the God of Death, she sets out to exact terrible vengeance.

Post news Report RSS Blob shadows for optimization (February 12, 2021)

One of the things that I was happy to figure out was getting real-time shadows for compute shader particles in Unity.

Posted by on

30

Blob shadows for optimization
Imgur.com

"One of the things that I was happy to figure out was getting real-time shadows for compute shader particles in Unity. Since many elements are drawn on screen using my custom particle system (rain, fog, snow, rats, crows, centipedes), it was really important to be able to get shadows for these particles. By default, these particles are drawn separately from everything else that has been drawn on the screen, so you have to use command buffers to add these elements separately to the lighting system. It might sound simple, but it took me a while to figure out command buffers.

HOWEVER

Real-time shadows are very taxing for the GPU, so when I was doing some tests on lower-end PCs, I noticed that the framerate on the game was going down by half on some scenes. Scenes with crows suffered the most as each crow has a fairly high poly count (around 1000) and many of them can be seen on screen at once (2000+). Performance would go up simply by turning off shadows for these particles, but shadows are necessary to make these elements feel grounded in the world. So the solution?

Fake blob shadows! And MORE particles!

I’ve essentially added another particle system that connects into the crow's particle system that spawns a blob shadow particle under each crow. Since the ground height is always zero in this game, it’s as simple as having each blob shadow particle follow the crow’s XZ positions and having the Y be zero. I suppose calculating the height position of the game wouldn’t be that difficult as well, using distance fields or top-down depth cameras (which Wonhon already has for rain particles). Projecting shadows on uneven terrain might be a bit more difficult, but luckily this game has flat terrain so it’s all good.

It’s really satisfying to see the frame rate for the game go from 30 to 55fps on a low-end gaming laptop by making this simple change. Maybe I can figure out something else to get it to run at locked 60fps…" (c) Sean, the Wonhon: A Vengeful Spirit developer.

Post a comment

Your comment will be anonymous unless you join the community. Or sign in with your social account: