How using 3D lights on 2D sprites?

I have 3d meshes in the background and using URP but have 2D sprites. What I want is that the 2D sprites are lightended by 3D lights. I tried the material “sprite-lit default” but it isn’t affected by 3D light. I also tried every material in the URP folder but no one worked with transparent alpha channel. How can I use the 3D light for the 2D sprite in URP?

I can’t use 2D-lights because then the skybox and 3D meshes in the background won’t be lighted.

I also want to use 3D lights on a 2D tilemap.

create a new shader based on default lit, with sample texture 2d and put it on the sprite renderer

1 Like

Damn I have no idea how to do that. I have no knowledge about shaders.
Maybe someone have made already such shader. If there is such thing in Asset Store I would buy it.

Is this shader than in the material?

i would try the approach of using a quad mesh filter and a mesh renderer instead of a sprite if you can. since it’s technically a mesh, it will take 3d lights into account. but, if you’re heavily dependent on sprite renderer features, this may not be viable for you. also, this won’t work for the tilemap, you’d probably have to make a custom shader for that.

Yeah I need this for the tilemap too.

I found something, I need to get into it:

https://discussions.unity.com/t/custom-shader-built-for-2d-sprites-to-react-to-3d-light-environment-breaks-on-runtime-custom-shader-turns-2d-sprite-white-in-3d-environment/255000

But at best there would be already such shader/material in the Asset Store.

The sprite doesn’t have any depth- or normal-information, so it cannot be lighted correctly.
What I would try is using Quads with textures (not the sprite renderer) and add a normal map to it (there are tools which can kind of predict the normals of a sprite. Depending on the sprite this works well or not).

I made an material from the Lit-material from URP and it seems to work with point light.

But I have one gameobject, which is affected by directional light and one another is not. I don’t know why, because I have both adjusted same.

The gameobject which is affected by directional light have some yellow lines if I select the gameobject. What means this yellow lines? And what make the one gameobject to be affected by directional light and the other not? I don’t understand this.


I made a shader/material for 2D sprite (using “Sprite Renderer”) which are lightended from 3D pointlights and directional light.

But the Tilemap-Render don’t get the light from directional light only from point light. How can I fix this?

you can always pass your own sun direction as a global parameter, it’s kind of hacky but it’ll work (1 max, no shadows).

just send in the transform.forward of your directional light using Shader.SetGlobalVector, and read it with the same name in your shader, something like _SunDir. you can extend this to color etc as well if you need.

Ok I got it to work. Now everything is good. In the debug modus I could fix it.

I upload the shader and material here for others.


Lit2D_Shader Graph.zip (4.8 KB)