Hello Guest

Author Topic: TileMap Lighting  (Read 7764 times)

johntvolk

  • Newbie
  • *
  • Posts: 7
    • View Profile
TileMap Lighting
« 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

johntvolk

  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: TileMap Lighting
« Reply #1 on: January 23, 2013, 10:11:21 pm »
Oh, BTW, I'm using 1.80 final patch 3 from the Asset Store.

MaaS

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 39
    • View Profile
Re: TileMap Lighting
« Reply #2 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 :)

johntvolk

  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: TileMap Lighting
« Reply #3 on: January 25, 2013, 08:31:12 pm »
Thanks, MaaS! I'll give it a try.

johntvolk

  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: TileMap Lighting
« Reply #4 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

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: TileMap Lighting
« Reply #5 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.

johntvolk

  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: TileMap Lighting
« Reply #6 on: January 31, 2013, 07:22:09 pm »
Thanks! I may give it a shot.