Hello Guest

Author Topic: Lighting not working properly on sprite  (Read 7118 times)

Pixotic

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 9
    • View Profile
Lighting not working properly on sprite
« on: February 22, 2014, 06:58:33 am »
I have a tilemap and a sprite in my scene, along with a point light. The tilemap is lit by both ambient lighting and the pointlight, but the sprite is unaffected by the pointlight. The spritecollection's settins for the sprite in question have the correct normal mode (normal only) and the shader material tk2d/LitBlendVertexColor (same as is on the tilemap chunks). The sprite appears to be lit by the ambient lighting of the scene and matches the light level when there's no pointlight, I'm a bit confused as to why this isn't working :P

Here's a short youtube clip illustrating the issue: https://www.youtube.com/watch?v=TwCNFieU31Y

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Lighting not working properly on sprite
« Reply #1 on: February 22, 2014, 12:46:02 pm »
Does it work ok when using a normal Unity diffuse shader? LitBlendVertexColor is vertex lit, though I would expect some change when you're dragging it about there. Also z distance wise, is it further away from the light?

Pixotic

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: Lighting not working properly on sprite
« Reply #2 on: February 22, 2014, 07:46:05 pm »
No, no change in lighting when using a standard Diffuse shader. Z-wise, the point light is at -0.65, sprite at -1 and tilemap at 0. I've tried adjusting the z of the pointlight but it had no effect on lighting the sprite.

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Lighting not working properly on sprite
« Reply #3 on: February 22, 2014, 10:35:38 pm »
Can you post a repro for this? Based on your description I don't see any reason it shouldn't work.

Pixotic

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: Lighting not working properly on sprite
« Reply #4 on: February 22, 2014, 11:39:32 pm »
Here are the steps I've taken to reproduce the issue:

Make a new scene, delete default camera
Create tk2dCamera, tk2dTileMap, tk2dSprite
Switch tk2dCamera's Camera -> Rendering path from player settings to vertex lit
Ensure that sprite collections for the tilemap and sprite have Normal Mode set to Normals only
Adjust ambient scene lighting to a low setting
Change shader material on tilemap chunks and sprite to tk2d/LitBlendVertexColor, confirm there is difference in light shading
Add Point Light to scene, move it around, observe lighting on tilemap and sprite

I recorded myself doing these steps so you can see my results: https://www.youtube.com/watch?v=Sy4tSO2bAzY

After recording this I made a brand new spritecollection with a spare texture file I had and it actually worked! So clearly there's something wrong with the sprirecollection I'm trying to use but I guess I don't know enough about tk2d to identify it straight away. Maybe there's something you can see in the sprite editor (I show it near the end of the video) that I'm missing?

Pixotic

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: Lighting not working properly on sprite
« Reply #5 on: February 23, 2014, 12:07:01 am »
This is bizarre. I thought it was an issue with the specific sprite collection I was using, but making a basic gameobject with a tk2dsprite using that sprite collection worked just fine. I created a new player prefab using -exactly- the same components as the existing prefab and it works perfectly with my scene's lighting.

I'm glad I've solved the problem but I wish I knew what caused it...

Pixotic

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: Lighting not working properly on sprite
« Reply #6 on: February 23, 2014, 01:27:07 am »
I'm not sure if this warrants a new thread or it's preferable to keep it in this one, but there's an odd problem now with my tilemap having a weird grid visible in both the scene view and game view even while the game isn't running - here's a screengrab: http://imgur.com/Z03crfo

The texture used in the sprite collection is seamless, the sprite collection settings have Extend pad mode with no extra padding, so I'm at a loss as to what I did to mess it up.

Any ideas?

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Lighting not working properly on sprite
« Reply #7 on: February 23, 2014, 01:36:10 am »
Try extend with SOME extra padding. You absolutely need padding if you're using bilinear, might get away with it if point filtering.

Pixotic

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: Lighting not working properly on sprite
« Reply #8 on: February 23, 2014, 01:41:16 am »
Yeah it's all point filtering. Gotta have that pixelly goodness...

Problem goes away if I use 'good' or lower quality setting. I tried adding some padding before I found the quality setting thing but it didn't seem to help.

I tried again, y'know, for science, set quality to fantastic, go to the spritecollection with my tiles in it, change Extra padding to 1, apply, commit, no change. Set it to 16, apply, commit, no change.

Pixotic

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: Lighting not working properly on sprite
« Reply #9 on: February 23, 2014, 01:45:09 am »
Further experimentation reveals that it's the anti-aliasing causing it.