Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Secondary Textures" - Normal Map Support #18

Open
bitblip opened this issue Nov 30, 2019 · 17 comments
Open

"Secondary Textures" - Normal Map Support #18

bitblip opened this issue Nov 30, 2019 · 17 comments

Comments

@bitblip
Copy link

bitblip commented Nov 30, 2019

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
Copy link

haywirephoenix commented Dec 24, 2019

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
Copy link
Owner

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
Copy link
Owner

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
Copy link

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

@martinhodler
Copy link
Owner

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
Copy link

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
Copy link

sballew commented Oct 11, 2020

@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
Copy link

johanolofsson commented Oct 11, 2020 via email

@johanolofsson
Copy link

johanolofsson commented Oct 11, 2020 via email

@sballew
Copy link

sballew commented Oct 12, 2020

@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
Copy link

sballew commented Oct 12, 2020

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
Copy link
Author

bitblip commented Oct 31, 2020

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

@johanolofsson
Copy link

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

@johanolofsson
Copy link

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
Copy link

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
Copy link
Author

bitblip commented Apr 30, 2022

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
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants