Search Unity

  1. We are migrating the Unity Forums to Unity Discussions by the end of July. Read our announcement for more information and let us know if you have any questions.
    Dismiss Notice
  2. Dismiss Notice

Question Sprite Custom Lit Normal Calculation

Discussion in 'Shader Graph' started by theseal53, Apr 14, 2024.

  1. theseal53

    theseal53

    Joined:
    Oct 29, 2017
    Posts:
    7
    Hi all,

    I'm working on a Sprite Custom Lit Shader Graph that mixes unlit portions for emissions/bloom, and lit portions that interact with lights. I've got it working... mostly.

    When trying to apply normals, I'm finding that the unlit pixels are still interacting with the normal map, giving some undesired effects. Because of this, I expect that I'll need to implement my own calculation of how normals are applied.

    Is there a way in shader graph to get what overall direction the light is coming from? If so, I think I could come up with a good solution to negate normal lighting for specific pixels.

    Thanks for your help!


    Current shader graph


    No normals applied. Emission looks good


    Normals applied. Emission is a little borked
     
    Last edited: Apr 14, 2024
  2. theseal53

    theseal53

    Joined:
    Oct 29, 2017
    Posts:
    7
    Bumping this, it would be helpful to know even if it's not possible
     
  3. Qriva

    Qriva

    Joined:
    Jun 30, 2019
    Posts:
    1,356
    What is overall light direction? You can get main light no problem (custom node), you can also get additional lights, but you need loop, and well, there is no "overall" direction for multiple directions.
     
  4. theseal53

    theseal53

    Joined:
    Oct 29, 2017
    Posts:
    7
    Gotcha, thanks! I was hoping there would be something like a "normal texture" node like there's a "light texture" node, but it sounds like that's not how things work.

    Would the loop look something like this? (making this up pretty limited knowledge)

    Get light -> Check if uses normals -> Calculate intensity at distance -> Calculate direction to pixel -> Find dot product of direction and normal -> Subtract (intensity - intensity * dot product) from light texture

    Ultimately, I'm just trying to nullify normal calculations on some pixels, and setting the dot product to 1 on those seems like it would do the job
     
    Last edited: Apr 21, 2024
  5. Qriva

    Qriva

    Joined:
    Jun 30, 2019
    Posts:
    1,356
    I have no experience with 2D Lit, but it's a bit strange there is no emission output.

    In any case you can hack it by changing (lerping) between normals. You use your emission mask to find if that pixel should work like Lit or not. You can use step() to create hard threshold or use the actual opacity of the mask and lerp between texture normals and default normals.
     
  6. theseal53

    theseal53

    Joined:
    Oct 29, 2017
    Posts:
    7
    Oh yep, I've got some lerping going on in my graph right now (the Blend node). Unfortunately, it looks like there's some normal map logic still being applied even when I completely blank out the pixels that should be unlit. My guess is that the blank pixels on the normal map are being interpreted as directly facing the camera