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

Question 2D Solid-Color Shading With Pixel Art

Discussion in 'Shaders' started by tylerroman95, Nov 2, 2021.

  1. tylerroman95

    tylerroman95

    Joined:
    Jul 27, 2021
    Posts:
    2
    Hi all,

    I've been trying to get this to work to no avail the past couple of days.

    Essentially, I want to achieve something like a cel/toon shader to apply to any given 2D sprite which has a normal map attached to it. So far, I've tried a couple 3d tutorials and resources for toon shading, but for one reason or another they just don't work when I try to convert them over to 2D, specifically trying to leverage all the cool features for pixel art Unity has started relatively recently supporting.

    I've got what I want working 95% of the way there in Godot:
    (light from top right)

    (light from bottom left)


    However, in Godot lighting affects sprites before anything like skeleton deformations. This is why I decided to switch over to Unity, since I quickly discovered that light calculation happens after such deformations. However again, I can't seem to get the same method I used in Godot to achieve the pixel-perfect cel shading above to work in Unity. Specifically, at least the Unity graph shader seems to lack any control of how the light is actually calculated at all. I've had the barest success in changing how this is done on a normally written shader, but honestly I've had some trouble wrapping my head around that since it doesn't seem as straight-forward as modifying the fragment shader in openGL/webGL program, as is the case in Godot. (For reference, I copied the Sprite-Lit-Default shader and tried to modify it to suit my needs.) If the answer is simply that I must learn how to properly program shaders in Unity, that's fair enough, but I don't know enough to be able to tell that's my principal problem or if there's something painfully simple that I'm missing in the graph shader.

    In short, what I'm seeing in unity is (render at runtime):

    And what I want is (manual edit):


    Given none of my shaders have gotten close to what I want, I don't think posting any of them would be productive. If you have any tips or resources, I'd be greatly appreciated if you share them. Thank you for your time.
     
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,329
    You want a cel-shading shader. Unfortunately Unity's Shader Graph does not make using custom shading models easy. You can search for "URP Shader Graph Cel-Shading" and try to follow some of those tutorials to see if you can get something, but I believe the URP 2D renderer does lighting completely differently than URP's 3D renderer and I don't know of any tutorials that are written for the 2D renderer.

    You might be better off using the default renderer rather than the URP 2D renderer, as there's a better chance you'd be able to find a working cel-shading shader that works for that.
     
  3. tylerroman95

    tylerroman95

    Joined:
    Jul 27, 2021
    Posts:
    2
    yeah, after some time that's the sense I get as well. I already have this *mostly* how I like it in Godot, but it's a bit tedious to set up. I was hoping that it'd be easier to do in Unity and I might be able to leverage some extra shiny features from the URP 2D pixel art packages with it. Oh well. Thanks for responding!
     
  4. SenorWalter

    SenorWalter

    Joined:
    Mar 14, 2017
    Posts:
    1
    Hey, have you found a solution for the solid color problem? Im having the exact same problem!