1
\$\begingroup\$

I'm making a 2.5D game, where 2D sprites are in a 3D environment. I'm using URP and I have a problem with lighting the sprites. The sprites are lighting up from behind, and not front. I tried with directional, spot and point lights but the result is the same no matter what official shader I use they only light up when they receive light from behind. Front light has no effect whatsoever on the sprites.

I spent the entire day looking for a solution but I've got almost nothing. Only solution I saw someone else mention is making the game object with the "sprite renderer" on, a child of another gameobject and rotate it 180 degrees on Y. But that is not an option for me cause I'm using custom scripts to rotate that game object already.

So can there be a custom shader? Can one be created using shadergraph maybe? I know some others have faced the same problem but did anyone really solve it?

Thanks.

\$\endgroup\$
6
  • \$\begingroup\$ Can you walk us through the steps required to create a sample scene that demonstrates this problem, starting from a new, empty project? Once we can reproduce the issue you're having, we can test potential solutions to make sure they'll work for your needs. \$\endgroup\$
    – DMGregory
    Jul 19, 2020 at 23:08
  • \$\begingroup\$ Sure, let me try. I recreated this in a regular 3D environment as well not just URP. You can pick any 2D sprite and place it on the scene. Now we want this sprite to be lit so we need to pick a shader. -Create a new material and assign it to the sprite renderer. Change the materials shader to something lit. (for example) "Universal Render Pipeline/Simple Lit". -Create a point light and place it in front of the sprite on the scene. You will see that it does not cast light on the spite. But if you place it somewhere behind the sprite, it'll light up. \$\endgroup\$
    – Vern Rowan
    Jul 19, 2020 at 23:12
  • 2
    \$\begingroup\$ I'm unable to reproduce the effect you describe. If I launch my URP project and place a sprite in the sample scene with the simple lit material, it correctly receives light and shadow on the front side of the sprite, and the sprite is not visible at all from the opposite side. Is it possible you've mirrored your sprite by scaling it by -1 on the x or y? This will invert the winding of its polygons, making them visible from the other side, but it won't flip the normal used for lighting, which will still face the original lit side. \$\endgroup\$
    – DMGregory
    Jul 20, 2020 at 11:38
  • \$\begingroup\$ Thanks for your comments, turns out it was my mistake after all... I had no idea enabling "GPU Instancing" could have this effect. \$\endgroup\$
    – Vern Rowan
    Jul 20, 2020 at 16:21
  • \$\begingroup\$ This is why it's so important to reproduce the problem in a new empty project - it will help you identify exactly what steps are required to cause the problem. \$\endgroup\$
    – DMGregory
    Jul 20, 2020 at 16:22

1 Answer 1

1
\$\begingroup\$

Ok, this problem apparently occurs because at some point I enabled "GPU Instancing" under the materials "Advanced" options. Material is using the shader "URP/SimpleLit" with its Albedo set to the sprite texture. So if anyone else runs into this kind of lighting problem in their projects "GPU Instancing" might be why the lighting is acting weird.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .