Nature sprites & shadows issues

Post here if you need help getting started with Daggerfall Unity or just want to clarify a potential bug. Questions about playing or modding classic Daggerfall should be posted to Community.
User avatar
Interkarma
Posts: 7247
Joined: Sun Mar 22, 2015 1:51 am

Re: Nature sprites & shadows issues

Post by Interkarma »

MasonFace wrote: Fri Apr 24, 2020 4:01 pm @Interkarma:

On the topic of sprites casting shadows, I've been wondering for quite a while how you've managed to get a 2D image to cast a shadow that is consistent with the direction of the light source. Do you have a write-up on that somewhere you can link? Otherwise, do you mind giving a brief summary of how that works?

Thanks!
For nature sprite batches, the orientation of each billboard is done in a shader using built-in view matrix variable UNITY_MATRIX_V. For player this faces camera, for shadow projection this faces light source. The whole billboard is actually constructed in vertex shader from position and specially packed data. Shader link:

https://github.com/Interkarma/daggerfal ... tch.shader

It's really efficient and the one set of vertices work for both cases. It's not doing any extra work that shadows wouldn't be doing anyway. The catch is it only looks good when there's a single light source like the sun.

For other billboards like mobile NPCs, enemies, and animals, these are driven by CPU. A script transforms each billboard to face inverse of player camera (or editor camera in editor mode). These do have the problem of shadow being tied to billboard orientation which doesn't look as good. The shadow twists around as you circle target. That's why those shadows have always been switched off. I felt they broke the illusion more while on than off.

I've recently added an .ini setting for KoW to enable shadows for these CPU billboards. It doesn't look as good as nature billboards though, and it's just a matter of time before someone posts a bug report about those shadows and I'll link back to this post as a way of explaining why they don't look as good. For any future visitor directed here under those circumstances, greetings from April 2020! :)

Post Reply