Search Unity

Toony Colors Pro+Mobile: Cartoon Shaders pack with lots of features!

Discussion in 'Assets and Asset Store' started by Jean-Moreno, Apr 15, 2013.

  1. dock

    dock

    Joined:
    Jan 2, 2008
    Posts:
    605
    Is it possible to render soft shadows with a hard cutoff, as seen in Lil Gator on the right?
    I've looked through all of the options but I couldn't find a way for Toony Colors to behave like this.

    edit: I spoke to the Lil. Gator dev and apparently this is the code that makes the shadows sharp. Can this be injected?

    Code (CSharp):
    1. half shadow = step(gi.light.color.r, 0.5);
    2. diff = min(1 - (SHADOW _ STRENGTH * shadow), diff);
     

    Attached Files:

    Last edited: Dec 21, 2022
  2. Jean-Moreno

    Jean-Moreno

    Joined:
    Jul 23, 2012
    Posts:
    593
    Sorry for the late answer, I was away for the holidays.

    You can tweak the main light shadow map through the "Main Light Attenuation" hook in the Shader Properties.
    This setup seems to do what you are looking for, + I added a setting for the threshold value so you can choose how "inflated" it looks (if you don't need that, just replace step(atten, {3}) with step(atten, 0.5) and remove the threshold range property):
    upload_2023-1-4_13-29-45.png

    Note that this won't handle antialiasing, in Lil Gator it's probably a post effect handling that (e.g. FXAA), but if you need it to then you could probably use smoothstep and fwidth to get some antialiasing (let me know if you need some help with that).
     
  3. Ksanone

    Ksanone

    Joined:
    Feb 7, 2015
    Posts:
    41
    Hi, I can't seem to get outline working in Unity 2022.2.1f1. Am I missing a step? Thanks. Screenshot 2023-01-06 172506.png Screenshot 2023-01-06 172525.png Screenshot 2023-01-06 172548.png Screenshot 2023-01-06 172558.png Screenshot 2023-01-06 172607.png
     
  4. Jean-Moreno

    Jean-Moreno

    Joined:
    Jul 23, 2012
    Posts:
    593
    Looks good to me... make sure that there's no space after "Outline" in the LightMode Tag, just in case.

    I tried in a blank project, Unity 2022.2.1 and it did work. Can you do the same and let me know if it works then?
    If it doesn't, please send me that project by email.
    If it does work, then we'll have to figure out what's preventing it from working in your original project.
     
  5. ErisArcana

    ErisArcana

    Joined:
    May 18, 2015
    Posts:
    26
    Is it possible to change the texture of individual material layers from a script? I've made a custom shader where I have 4 additional layers because the main character I'm making has to be customizable so I need to be able to set the texture of the layers based on what the player chooses. I would just need to change the diffuse texture of the material layer, since the character is not using any other maps.

    So I guess what I'm wondering is can I go about setting the texture the same way as one of unity's default materials/shaders or would I need to find specific properties for the TCP2 shader?
     
    Last edited: Feb 1, 2023
  6. Jean-Moreno

    Jean-Moreno

    Joined:
    Jul 23, 2012
    Posts:
    593
    When applying a Material Layer on a texture property, it will automatically create a second texture property in the shader (if you use the "Same as Base layer" option). The variable name of that new texture is created based on the original texture variable name, and the layer name.
    You can select the shader in the Project view and see the variable names in the inspector:
    upload_2023-2-1_18-20-43.png
    Then in your code, you can just do
    Code (csharp):
    1. material.SetTexture("_MainTex_myLayer", newTexture);
     
  7. ErisArcana

    ErisArcana

    Joined:
    May 18, 2015
    Posts:
    26
    Ok cool, that's easier than I thought.. It's working now, thank you! :)
     
  8. strawberrydoll

    strawberrydoll

    Joined:
    Jan 15, 2014
    Posts:
    43
    Why would the shadow color not affect the ramp color with shader generator shaders? It works fine with the desktop shader, but I need cutout so I'm using the shader generator.
    Desktop shader:
    chrome_7dTqBD4H55.png

    Generated shader: (with and without full white shadow color) chrome_plTJuj1mat.png chrome_e9qJlDtfHh.png

    Edit: Seems like the issue only exists when using pixel lights, directional lights don't have this issue. Pixel lights work "correctly" with the default desktop shader though,so wonder why there's a discrepency
     
    Last edited: May 10, 2023
  9. Jean-Moreno

    Jean-Moreno

    Joined:
    Jul 23, 2012
    Posts:
    593
    This was the behavior a long time ago, it was actually a mistake because additional lights don't really "create" more shadow on the model, so it didn't make sense to have them apply the shadow color for those areas, it would actually add more coloring (could be interesting for the style but it wasn't intuitive).
    In the Shader Generator 1, there is an option to restore that behavior, look for "Shadow Color (other lights)".
    In the Shader Generator 2, this setting doesn't exist anymore, you'd have to play with the Shader Properties or do some code injection to emulate back that behavior.

    Lastly your version seems very outdated, the Hybrid Shader 2 replaces the now legacy Desktop & Mobile shaders, and was released over a year ago.

    Oh and regarding the differences in your screenshots, the ramp threshold seems very low for the generated shaders, so I'd look into that first.
     
  10. strawberrydoll

    strawberrydoll

    Joined:
    Jan 15, 2014
    Posts:
    43
    Thank you, I am using the legacy shaders and the SG1 Shadow Color (other lights) is what I was looking for.
     
  11. jinil_neo

    jinil_neo

    Joined:
    Jun 29, 2020
    Posts:
    3
    Hi, Is it possible to have the outline pass through and not be visible while applying the dissolve effect?

    upload_2023-5-25_17-40-18.png
     
  12. Jean-Moreno

    Jean-Moreno

    Joined:
    Jul 23, 2012
    Posts:
    593
    Unfortunately with the technique used, it's not possible, at least out of the box.
    Theoretically you could maybe use a pre-pass that would only mark the pixels that will be dissolved afterwards on the stencil buffer, so that those pixels would not show the outline either, however this wouldn't create any outline around the dissolved parts.

    If you need an outline that works nicely with dissolve, your best bet is using a screen-space post-process based solution - TCP2 doesn't offer any, but there are some implementations on Github and on the Asset Store.
     
  13. dock

    dock

    Joined:
    Jan 2, 2008
    Posts:
    605
    OMG I can't believe I missed this. Thank you so much! this looks fantastic.
    You can see the regular shadow cast on the cube, and the smooth shadow on the floor and character.
    It would be great to see a checkbox option in future for toony shadows. I really like the Threshold control too! Thank you!

    toony smooth shadow.gif
     
    Jean-Moreno likes this.
  14. dock

    dock

    Joined:
    Jan 2, 2008
    Posts:
    605
    I took a look at this approach for soft edges but I couldn't figure it out. Any suggestions?
    It would be nice to see what smoothing or banding could be introduced to shadows.
     
    Last edited: Jun 8, 2023
  15. Jean-Moreno

    Jean-Moreno

    Joined:
    Jul 23, 2012
    Posts:
    593
    Try this in the custom code:
    upload_2023-6-12_16-35-47.png
    Code (csharp):
    1. half shadow = smoothstep({3}, {3} + fwidth(atten), 1 - atten);
    2. ...
    3. min(1 - ({2} * shadow), 1)
    (not sure why "diff" was a variable instead of just 1 in the code I posted previously...)
     
  16. RedZAndroidDev

    RedZAndroidDev

    Joined:
    Dec 2, 2016
    Posts:
    7
    Here is a useful video for those who are new to the Toony Colors Pro
     
    Jean-Moreno likes this.