Hello Guest

Author Topic: Proper steps for bump-map lighting on a tilemap?  (Read 8581 times)

Afro-Ninja

  • 2D Toolkit
  • Jr. Member
  • *
  • Posts: 62
    • View Profile
Proper steps for bump-map lighting on a tilemap?
« on: June 22, 2014, 09:27:20 pm »
I've searched and found a lot of topics on the subject but sometimes it's hard to figure out what is the most up to date method.
I have a collection that I use only for tiles, and I would like to apply a normal map shading technique to it.
Here's what I have done so far:

1. I set the normal generation for the collection to "normals and tangents"
2. I duplicated the collection's atlas and turned it into a normal map, and UNchecked 'create from grayscale' (the map has a blue hue to it)
3. I changed the collection's shader to unity's 'transparent - bumped diffuse' and applied my new normal map to it.

It certainly changed the way the lighting looks, but something is just odd about it. I move my lights around and the shadows don't really fill in like I would expect.

Should I be taking a different approach? Thanks.

Afro-Ninja

  • 2D Toolkit
  • Jr. Member
  • *
  • Posts: 62
    • View Profile
Re: Proper steps for bump-map lighting on a tilemap?
« Reply #1 on: June 23, 2014, 07:10:16 pm »
as a side note, it seemed like I could get this working on a stand-alone sprite that wasn't part of a tilemap. It's not a big priority, just something I was curious about. If this is a large undertaking you don't need to go into specifics.

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Proper steps for bump-map lighting on a tilemap?
« Reply #2 on: June 23, 2014, 08:54:07 pm »
I wrote a reply to this but must've forgotten to send :(
The tilemap doesn't generate tangents, you can get it to generate tangents by doing that after this line -
chunk.mesh.RecalculateNormals();
The tangents should be calculated using the UVs, but you can simply use any vector perpendicular to the normal...

Afro-Ninja

  • 2D Toolkit
  • Jr. Member
  • *
  • Posts: 62
    • View Profile
Re: Proper steps for bump-map lighting on a tilemap?
« Reply #3 on: June 23, 2014, 08:56:53 pm »
which .cs file is that found in?

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Proper steps for bump-map lighting on a tilemap?
« Reply #4 on: June 23, 2014, 09:04:35 pm »
tk2dTileMapMeshBuilder.cs

thecosmicboy

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Proper steps for bump-map lighting on a tilemap?
« Reply #5 on: September 16, 2015, 03:58:50 pm »
Any chance this could be elaborated on?

To calculate the normals in the tk2dSpriteCollectionBuilder.cs
it contains these lines after the normals are recalculated to calculate the tangents.
Quote
                            tmpMesh.RecalculateNormals();
               
               coll.spriteDefinitions.normals = tmpMesh.normals;

               if (gen.normalGenerationMode == tk2dSpriteCollection.NormalGenerationMode.NormalsAndTangents)
               {
                  Vector4[] tangents = new Vector4[tmpMesh.normals.Length];
                  for (int t = 0; t < tangents.Length; ++t)
                     tangents[t] = new Vector4(1, 0, 0, -1);
                  coll.spriteDefinitions.tangents = tangents;
               }


I have found "chunk.mesh.RecalculateNormals();" inside the tile tk2dTileMapMeshBuilder.cs
but I am unsure of how to apply the simple tangent code above to the TileMap.

Any help would be greatly appreciated :)

Edit : I have solved the problem by using the attached script called "TangentSolver.cs"
and implementing this line of code "TangentSolver.Solve(chunk.mesh);"
inside the tile tk2dTileMapMeshBuilder.cs script just after the normals are recalculated.

Like so

Quote
chunk.mesh.RecalculateNormals();
         TangentSolver.Solve(chunk.mesh);

Works like a charm,
Maybe you could implement this code into the next update.
« Last Edit: September 16, 2015, 04:18:53 pm by thecosmicboy »

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Proper steps for bump-map lighting on a tilemap?
« Reply #6 on: September 17, 2015, 11:26:32 pm »
Hi there,
Thanks! I'll look into this.

windjammers

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: Proper steps for bump-map lighting on a tilemap?
« Reply #7 on: October 08, 2015, 09:02:27 am »
I notice that the file uploaded is a .meta file rather than the associated .cs file.I have a similar problem with tilemap bumpmaps and would love to see the code used to fix it.

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Proper steps for bump-map lighting on a tilemap?
« Reply #8 on: October 08, 2015, 10:50:19 pm »

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Proper steps for bump-map lighting on a tilemap?
« Reply #9 on: October 08, 2015, 10:52:39 pm »
I'm not sure but I think it might be this -
https://github.com/danielbuechele/SumoVizUnity/blob/master/Assets/Helper/TangentSolver.cs

It isn't the same code but should work in principle, TangentHelper.TangentSolver(chunk.mesh) in this case.

windjammers

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: Proper steps for bump-map lighting on a tilemap?
« Reply #10 on: October 09, 2015, 01:41:35 pm »
Worked a treat. Looks exactly as I'd hoped. Thanks for all the help with this.