Hello Guest

Author Topic: Sprite/Atlas shader with normals?  (Read 7096 times)

windjammers

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 7
    • View Profile
Sprite/Atlas shader with normals?
« on: October 02, 2015, 02:03:18 pm »
I have a normal map that matches my sprite collection atlas. Is there a 2dtk-centric way to apply this normal map to my sprites?

edit: The closest I get to the results I want are as follows.

1) Shaders: Using either the Unity standard shader or one provided with Sprite Lamp (the tool I use to generate my normal maps) I get tiles that are lit properly providing I don't flip or rotate them. If I do the tile tile rotates properly, as does the normal map, but the lighting is wrong. It responds to light as though it hasn't rotated or flipped, as though lighting is rendered first.

2) Using the tilemap settings data tab I can add gameobjects to each tile that contain the correct sprite with normals. This works up to a point. There are a few major problems though. Firstly I can't see how the level is lit in the scene editor. I have to run it to see this. Secondly it doesn't work consistently, with added gameobjects frequently having the wrong rotation/scale. Finally, I don't think this is an efficient way to do things, as I have read elsewhere on the forum that 2dtk doesn't like caching gameobjects with non-uniform scale/rotation.

I've seen on the roadmap that there's some support for sprite collections with normals to be added, but I'm looking for a robust solution in the meantime that someone with my slightly wobbly game dev. skills can impliment. :)
« Last Edit: October 02, 2015, 02:34:02 pm by windjammers »

windjammers

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: Sprite/Atlas shader with normals?
« Reply #1 on: October 04, 2015, 02:19:37 pm »
Here's an image to illustrate the problem.

The tile in the top0left is the tile as it should be. The top-right shows the tile in normal, x-flip, x-flip and both x and y flipped forms. Note that the lighting is the same for all four tiles.

The bottom row of tiles are as follows:
Tilemap tile in normal rotation.
Gameobject with similar material. Normal rotation.
Tilemap tile, 90 degree rotation.
Gameobject with similar material. 90 degree rotation.

Hopefully that makes the issue a little clearer.


windjammers

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: Sprite/Atlas shader with normals?
« Reply #2 on: October 05, 2015, 03:41:21 pm »
With this thread I've managed to get it working. Kind of...

I've given up on having tilemap diffuse/tilemap normals working. There's no way without going deep into coding, and there doesn't seem to be a 2dtk implementation coming any time soon. As such I'm having a simple tileset add gameobjects with working diffuse and normal mapped sprites. This works fine so long as I don't use rotate 90 degrees while building anything in the tileset editor and will have to do.

The unfortunate downside to this is that it the gameobjects added don't match the flip/rotation of their spawning point tile, which is annoying. It seems to vary on a tile by tile basis which combination of rotation and x/y flip will give incorrect results. At this stage I'm considering another tilemap drawing solution (a real downer having already bought 2dtk.)


« Last Edit: October 05, 2015, 04:05:32 pm by windjammers »

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Sprite/Atlas shader with normals?
« Reply #3 on: October 06, 2015, 10:27:50 am »
Tilemaps don't have tangents, thats probably why they're looking dodgy. check this page for a solution http://2dtoolkit.com/forum/index.php/topic,4197.msg23806.html#msg23806

Sprites are a different matter, they should just work.

windjammers

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: Sprite/Atlas shader with normals?
« Reply #4 on: October 07, 2015, 12:53:24 pm »
Cheers for that. It does seem to be exactly what I'm looking for. I can't see a link to the TangentSolver.cs file the post by TheCosmicBoy is referring to but I expect I'll see it once my 2dtk purchase is registered or something like that.