Hello, I have a simple 3D scene set up that consists of global directional light, and a few torches that consist of point lights. I am also using the “built-in render pipeline”, not URP. I have 2D sprites in the scene that consist of a sprite renderer, and the “Sprites-Default” material. The problem with this is that when the sprite is in a shadow it does not darken, and if the sprite gets closer to a point light (torch emitting a yellowish light), it doesn’t tint the color. The color does not change with respect to lighting.
So I found a simple tutorial that consists of creating a new material, and under “Shader” selecting “Sprites” → “Diffuse”. Link to tutorial for reference:
This was on the right track and almost worked - the only problem is that the sprite doesn’t really darken that much in shadows, and gets extremely bright when close to the yellowish light. Is there any way to adjust this? The lights look perfect in the 3d scene, so I wouldn’t want to adjust the light down, otherwise it will barely light up the 3d scene.
Is there a way to get into the shader code of this and tone the lighting down?
A possible option might be to create a flat mesh and map the sprite as a texture over that. This is not an option for me. I need to use the sprite renderer and 2d sprites.
By the way, I am using the “built-in render pipeline”, not URP.
Thanks and any help or advice is greatly appreciated!
I’m at a point where it seems the only way to accomplish this is to track the position of the lights, and every onscreen sprite needs to do a distance check in order to determine brightness. I would be out of luck with the shadows.
Is this really the only way?
Any downside to having 50ish gameobjects checking distance as far as performance goes? Or is that not a large amount and it should be fine?
It sounds like you don’t have the scene configured the way you want. If the sprites aren’t dark enough when no light is affecting them then you should check the ambient light of your scene and make sure it it set to the darkest color you want in your scene.
If your sprites are too bright when near the light then first check to make sure you are using linear lighting in your project and not gamma. If you are using linear, then you’ll have to consider several options. The easiest is to simply design your game so that lights never get so close as to wash out the color of your sprites. If that isn’t an option then you might have to consider a custom lighting model shader for your sprite materials that doesn’t use the typical distance-squared formula for lighting calculations. I’ve had to do this in a number of projects in order to get visually pleasing lighting since it often requires something that doesn’t work the way lights would in real life.
I have been playing around with the ambient lighting, as well as light sources, and I have to make the scene way too dark in order to get the sprite to tink darker in any meaningful way. And yes when the sprites get anywhere near a light source, they get way too bright and wash out like you mentioned.
I checked the light setting under “Project Settings” and it is already set to “Linear Lighting” by default, I went to switch it to gamma just to see and it gave me a warning that it was going to take a long time to migrate over, so I didn’t do it.
Is there an off the shelf shader that I can just change a few lines of code and be good to go? I am using the built-in render pipeline (not URP), so I am not finding good examples.