Search Unity

Toony Colors Pro+Mobile 2

Discussion in 'Assets and Asset Store' started by Jean-Moreno, Mar 7, 2015.

  1. NamraGame

    NamraGame

    Joined:
    Feb 17, 2019
    Posts:
    31
    Hi!
    I was trying to access to "base color" value via C# script, like this
    Code (CSharp):
    1.  foreach (MeshRenderer render in renders)  
    2.                 {
    3.                     foreach (Material material in render.materials)
    4.                     {
    5.                         if (isRed)
    6.                         {
    7.                             material.color = Color.red;                
    8.                         }
    This works for Hybrid shaders, cool, but stops working for shaders that are generated with the shader generator...
    is there something I missed? thanks!
    upload_2021-9-9_15-48-9.png
     
  2. Jean-Moreno

    Jean-Moreno

    Joined:
    Jul 23, 2012
    Posts:
    592
    Depending on the render pipeline used, you can use material.SetColor instead:
    • for built-in pipeline:
      Code (csharp):
      1. material.SetColor("_Color", Color.red);
    • for URP:
      Code (csharp):
      1. material.SetColor("_BaseColor", Color.red);
    It's even better to cache the variable name as an int using Shader.PropertyToID, to avoid the lookup each time the function is called (internally shader variables are assigned as integers).

    You can also manually define the variable name using the "Shader Properties" tab of the Shader Generator 2.

    Another small tip: when you access renderer.materials, Unity will actually create a copy of all the materials of that renderer which might not be what you want. It's better to use renderer.sharedMaterials, and then explicitly replace the one that you want to make unique (but maybe the current behavior is what you're looking for).
     
    NamraGame likes this.
  3. dock

    dock

    Joined:
    Jan 2, 2008
    Posts:
    605
    upload_2021-9-22_11-39-45.png

    upload_2021-9-22_11-41-29.png upload_2021-9-22_11-41-52.png

    Is it possible to use the Ramp Shading to recolour a greyscale texture instead of perform lighting? I want to make a bunch of greyscale objects which I can recolour with different gradients.

    On the left is an example using a texture I converted in photoshop with gradient map.
     
  4. Jean-Moreno

    Jean-Moreno

    Joined:
    Jul 23, 2012
    Posts:
    592
    Currently it's not possible without Code Injection, I'll make you an example file when I have some time.

    But it also got me thinking... if we could assign a Custom Material Property to the UVs of a Texture property, then I think it would be doable with the UI only, so I'll add that to my roadmap! It'd be more convenient than the Code Injection way.
     
  5. NamraGame

    NamraGame

    Joined:
    Feb 17, 2019
    Posts:
    31
    thanks a lot! it works :-D
     
  6. NamraGame

    NamraGame

    Joined:
    Feb 17, 2019
    Posts:
    31
    about the 2nd half, funny because I understood the opposite on Unity API! I'm gonna try with sharedMaterials, because it was a bit annoying to have to store the previous color value to put it back...
     
  7. dock

    dock

    Joined:
    Jan 2, 2008
    Posts:
    605
    upload_2021-10-3_22-7-27.png

    I'm really impressed with the new terrain shader in SG2! Excellent work!

    I was wondering, how could I change the wall colours for different areas? Is there any way?
    I was reading through the docs but I couldn't figure it out.

    I tried to paint a hole in the terrain but it didn't work. Is there a way to support Terrain holes?
     
    Jean-Moreno likes this.
  8. Jean-Moreno

    Jean-Moreno

    Joined:
    Jul 23, 2012
    Posts:
    592
    Glad you like it, I've been working on it for a few months now and it's been a challenge to make it flexible like that!

    Depends on what you mean by "walls" actually. If it's dependent on the terrain layer, then you could assign a custom data slot to override the main color of the shader for example. If it's the same terrain layer, but a different part of the world, then it would be a bit trickier... first thing that comes to mind is to have a different color per-terrain: connect multiple terrains, but use a different material (same shader but different values) for each one.
    If something else, please elaborate!
    Good point, I forgot to test that... I'll look into it, I've actually never used holes at all in Unity so that's why I forgot! I did see code in Unity's shaders about it though which I thought I had copied.
     
  9. dock

    dock

    Joined:
    Jan 2, 2008
    Posts:
    605
    It's possible that I can achieve the different coloured walls simply by using the Triplanar option on the different layers, but unfortunately I get this error every time I follow the instructions from your tutorial.
     
  10. Jean-Moreno

    Jean-Moreno

    Joined:
    Jul 23, 2012
    Posts:
    592
    What version of Unity are you using?
     
  11. dock

    dock

    Joined:
    Jan 2, 2008
    Posts:
    605
    I'm on Unity 2021.1.22.

    The only other thing I have in the project is the preview Terrain Tools, but they shouldn't matter to shaders.
     
  12. Jean-Moreno

    Jean-Moreno

    Joined:
    Jul 23, 2012
    Posts:
    592
    Ok, turns out triplanar and no-tile sampling might be broken in the built-in render pipeline because of a bug with the surface shader system (since I've added the ability to separate texture and samplers in the shaders). I've sent you a tentative fix by DM.
    I'm also looking into the terrain holes, the code is indeed there but doesn't work for some reason... I'll keep you posted.
     
  13. dock

    dock

    Joined:
    Jan 2, 2008
    Posts:
    605
    I'm using the Material Layers and really enjoying the Load Source Preset.
    I was able to set up RGB vertex colour splatting on my surfaces, and I managed to define an area for walls using a modification of Load Source Preset > Normal > World > Y.
    I instead changed the Custom Code to
    1- ({2}.y + {3})
    to exclude the Y faces, so it would just give me the XZ walls.

    upload_2021-10-17_10-43-35.png

    The problem I'm having is that I can't get Triplanar UVs working. I can use WorldPos XZ on the Base and Splatmap layers, but I get lots of errors if I try Triplanar UVs for any of them.

    if I choose Triplanar on Walls I get
    Shader error in 'Docky/Splat Toony Triplanar': invalid subscript 'worldPos' at line 200 (on d3d11)

    Whereas if I change things on the Splatmap layers I get errors about Noise texture UVS and other things.

    Any tips for getting better UV control on Material layers?
     
    Last edited: Oct 22, 2021
  14. Voldana78

    Voldana78

    Joined:
    Jun 12, 2021
    Posts:
    4
    Hi there, we decided to use TCP2 for our new project and so far the results were magnificent, since we're using curved world asset as well the compatibility of two assets made our work much easier, however we've been trying to add outline to our project but unfortunately due to our lack of knowledge in shaders we couldn't figure out what the problem was, so I decided to ask you here the problem is the outlines are not moving with the rest of the object as the curve happens do you happen to know a workaround for this problem? Untitled.png
     
  15. Jean-Moreno

    Jean-Moreno

    Joined:
    Jul 23, 2012
    Posts:
    592
    Hi, sorry for the late answer.
    Did you use the Shader Generator 2 to create the shader? From what I can tell, it should work that way.
    If so, please send me the shader by email or DM, and let me know which version of Unity you are using, along with URP version if you are using that, and the version of Curved World.
     
  16. frogwise

    frogwise

    Joined:
    Nov 27, 2009
    Posts:
    103
    Now that Light Cookies are working in URP, does anyone know how to enable them on a Toony Colors pro shader?
     
  17. dock

    dock

    Joined:
    Jan 2, 2008
    Posts:
    605
    @frogwise I too would like to know how to do this! I just tried the Hybrid shader in URP 2021.2.5 and light cookies are not received.
     
  18. Jean-Moreno

    Jean-Moreno

    Joined:
    Jul 23, 2012
    Posts:
    592
    I probably need to manually add support for them in the code, I haven't had time to look into that yet.
    I also probably need to take a look at the new light layers introduced in URP 12.
    And also decals!

    I'm quite swamped with freelance work so unfortunately I currently don't have as much time as I'd like, but it will come eventually!

    Feel free to send me an email if you want to follow up on the progress, and if you have anything to share on those subjects if you managed to implement the features on your end.
     
  19. Frostpiper

    Frostpiper

    Joined:
    Jan 11, 2016
    Posts:
    1
    Hey, thanks for the amazing work on the shader, I'm loving how versatile it is. I was wondering if there is support for multiplying a gradient on top of the albedo, from the bottom to the top of an asset? Attached an image with the effect I'm thinking about.
     

    Attached Files:

  20. Jean-Moreno

    Jean-Moreno

    Joined:
    Jul 23, 2012
    Posts:
    592
    You can do it "manually" using the Shader Properties system, this is an example setup:

    upload_2022-1-19_7-47-35.png

    I plan to add an easier way to do this eventually, with a simple check box in the Features tab!
     
    Frostpiper likes this.
  21. unity_dev3194

    unity_dev3194

    Joined:
    Apr 17, 2017
    Posts:
    79
    How can I fix z-fighting for materials utilizing the hybrid shader? Lots of artifacts when two objects using the same hybrid shader material overlap.
     
  22. Jean-Moreno

    Jean-Moreno

    Joined:
    Jul 23, 2012
    Posts:
    592
    This shouldn't be specific to the Hybrid Shader as far as I know.

    That being said, one way to do that would be to slightly change the position in clip space, but you'll have to add this manually.
    Look for the lines with
    Code (csharp):
    1. output.pos = positionCS;
    and just before you can do something like:
    Code (csharp):
    1. positionCS.z += _MyZOffsetProperty;
    2. output.pos = positionCS;
    (make sure to declare the _MyZOffsetProperty variable)
    You'll likely also have to do it for the outline pass if you use that.
     
    unity_dev3194 likes this.
  23. rrahim

    rrahim

    Joined:
    Nov 30, 2015
    Posts:
    206
    Hi, my entire project is using Toony Colors Pro where possible and there are a few cases where I'd like to use some of Davit Naskidashvili's other shader features together with Toony Colors.
    I know Curved World is currently integrated, is it possible to integrate the others such as Advanced Dissolve and Dynamic Radial Masks?
    Are there any guidelines to do so manually?
     
  24. Jean-Moreno

    Jean-Moreno

    Joined:
    Jul 23, 2012
    Posts:
    592
    No plans for those, and for manual integration you should check those asset's documentations. I know Curved World does have a guide for manual shader integration, so maybe they do as well?

    Also FYI I made a tutorial to create your own advanced dissolve shader using the Shader Properties system of TCP2, if that can help!
     
  25. rrahim

    rrahim

    Joined:
    Nov 30, 2015
    Posts:
    206
    Thanks, it'll help in maybe figuring out how to integrate it.
    The other assets work with shader graph through a node, so I guess that's the integration option they support.
     
  26. unity_dev3194

    unity_dev3194

    Joined:
    Apr 17, 2017
    Posts:
    79
    Thank you
     
  27. nojohnny123

    nojohnny123

    Joined:
    Nov 29, 2018
    Posts:
    6
    Hey Jean! Gotta question regarding Shader Generator 2.

    I'm using a screenspace texture in the shader properties; but I can't quite figure out how to put things together to make a mask so that the screenspace texture only appears in certain areas of the model.
     

    Attached Files:

  28. Morg0t

    Morg0t

    Joined:
    Aug 6, 2020
    Posts:
    2
    Hi, Jean.

    I have small problem with Hybrid Shader (and its Outline version).
    Every time I am building my game, I get one "Shader error" for both shaders and a stockpile of warnings.
    It results in shader being "Failed to compile" and effectively prompts me to reimport package again and again.

    Every single warning is about "possible loss of data, conversion from larger type to smaller". Possibly it has something to do with my project settings, Render Pipeline etc. In another project of mine I have none of these problems and everything works as intended
     

    Attached Files:

  29. Jean-Moreno

    Jean-Moreno

    Joined:
    Jul 23, 2012
    Posts:
    592
    You would need a way to mask out the screenspace texture in local areas of the mesh, so typically you would use a mask texture using the mesh's uv, or a vertex color channel.
    Add either after the screenspace texture so that it's multiplied with it, and then for a value of 1 the screenspace texture will show, and a value of 0 it will be masked (e.g. use the red channel of the vertex colors, or the red channel of a mask texture - that you can set to be "Single Channel" to save up on memory, or you could use a unused channel from an existing texture to save a texture fetch in the shader, for example the alpha channel of your Albedo texture).
    Let me know if you need some clarifications on all that!
     
  30. Jean-Moreno

    Jean-Moreno

    Joined:
    Jul 23, 2012
    Posts:
    592
    The warnings might be because some float are converted to half in the code, but they shouldn't prevent the shader from compiling (depending on the target platforms, there are more or less strict warnings on compilation).
    The TRANSFER_SHADOW error however might be an issue... but not sure where that comes from.

    I'm actually in the process of changing the internal structure of the Hybrid Shader as far as pipeline compatibility goes, because it has been a challenge with the way I've been using so far (two SubShaders in the same file, one for each pipeline).
    I'll be using a custom file format that will compile only the code for the relevant pipeline on import, this should improve compatibility with the latest URP features (decals, light layers, etc.) and maybe hopefully issues like yours.

    Please send me an email if you want to try an early version of that system, I'd love to know how it performs on an actual project!
     
  31. unity_dev3194

    unity_dev3194

    Joined:
    Apr 17, 2017
    Posts:
    79
    Do any of the shaders have cross-fading support for LODs? If not, what would be the best way of implementing LOD cross-fading/dithering into the hybrid shader?
     
  32. Jean-Moreno

    Jean-Moreno

    Joined:
    Jul 23, 2012
    Posts:
    592
    Not yet, but I should definitely add that!
    Noted to be added for the next update.
    (it might actually work already for shaders made with the Shader Generator 2 hen using the built-in pipeline, since they use surface shaders and thus have a lot of built-in features supported by default)

    EDIT: LOD Crossfading has been added as of version 2.9.0
     
    Last edited: Mar 21, 2022
  33. sefaenes

    sefaenes

    Joined:
    Jul 12, 2019
    Posts:
    22
    @Jean-Moreno I have an error on iOS build;

    Note: Creation of internal variant of shader 'Toony Colors Pro 2/Hybrid Shader Outline' failed.
    -------- Shader Toony Colors Pro 2/Hybrid Shader Outline
    -------- GLSL link error: WARNING: Output of vertex shader 'vs_TEXCOORD0' not read by fragment shader
    ERROR: Input of fragment shader 'vs_TEXCOORD1' not written by vertex shader
     
  34. Jean-Moreno

    Jean-Moreno

    Joined:
    Jul 23, 2012
    Posts:
    592
    Can you update to the latest version (2.9.0), and try with the Hybrid Shader 2 instead?
     
  35. abhijeet1001

    abhijeet1001

    Joined:
    Jan 6, 2015
    Posts:
    65
    Latest version of tcp2 has broken outline feature. Enabling that just makes the model darker. Here is the gif from the demo scene. I am using unity 2020.3.21f1 LTS
     

    Attached Files:

    • 1.gif
      1.gif
      File size:
      1.4 MB
      Views:
      209
  36. Jean-Moreno

    Jean-Moreno

    Joined:
    Jul 23, 2012
    Posts:
    592
    Yep I can reproduce on my end... I'll look into it today.

    EDIT: @abhijeet1001 this should now be fixed in TCP2 v2.9.1.
     
    Last edited: Apr 28, 2022
    abhijeet1001 likes this.
  37. xDavidLeon

    xDavidLeon

    Joined:
    Jun 9, 2014
    Posts:
    123
    Hi @Jean-Moreno !

    I just tested TCP 2.9.1 in URP 12.1.6 using Unity 2021.3.2f1 LTS.

    When creating a simple shader using Shader Generator 2 and toggling ON Enable Depth Normals Pass, there is an error:

    Shader error in 'Toony Colors Pro 2/User/My TCP2 Shader': invalid subscript 'normalWS' at line 443 (on d3d11)

    Attaching Screenshot.

    upload_2022-5-16_10-59-43.png
     
  38. Jean-Moreno

    Jean-Moreno

    Joined:
    Jul 23, 2012
    Posts:
    592
    I had replied by DM but for anyone seeing this: a fix is coming in the future version 2.9.2.
     
  39. LegacySystem

    LegacySystem

    Joined:
    Jan 28, 2021
    Posts:
    52
    Hi, We want to toggle the outline on runtime but it seems Outline is controlled by keyword. Is there a tutorial or how to use documention for such thing ?
     
  40. Jean-Moreno

    Jean-Moreno

    Joined:
    Jul 23, 2012
    Posts:
    592
    It's a bit more complicated than just a keyword, because the outline uses its own additional shader pass, meaning that we have to actually change the shader to enable the outline.

    You have a few solutions:
    • Have two materials and switch between them to enable/disable the outline
    • Directly change the shader of the material to one with the outline
    • Use the outline shader, but set its width to 0 - theoretically this will ensure that the outline isn't visible, and then set the number to anything positive to enable it (note though that with this method, you'd still pay the perf cost of the outline shader even when it's not visible)
     
  41. LegacySystem

    LegacySystem

    Joined:
    Jan 28, 2021
    Posts:
    52
    Thank you for your answer. We tried the third method already and faced some issueed on some models. I was trying to avoid first one because number of material is not small and doubling everything will make lots oof things difficult. I'll try the second one.
     
  42. SolumDA

    SolumDA

    Joined:
    Jun 3, 2021
    Posts:
    6
    why I can't put outline in urp + webgl ?
    I don't know here is the problem :/
     
    Last edited: Jun 30, 2022
  43. Jean-Moreno

    Jean-Moreno

    Joined:
    Jul 23, 2012
    Posts:
    592
    I don't know either with such minimal information... does it work in the editor? does it work in a desktop build?
    Anything in the console or the build log that looks related?
     
  44. SolumDA

    SolumDA

    Joined:
    Jun 3, 2021
    Posts:
    6
    yes work on editor and desktop build, console don't say anything about.
    All I have to help is this:
    upload_2022-6-30_14-7-59.png upload_2022-6-30_14-8-34.png upload_2022-6-30_15-13-25.png
     

    Attached Files:

    Last edited: Jun 30, 2022
  45. haleler51

    haleler51

    Joined:
    Apr 9, 2015
    Posts:
    30
    Are there any plans to add support for URP light layers?
     
  46. Jean-Moreno

    Jean-Moreno

    Joined:
    Jul 23, 2012
    Posts:
    592
    They should work in the Hybrid Shader 2, I still have to add support in the Shader Generator 2 though.
     
  47. Jean-Moreno

    Jean-Moreno

    Joined:
    Jul 23, 2012
    Posts:
    592
    Hmm weird... I'll do some tests on my end and will get back here.
    Quick question: are you using WebGL 1 or 2? If 1, maybe try to use WebGL 2 and see.
     
  48. SolumDA

    SolumDA

    Joined:
    Jun 3, 2021
    Posts:
    6
    same problem in webgl 2 ..
     
  49. Jean-Moreno

    Jean-Moreno

    Joined:
    Jul 23, 2012
    Posts:
    592
    It works on my end, here's the log and a screenshot. I used the Hybrid Shader 2 Outline on the sphere.

    upload_2022-7-6_14-59-41.png

    upload_2022-7-6_14-59-51.png
    First you can try with another browser (here I'm using Firefox); then if the result is the same, try with an empty project to see if you can have it working, and if so you'll have to figure out what's different between the two to understand why it doesn't work in your main project.
    I don't have any ideas right now unfortunately :/
     
  50. SolumDA

    SolumDA

    Joined:
    Jun 3, 2021
    Posts:
    6
    you can share your render pipeline configs ?
    anyway thx for the response!