2D Toolkit Forum
2D Toolkit => Support => Topic started by: Afro-Ninja 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.
-
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.
-
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...
-
which .cs file is that found in?
-
tk2dTileMapMeshBuilder.cs
-
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.
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
chunk.mesh.RecalculateNormals();
TangentSolver.Solve(chunk.mesh);
Works like a charm,
Maybe you could implement this code into the next update.
-
Hi there,
Thanks! I'll look into this.
-
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.
-
I'm not sure but I think it might be this -
https://github.com/danielbuechele/SumoVizUnity/blob/master/Assets/Helper/TangentSolver.cs
-
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.
-
Worked a treat. Looks exactly as I'd hoped. Thanks for all the help with this.
(https://dl.dropboxusercontent.com/u/43129774/lighting%20example%202.PNG)