Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Voting for the Unity Awards are OPEN! We’re looking to celebrate creators across games, industry, film, and many more categories. Cast your vote now for all categories
    Dismiss Notice
  3. Dismiss Notice

ToonFragment has strange rendering

Discussion in 'Shaders' started by Mehd, Feb 27, 2018.

  1. Mehd

    Mehd

    Joined:
    Apr 29, 2016
    Posts:
    91
    Hello,

    I already have a functionning surface shader for cel-shading effect. I wanted, for more insight in the field, write an equivalent using only vertex and fragment shader. I more or less managed to do so. I mean, I get no error. But the look is not what I was expecting.

    Capture du 2018-02-27 18-39-25.png


    Here's the code: https://github.com/Mehd6384/Shaders/blob/master/UnlitToon.shader

    Could anyone explain why this happens ? Instead of having a nice smooth line ?

    Also, does anyone know how to see generated code by the surface shader ? I tried cliking but nothing happened.

    Thanks !
     
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,230
    You're doing your cell shading per vertex. That means each vertex is calculating a color and that color gets interpolated between the vertices. For toon shading you really want to do the vast majority of the math in the fragment shader. You're already passing the normal to the fragment shader anyway, so basically copy over everything after calculating the world normal.

    For this shader? There's no surface shader here, so there's nothing to generate.
     
  3. Mehd

    Mehd

    Joined:
    Apr 29, 2016
    Posts:
    91
    You, my friend , are awesome ! Trying this right now.
    Nope, I meant for any other surface shader. You have an option "Show generated code" in the inspector
     
  4. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,230
    Clicking that button will open up the generated shader in whatever you have set for your external script editor (Edit > Preferences > External Tools). If none is set, or if the program selected is not installed, I suspect nothing will happen when you click that button.