martinhodler / unity-aseprite-importer

An aseprite-file importer for unity written in C#, built upon the experimental AssetImporter API
GNU General Public License v3.0
321 stars 48 forks source link

"Secondary Textures" - Normal Map Support #18

Open bitblip opened 4 years ago

bitblip commented 4 years ago

I'm playing with the upcoming unified render pipeline 2D lights and find I'm back to having to export from aseprite manually. I need to add the normal map to the "Secondary Textures" using the sprite editor and I don't see a way to access this while using the importer.

haywirephoenix commented 4 years ago

I second that, can't figure this out either. For now create a material and set the shader to Sprite-lit-default. You can drag the normal map in there.

martinhodler commented 4 years ago

I tried to use the SpriteEditor from Unity to be able to set borders, make changes to the spritesheet and so on but Unity is hiding this editor in their own code which makes this much harder... I will see what I can do.

martinhodler commented 4 years ago

I'm working on it right now. I was able to support the sprite editor... there is some work to do that all of it's features work with the importer

johanolofsson commented 4 years ago

Hi, im basically doing the same thing for PyxelEdit. Did you ever figure this out?

martinhodler commented 4 years ago

yes there is an implementation in the sprite-editor branch. It has still some issues but you can use the sprite package from unity and include the classes you need in your package. I didn't had the time to completely implement it but you should be able to do it. There is a DataProvider for the SecondaryTexture.

johanolofsson commented 4 years ago

Oh awesome, yes I made it work. Was sufficient to simply use the TextureGenerator and provide the right stuff including the secondary textures. Works really well in tilemaps now! Thx for pointing me in the right direction!

sballew commented 3 years ago

@johanolofsson Do you have any code snippets you could share where you use TextureGenerator? Documentation on this is difficult and I have yet to get it working.

I'm trying to find a way to have unity-aseprite-importer detect a metadata layer, like @normal or @emission, and then set it as a secondary texture. No luck yet. @martinhodler Do you have any thoughts on how to approach it?

johanolofsson commented 3 years ago

Yes, this sure isn't easy to setup right out of the box! :)

What you need to do is to use UnityEditor.Experimental.AssetImporters.TextureGenerator.GenerateTexture() and provide it a TextureGenerationSettings object. This settings object has a member called secondarySpriteTextures in which you can set your additional textures.

Hope this puts you in the right direction!

Good luck!

/JO

On Mon, Oct 12, 2020 at 12:00 AM Sean Ballew notifications@github.com wrote:

@johanolofsson https://github.com/johanolofsson Do you have any code snippets you could share where you use TextureGenerator? Documentation on this is difficult and I have yet to get it working.

I'm trying to find a way to have unity-aseprite-importer detect a metadata layer, like @normal or @emission, and then set it as a secondary texture. No luck yet. @martinhodler https://github.com/martinhodler Do you have any thoughts on how to approach it?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/martinhodler/unity-aseprite-importer/issues/18#issuecomment-706767513, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABCA46JLU6OUJXKZNXLTHILSKIMHZANCNFSM4JTHT5UA .

johanolofsson commented 3 years ago

Oh sorry Martin, my have replied to u instead of a guy asking a question :)

On Mon, Oct 12, 2020 at 12:30 AM Johan Olofsson johan.olofsson@bitbound.se wrote:

Yes, this sure isn't easy to setup right out of the box! :)

What you need to do is to use UnityEditor.Experimental.AssetImporters.TextureGenerator.GenerateTexture() and provide it a TextureGenerationSettings object. This settings object has a member called secondarySpriteTextures in which you can set your additional textures.

Hope this puts you in the right direction!

Good luck!

/JO

On Mon, Oct 12, 2020 at 12:00 AM Sean Ballew notifications@github.com wrote:

@johanolofsson https://github.com/johanolofsson Do you have any code snippets you could share where you use TextureGenerator? Documentation on this is difficult and I have yet to get it working.

I'm trying to find a way to have unity-aseprite-importer detect a metadata layer, like @normal or @emission, and then set it as a secondary texture. No luck yet. @martinhodler https://github.com/martinhodler Do you have any thoughts on how to approach it?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/martinhodler/unity-aseprite-importer/issues/18#issuecomment-706767513, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABCA46JLU6OUJXKZNXLTHILSKIMHZANCNFSM4JTHT5UA .

sballew commented 3 years ago

@johanolofsson Thanks, conceptually it makes sense, but I'm not sure how to actually use TextureGenerator.GenerateTexture. There's no usage documentation on it. Any tips on how to use it in the context of an importer?

sballew commented 3 years ago

I got it working. I have a fork of unity-aseprite-importer here: https://github.com/sballew/unity-aseprite-importer/blob/master/Editor/AseFileImporter.cs#L104

I have a number of fixes in my fork, including support for secondary textures. I'll look at doing a PR, however I did do a Unity 2020.2 upgrade on the fork.

The approach I took lets the user specify a layer like @secondary(_Emission). This layer then generates a Texture2D for those layer frames, and then assigns it as a secondary texture with the name _Emission. This would work for any name that the user wants to assign.

I also added some layer name shortcuts for common secondary texture names. Right now it's @emission and @normal, which map to @secondary(_Emission) and @secondary(_NormalMap).

bitblip commented 3 years ago

After upgrading 2020 your fork worked like a charm, exactly what I was looking for.

johanolofsson commented 3 years ago

Has anyone tried this in 2020.2? It works fine for me in 2020.1.x but in 2020.2 it stops working.

johanolofsson commented 3 years ago

Ok, so the problem seems to be that as of 2020.2 the rendering of sprites will ignore pixels which have alpha=0 in the main texture, regardless of what colors the same pixel has in secondary textures. In my case I had emissive pixels with colors but transparent in main. I fixed it by simply putting a=1 in the main texture where there is emissive. Not a perfect solution but it works. I don't really know why this behavior suddenly appears. Maybe it's some kind of optimization in the URP and if it is in some way configurable. If someone figures it out, pls let me know :)

KevinRoussel commented 3 years ago

Hello @sballew ! I'm trying to use exactly this feature. I'm using Unity 2020.3 LTS and the fork doesn't work for me, the inspector is broken on .ase files. Do you know if it should be working on this version ?

bitblip commented 2 years ago

The importer has improved quite a lot. Access to the sprite editor at least now makes it possible to use the importer and access extra layers. I'd still love to see support for special layer names that are written to secondary sprite layers. Something similar to how run, walk and idle tags get special animation treatment.

CarlisleJonah commented 1 year ago

I made a fork with secondary texture support for my own personal use. I don't plan to provide support for it but here it is if anyone wants it. Currently working on Unity 2022.1.23f1: https://github.com/CarlisleJonah/unity-aseprite-importer

Any layer name that begins with @ (except for @transform which is reserved) will be imported as a secondary texture (with the @ removed).

I haven't added support for Tilesets or Bundled sprite because I don't need them, but it shouldn't be too difficult to see the changes I made to GeneratedSpriteImporter.cs and make similar changes to GeneratedTileImporter.cs and BundledSpriteImporter.cs.