sprite-dicing icon indicating copy to clipboard operation
sprite-dicing copied to clipboard

Add support secondary textures

Open Creta5164 opened this issue 7 months ago • 8 comments

Hello.

It's been quite some time since we decided to adopt this asset, and thanks to it, we've been able to effectively optimize our game.

One thing I find drawback is that it doesn't support secondary textures, which are supported by Unity Atlas.

Of course, I understand that this package wasn't originally created for 2D sprites within a game space, but still, as a personal wish, I hope this feature could be supported.

Specs to define

Support secondary textures for SpriteDicing.

Note

Recently, while frequently using SerializedObject, I discovered that the Sprite asset (or Importer) has a spriteSheet property, and within this, the secondaryTextures property references a Texture type, not a Sprite type.

Considering that Unity Atlas also generates an atlas where secondary textures are drawn based on the same sprite positions as the original atlas texture, it seems it should work simply by passing a texture with the secondary texture applied to the same UV coordinates.

However, since dicing atlases have the characteristic of grouping duplicate pixel chunks into one, I am concerned about how effectively this can be applied and what edge cases might exist.

...It's like when C++ code imports C# code for AOT compilation, resulting in very verbose code.

Creta5164 avatar Aug 31 '25 13:08 Creta5164

Okay translator makes it disrespectful description, sorry for that.

Creta5164 avatar Aug 31 '25 13:08 Creta5164

Something like this?

I'm not familiar with the spriteSheet property, but if it's just a matter of using that instead of assigning the main texture directly - should be straightforward.

elringus avatar Aug 31 '25 14:08 elringus

Though I guess a separate Secondary Textures list won't work, because there have to be mapping between main and secondary textures. This will probably require a custom drawer for the textures that will allow assigning multiple textures per entry.

elringus avatar Aug 31 '25 14:08 elringus

I'm not familiar with the spriteSheet property, but if it's just a matter of using that instead of assigning the main texture directly - should be straightforward.

Recently, while frequently using SerializedObject, I discovered that the Sprite asset (or Importer) has a spriteSheet property, and within this, the secondaryTextures property references a Texture type, not a Sprite type.

Image

@elringus I might mislead information here, it's secondaryTextures property in m_RD/m_AtlasRD in Sprite, you can find in generated sprite asset file.

However, please note that these properties are not documented as they are handled internally by the engine. Therefore, when attempting this, I suggest verifying first. If it proves impossible, perhaps we could close this issue.

Creta5164 avatar Aug 31 '25 14:08 Creta5164

Image

https://github.com/user-attachments/assets/8d622dd6-39c3-48ea-a313-39903773e889

Update : I've confirmed that it's working, we can use texture and name property inside of secondaryTexture both of m_RD and m_AtlasRD.

However, since it's not documentated, we should take care about what we should use or not m_RD or m_AtlasRD.

Creta5164 avatar Aug 31 '25 14:08 Creta5164

Secondary textures are typically used to convey additional information for Sprite graphics processing, such as ‘normal maps’ or ‘palette maps,’ by utilizing separate textures.

Therefore, this feature is particularly necessary, and Unity Atlas actually supports it.

However, as mentioned earlier, it must pack with careful consideration of the Dicing atlas's characteristic of grouping and compressing duplicate chunk pixels. When doing so, it is expected that cases may occasionally arise where pixels appear duplicated in the main texture but are not duplicated due to secondary textures. I believe this requires particular attention.

Creta5164 avatar Aug 31 '25 14:08 Creta5164

I think secondary maps should go into their own atlas textures. Mixing them with the main textures is asking for trouble.

elringus avatar Aug 31 '25 14:08 elringus

I think secondary maps should go into their own atlas textures. Mixing them with the main textures is asking for trouble.

Yes exactly, so Unity atlas does separate them into serveral textures, from main to extras so we should consider this when feature got implemented.

Creta5164 avatar Aug 31 '25 15:08 Creta5164