2D Toolkit Forum

2D Toolkit => Support => Topic started by: johntvolk on January 23, 2013, 10:08:24 pm

Title: TileMap Lighting
Post by: johntvolk on January 23, 2013, 10:08:24 pm
Hi,

I'm wondering if TileMaps will get support for the lighting effects currently available for Sprites (or maybe that have it, but I don't know what I'm doing). I'm able to get light sources working with Sprites added to the scene (Set "Normals Only", change shader), but if I add a TileMap (even using the same SpriteCollection for which lighting works as a Sprite) all the tiles show up black. Thanks.

- John
Title: Re: TileMap Lighting
Post by: johntvolk on January 23, 2013, 10:11:21 pm
Oh, BTW, I'm using 1.80 final patch 3 from the Asset Store.
Title: Re: TileMap Lighting
Post by: MaaS on January 24, 2013, 12:14:39 am
Hi!

In tk2dTileMapMeshBuilder.cs, just comment this if, so the meshes have normals :

if (tileMap.serializeRenderData)
   chunk.mesh.RecalculateNormals();

to

//if (tileMap.serializeRenderData)
   chunk.mesh.RecalculateNormals();

This was previously answered here, but the file has changed (I'm using 1.9 beta 2)... http://unikronsoftware.com/2dtoolkit/forum/index.php/topic,880.msg4274.html#msg4274 :)
Title: Re: TileMap Lighting
Post by: johntvolk on January 25, 2013, 08:31:12 pm
Thanks, MaaS! I'll give it a try.
Title: Re: TileMap Lighting
Post by: johntvolk on January 30, 2013, 08:41:59 pm
MaaS,

I was able to mostly get this working. I do have one question, though. If I comment out that line so I get normals generated and change the shader, my tiles show up illuminated correctly in my scene. But the shader change messes up the tiles in the painting/data palette in the tilemap inspector (they become black). Is there a to have both work correctly (without swaping the shader all the time)? Thanks.

- John
Title: Re: TileMap Lighting
Post by: unikronsoftware on January 30, 2013, 11:35:14 pm
The shader turning black in the preview is pretty random. I've had it do weirder things...
I will be switching this to use a custom shader solution, similar to the animation editor - this will enable scrolling the tilemap, etc.
Until then, you could hack in a solution by going to tk2dTileMapBrushRenderer.cs, look for dictData.materials.SetPass(); - instead of setting this material, create a new material, set mainTexture & use that instead. That should fix it for you.
Let me know if you get stuck and I'll post some code when I'm back at my computer.
Title: Re: TileMap Lighting
Post by: johntvolk on January 31, 2013, 07:22:09 pm
Thanks! I may give it a shot.