Hello Guest

Author Topic: 2D characters in 3D environment (with lights and bumpmapping)  (Read 25291 times)

The_Xperience

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 1
    • View Profile
2D characters in 3D environment (with lights and bumpmapping)
« on: December 17, 2012, 03:01:00 pm »
Hi everyone,

I'm relatively new to Unity and the 2D Toolkit. I'm looking into this and already purchased it to help me align the pixel art, but now run into some problems on the kind of game I want to create. While this Toolkit seems to be perfect for rendering classic 2D style games, I can't find a way to use more complex things like lighting, bumpmapping or  a 3D scenery. How can i use bumpmapping without dropping the advantages of the 2D tookit completely?

I'm thinking of games like Vessel (http://i21.photobucket.com/albums/b298/tman987/cave.png), maybe Lone Survivor (http://www.relyonhorror.com/wp-content/uploads/2012/10/loneipad.png)... lately I found the game Legend of Dungeon (http://www.kickstarter.com/projects/robotloveskitty/legend-of-dungeon), which is even made with Unity and has a style of mixing 2D and 3D with lighting, bumpmapping and all the stuff... i really do like the way it looks like, but can't think of a good way to achieve that look.

I'm grateful for any ideas on this, even if it means I have to drop the usage of the 2D Toolkit, since I have other ideas on using that one. :)

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: 2D characters in 3D environment (with lights and bumpmapping)
« Reply #1 on: December 17, 2012, 03:10:17 pm »
You could make 2D Toolkit work with bumpmapping but I've not considered that a priority as performance drops with bumpmapping on mobile devices is pretty hefty. I'll try to find some time to write up some instructions on setting this up at some point.

dakeese

  • 2D Toolkit
  • Jr. Member
  • *
  • Posts: 50
    • View Profile
Re: 2D characters in 3D environment (with lights and bumpmapping)
« Reply #2 on: December 18, 2012, 01:58:11 am »
I'm also interested in bump mapping sprites. I'm tinkering with a few different possible visual styles for my next project.

I think you can get away with bump mapping on small characters, especially on devices like the iPhone 4s and newer. If you're just doing small characters, it has only a small impact on fill, while you're still getting the benefits of low texture memory and draw calls. Environment lighting could be mostly baked in if you wanted to keep the environment bump-lit.

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: 2D characters in 3D environment (with lights and bumpmapping)
« Reply #3 on: December 18, 2012, 10:28:57 am »
The main problem with bumpmapping sprites is the requirement for 2 atlases to be generated in sync, one for the normals and one for colour channels. Significant resources will need to be spent on this to get it working properly, and that's before handling all the nasty edge cases.

In some cases, it might be beneficial to have 2 totally separate atlases for color & normal with 2 uv channels per sprite.

This is quite a large undertaking. Obviously it is easy to do something like this with constraints, but heavy constraints never work in a general purpose toolkit...

I'm kinda warming up to the idea of using external atlases directly - perhaps it might be possible to do this somehow that way.

dakeese

  • 2D Toolkit
  • Jr. Member
  • *
  • Posts: 50
    • View Profile
Re: 2D characters in 3D environment (with lights and bumpmapping)
« Reply #4 on: December 18, 2012, 06:57:29 pm »
Makes sense. I would imagine that the characters in that Legend of Dungeon were not made using a general purpose tool!

dredlockz

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: 2D characters in 3D environment (with lights and bumpmapping)
« Reply #5 on: March 31, 2013, 11:57:44 am »
I'm also interested in this. A friend suggested 2D Toolkit as a way to handle animations easily, but this is the only feature I'm missing currently.
I already have my character animation normal maps, like so:



These work pretty well when making my own materials, but I can't figure out a way to make it work with 2D Toolkit, changing the atlas material to "Bumped Diffuse" creates some artifacts in the sprites. And no other 2DTk materials seem to accept normal maps.

Regarding the Legend of Dungeon dude, he explained how he did it here:

http://robotloveskitty.tumblr.com/post/33164532086/legend-of-dungeon-dynamic-lighting-on-sprites

He made his own animation scripts, i'm wondering if I should do my own too, or is there/ will there be a way for 2D Toolkit to work with normal maps?

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: 2D characters in 3D environment (with lights and bumpmapping)
« Reply #6 on: March 31, 2013, 01:43:00 pm »
You can do this with Transparent / Bumped Diffuse - what artifacts were you getting?
You will need matching bumpmaps to the diffuse maps. This isn't supported directly, but you can get pretty decent results by following these steps;
http://unikronsoftware.com/2dtoolkit/forum/index.php/topic,1143.0.html

Theres a bit of manual input required (i.e. keeping the 2 sprite collections in sync.) You will also have to disable trimming unless you can ensure your normal maps have the same alpha channel as the diffuse.

If there is enough interest I can obviously add it as a core feature, but this isn't exactly a widely requested feature.

dredlockz

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: 2D characters in 3D environment (with lights and bumpmapping)
« Reply #7 on: March 31, 2013, 02:29:55 pm »
Hey Unikron,
thanks for your response.

