1
\$\begingroup\$

I've been losing my mind over this for a couple of days now, and can't find any concrete information about it.

I am trying to write a custom shader (shader graph to be specific) to light sprite shape objects. This is a relatively simple shader:

Shader graph representation of a simple lit shader

This is what the shader material looks like applied to a generic square sprite, and the sprite shape. This is using a Light 2D Spot light:

A normal shape lit as expected, and a sprite shape not being lit with the same material applied

Clearly this shader is working fine for the generic square sprite, but not the sprite shape. I would think that maybe sprite shapes just can't be lit, and that would be the end of that. But when I apply the default Sprite-Lit-Default material, it seems to work just fine:

2D Lighting working on both the sprite shape and square

Albeit it requires some sort of "refresh" of the sprite shape, as it doesn't work when its assigned, but it will work once the sprite shape's "Stretch UV" option is toggled (to note, it doesn't matter if "Stretch UV" is toggled on or off, toggling it is just used to refresh something about the sprite shape).

The reason I can't just use the built-in Sprite-Lit-Default material is because I want to include other properties/effects to the custom shader beyond just the basic lighting.

I'm sure there's a piece of information/knowledge that I lack, or something that I'm missing, but at the moment I'm all out of ideas. Even if a concrete answer of "it's not possible because XYZ" would make me happy at this point.

Some Housekeeping information:

  • Unity version: 2021.3.8f1
  • Sprite Shape version: 7.0.6
  • Shader Graph version: 12.1.7
  • Using the Renderer 2D in URP (Because 2d lighting)

Any other information I'd be more than happy to give. I'm not sure what else would be relevant.

\$\endgroup\$
2
  • 1
    \$\begingroup\$ Have you tried looking at the code of the default sprite lit shader, to try to determine what it's doing differently? \$\endgroup\$
    – DMGregory
    Commented Sep 29, 2022 at 15:54
  • \$\begingroup\$ I'll be honest, I don't know shader code, hence using unity's visual solution. So I wouldn't know where to begin comparing them. But I think you're totally right about that being a good first step. \$\endgroup\$ Commented Sep 29, 2022 at 15:58

2 Answers 2

2
\$\begingroup\$

I know this was partially answered already, but for anyone still trying to get this to work with the Sprite Custom Lit shader, this seemed to work for me:

Create a Texture2D variable and make sure its Reference is set to "_ShapeLightTexture0", and disable the Exposed checkbox.

1

This should grab a hard reference to Unity's built-in 2D lighting render target which you can use in place of the 2D Light Texture node.

2

Not sure why the 2D Light Texture node is bugged here either, but it's probably a simple fix for the Unity devs. I'll see about opening a ticket and getting this patched if no one has done so already.

In the meantime, I hope this works for others!

\$\endgroup\$
1
  • \$\begingroup\$ Thanks for the info! Do you know of any resource that has a list of these hard References? If not, how did you know to use "_ShapeLightTexture0"? Every time I've stumbled on one of these magic References its been through some vague Github comment chain or something, and it's infuriating that I don't know where to find them! \$\endgroup\$ Commented Nov 29, 2022 at 15:26
3
\$\begingroup\$

As a partial answer to this:

Only Custom Lighting is broken for sprite shapes. That is, setting the graph to Sprite Lit Custom, and using the 2D Light Texture Node like in the above image (image 1).

Setting the shader graph to "Sprite Lit" instead, and not using the 2D Light Texture Node works just fine:

enter image description here

This works if you don't want to apply any additional logic to the lighting of your sprite shape. In that case, this is all that you need to do. You can still build a Lit sprite shader that acts like the Sprite-Lit-Default shader as a base, and add any additional shader stuff on top. You just can't mess with the lighting information.

I still have no idea why the custom lit shader won't work, and I can't find any documentation/information pertaining to that. I will update this answer in the future if I stumble on anything like that.

\$\endgroup\$

You must log in to answer this question.

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