2D Lights with SpriteAtlas?

,

Is this a bug? I was trying out 2D Renderer with 2D Lights. One light to illuminate objects, a second to illuminate a red channel mask.

I tested the same image/mask combo on a Sprite Renderer (game object) and Image (Camera Canvas UI).

It only works as expected if I don’t use a SpriteAtlas on the images and use Shader mask. When the Atlas is used, I no longer see the red channel mask getting illuminated at all, only the main texture.

If I add the mask texture as a Secondary Texture in the Sprite Editor (as opposed to the Shader), then it will work on the Sprite Renderer, but the mask on the UI Image enlarges (you can see a portion of the mask, where it looks zoomed in). Texture on both are fine. [sometimes the mask actually looks correct until it enters Play Mode in this situation, then the mask on UI distorts]

Delete the Atlas, and it all works as expected. Mask is visible correctly on both object and UI, when using Shader. When using Secondary Image, mask only works on game object, and UI appears to use the red channel of the base image, not the mask.

So is there a setting I’m potentially missing somewhere, or should I report this as a bug?

It appears to be related to the UV of the sprite, but I'm surprised the packed mask doesn't account for the offsets like the normal texture does, to display it correctly. And I find it interesting that the Secondary Texture is ignored on the Canvas Image.

I can make it work as expected if I 1) don’t use atlases, or 2) make the mask texture the same size as the resulting atlas and position the mask graphic in the same location as the main texture from the atlas… which tells me the atlas is not used for masks or the calculations for atlas offsets are not working for masks.

SpriteAtlas secondary textures support :

  1. Expect the secondary texture to be specified through Secondary Textures in Sprite Editor.
  2. Secondary texture must retain the same size as the Sprite texture.
  3. The secondary texture sprite should be placed in the same position as the source Sprite. (UVs must match).
  4. If some source sprites have secondary textures and some don’t, secondary atlas will still be created for all the sprites.

2D Renderers (SpriteRenderer / TilemapRenderer / SpriteShapeRenderer):

  1. Automatically will setup the Texture properties in the material automatically based on Secondary Textures.
  2. Supported by both Built and URP-2D.

UI/Image:

  1. Secondary properties may not automatically be set.
  2. If SpriteAtlas is indeed required with Secondary textures for UI images,
  1. either the Secondary textures may need to be set in Material (with manual packing with exact UV alignment)
  2. or set the secondary textures to the material through scripting (GetSecondaryTextures)