When I try opening the link you gave me I get an "The topic or board you are looking for appears to be either missing or off limits to you." Do I need some sort of permission for it?

As for the artifacts, the problem was I wasn't using transparent/ Bumped Diffuse, I mistakenly set just Bumped Diffuse. So that fixed it :)
The only issue I have now is that the atlases for the normal and the diffuse are not matching, so it looks like this:



(The one on the left is a regular plane with a transparent/ bumped diffuse texture, the one in the right is animated with 2DToolkit)

Thanks for the tips, I'll check the trimming and whatnot, and keep you posted. If I manage to get this working I will definitely buy 2DToolkit, other that this minor fringe feature it works really well, keep up the good work :)

Edit: Success!
Apparently when I dragged&dropped all the textures to create the sprite collection, the order in which they were added to the collection was different between the diffuse and the normal maps so the sprites had different IDs assigned to them and were in different order in their respective Atlases. So I added them in order again one by one, and then they were in sync.

Thanks!
« Last Edit: March 31, 2013, 03:37:13 pm by dredlockz »

Martin

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 17
    • View Profile
Re: 2D characters in 3D environment (with lights and bumpmapping)
« Reply #8 on: March 31, 2013, 09:02:57 pm »
Also interested in normal map for our next project!

dredlockz

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: 2D characters in 3D environment (with lights and bumpmapping)
« Reply #9 on: April 01, 2013, 02:00:15 pm »
Here's the final result for anyone else interested (needs unity web player)

http://alessandroituarte.com/labs/PaperMario/

So definitely doable with 2D Toolkit! Just need to make sure the normal map animations are completely in sync with the diffuse texture

profanicus

  • 2D Toolkit
  • Full Member
  • *
  • Posts: 167
    • View Profile
Re: 2D characters in 3D environment (with lights and bumpmapping)
« Reply #10 on: July 01, 2013, 02:26:32 pm »
Count me in as another party keen on normal map support for atlases. Or some kind of arbitrary multi-atlas per sprite feature so I can dream about spec and emissive maps as well. :)

Anyway, back to reality - my current experiments have lead me to use normal mapping on tilemaps, and today's issue is that tangents are not generated for tilemaps like they are for sprites.

Any advice on how to go about adding this? For now I have just added a generic algorithm I found on Unity Answers that calculates them for the whole mesh, but it's not ideal. Since the tangents already exist for the individual sprites, is there a better way to get those onto the final tilemap mesh?

bitcrusher

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: 2D characters in 3D environment (with lights and bumpmapping)
« Reply #11 on: July 01, 2013, 04:20:58 pm »
Your site is down dred.  +1 for interest.

profanicus

  • 2D Toolkit
  • Full Member
  • *
  • Posts: 167
    • View Profile
Re: 2D characters in 3D environment (with lights and bumpmapping)
« Reply #12 on: July 02, 2013, 12:02:04 am »
Initially I just manually made a normal map from a duplicate of the generated atlas texture, but to do it properly I'm now following these instructions from another thread on a similar topic:
Duplicate the sprite collection (not the data object), open the duplicate, go into sprite collection settings, "Clear references" and Commit. You should get a second "Data" folder. Go through the list and switch all textures to the normal maps. Make sure the sprite dimensions are identical.

Problem is, 'Clear References' destroyed both the copied and original collections, and now they give "IndexOutOfRangeException: Array index is out of range.
tk2dSpriteCollectionBuilder.UpdateVertexCache (.tk2dSpriteCollection gen, Single scale, tk2dEditor.Atlas.Data[] packers, .tk2dSpriteCollectionData coll, System.Collections.Generic.List`1 spriteLuts) (at Assets/TK2DROOT/tk2d/Editor/Sprites/tk2dSpriteCollectionBuilder.cs:1685)" whenever trying to use them.

I think it may be related to my original collection having multiple materials, as all the materials got wiped as well. I realise this isn't really supported stuff, and am posting it more as a warning for anyone else looking to do similar.

edit: on second thoughts this is probably a bit of a nasty bug - it is easily reproduced by duplicating a collection that uses 2 materials, opening the new collection, 'Clear References' and committing. I am using the pre-release tilemap version.
« Last Edit: July 02, 2013, 12:16:34 am by profanicus »

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: 2D characters in 3D environment (with lights and bumpmapping)
« Reply #13 on: July 02, 2013, 10:37:30 am »
I'll investigate the clear references issue. It looks like its a bug.

profanicus

  • 2D Toolkit
  • Full Member
  • *
  • Posts: 167
    • View Profile
Re: 2D characters in 3D environment (with lights and bumpmapping)
« Reply #14 on: July 02, 2013, 11:19:45 am »
Any thoughts on the tilemap tangents implementation from my earlier question in the thread? I voted on Trello but not sure there will be universal excitement for the feature. :(

For now I have just added a generic algorithm I found on Unity Answers that calculates them for the whole mesh, but it's not ideal. Since the tangents already exist for the individual sprites, is there a better way to get those onto the final tilemap mesh?