Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Pixel art light shader - Getting rid of specular?

Discussion in 'Shaders' started by Kashou, Feb 11, 2021.

  1. Kashou

    Kashou

    Joined:
    Sep 19, 2017
    Posts:
    12
    Hi, I hope this is the right place for Shader questions as well since it's heavily 2D related. I'm having some issues creating a pixel art light shader. I've been kinda frankensteining this together with approaches I've found around the internet, and it works mostly.

    It's supposed to be a flat color light with the amount of gradients limited by _Shades, which works, but only as long as a color channel is 0 or 1, anything in between causes color bleed in the middle and additional shades become visible. I'm not entirely sure where the issue is now, whether it's my code or some mode or something causing behavior that I'm unaware of.

    From what I've read there seems to be some specular added always to Unity light and I have had no luck disabling it or working around it with any methods I've found around the net.

    I know there are new 2D light functions but I both want to figure out these shaders, and I also think I want some more control than what I've seen from the 2D light system.

    On the left you can see how it's intended to look... more or less. 3 flat shades with "Light Shades" set to 3 regardless of size, but if you change any of the RGB channels to anything between 0 and 1, you get the one on the right.

    This is my current shader code: https://pastebin.com/hwhxCXca

    Another theory I had was that the pixels are being "hammered" multiple times due to the flooring, causing the small values in a color channel to get added together multiple times causing them to stack up to a full value towards the middle. But even then I'm not sure what to do. I saw some functions like clip() that skips an entire pixel, but if this is the case I'm at a loss as how to avoid drawing multiple times on the same spot.
     
    Last edited: Feb 11, 2021
  2. Kashou

    Kashou

    Joined:
    Sep 19, 2017
    Posts:
    12
    Actually figured it out.

    float attenuation = 1.0 / distance;

    This means attenuation will spike up again after distance goes below 1 which causes the light flare.

    Still welcome any other insights or comments though.