Hi guys, most of the games I am working on these days are 2.5D and I’m trying to figure out how to use 3D lighting in 2.5D.
I know there are a lot of people on here who get frustrated if you don’t word these things right, so before I go on I would like to make some things clear. I am not asking you to make me a shader, I would never expect anyone to do free work for me. I am asking a question about shader graph specifically, because that is what I currently use do to my novice shading abilities. My shader experience mostly comes from messing around with it in blender, not unity, so I can get my way around and learn, but I don’t have a very good grasp on the nodes that exist in Unity’s shader graph.
Again I will say the game is a 2.5D game, so it uses sprites with lit materials and 3D lights.
The problem: When you move a light behind a sprite, it then has no effect on the sprite. Obviously this makes a lot of sense because that’s how light works.
The question: Is it possible to create a shader that takes some of the lighting from the backface that is being lit when the light is behind, and adds that to the front of the sprite? Whether that would just be rim lighting or completely flipping the lighting I don’t know, that could be something I figure out later. But, is it possible (I would think so) and if so, what is a good way to go about it? I am willing to take “No this is just not possible” or “This is too hard for anyone to help you with” as an answer.
Just a note: I have a very busy life and do not own a phone that can easily look at Unity forums, so I may take a bit to answer. Thank you in advance for taking a moment out of your own life to help out a guy you don’t even know. You were not required to, but you did it anyway, and I say God bless you for that.
If you’re wondering about my experience: I have been making personal games since I was a small child, but have never released anything.
Best I could do was make a basic normal map, that will at least give you some rim lighting, and if you can somehow make a very complex normal map, you could do more with it I assume.
It’s actually very easy if you are writing the lighting portion of your shader (the hard work is actually all the boilerplate to get things setup so you can even access the lights from shadergraph). All you need to do is apply the attenuation of the light per pixel. It’s that easy. Most lighting models then multiply this with the dot product betwixt the light direction vector and the normal of the polygon being shaded but you can simply leave that part out.
I also do a lot of 2D stuff in 3D spaces so pretty much every project I’ve ever done ends up with a handful of bespoked shaders that do this because it’s so common to need to apply lighting even across some objects regardless of facing direction relative to the light.
It’s, unfortunately, not a straightforward answer because it depends on so many factors. Especially, stuff like which pipeline are you using, which render path are you using, how many lights do you need to support, do you want to bother supporting preview windows, etc etc etc…
If you look around online there are various tutorials, all of which are various levels of outdated or irrelevant to any give use-case due to the issues I mentioned above.
The basic gist though is that you have to setup an unlit shadergraph shader and then create a custom node to access the lights currently being applied to any given situation. The actual code there will be a horrendous mess of conditional compilation and statements. Once you’ve done that, the actual calculation is literally just a one-liner. Multiply the light’s pre-calculated light and shadow attentions with whatever base texture and color tints you already have.
Assuming one is trying to make it work for URP then one of the sources I used to get it all working can be found here:
It’s horrendously outdated and won’t work anymore but it should at least give people a starting point to investigate further. I’d elaborate more but honestly, it’s such a mess that I don’t even understand half of what I did to jury-rig it into working, anymore.
This one looks more up to date but is definitely leaving a LOT of important details out and won’t work for Forward+.