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

Set custom or default fallback shader

Discussion in 'Shaders' started by quizcanners, Mar 29, 2015.

  1. quizcanners

    quizcanners

    Joined:
    Feb 6, 2015
    Posts:
    109
    I am using CameraDepthTexture in my shader.
    But when Camera renders objects to this texture it uses fallback shader.

    Code (CSharp):
    1. FallBack "Mobile/Diffuse"
    My shader changes depth a little. I want to put my shader in FallBack:

    Code (CSharp):
    1. FallBack "Custom/DiffuseMy"
    but it does not work, even if I make my shader an exact copy of Diffuse shader.
     
  2. UnityGuillaume

    UnityGuillaume

    Unity Technologies

    Joined:
    Mar 16, 2015
    Posts:
    123
    How does it does not work? print a warning? Display black?

    I'm not sure of the specific, but could simply be that Unity don't package your shader, if it's used by nothing explicitly (only by fallbacks). Try to add it to the "Always include List" in "Edit>Project Settings>Graphics"
     
  3. quizcanners

    quizcanners

    Joined:
    Feb 6, 2015
    Posts:
    109
    Object was rendered with no warning, but it was not rendered to the CameraDepthTexture.
    I found the problem now. When I use Fallback "Diffuse", it doesn't Fallback to "Diffuse", if uses "Fallback" inside "Diffuse" to get to "Mobile/VertexLit". So I need to replace it with my shader.

    Solution (kind of): I downloaded source for shaders:

    http://unity3d.com/get-unity/download/archive

    Opened mobile/VertexLit, changed it's name, and it works. It has no FallBack statement inside, so I know this is the one used. When I tried to remove fallback from other shaders no rendering to CameraDepthTexture was done.

    Propper way would be to know which shaders (shader commands) work for CameraDepthTexture rendering, but this is what I have so far. I'll try to modify it (probably break it) and maybe figure out why camera depth want it.

    I am failing to find documentation for this stuff.
     
    Last edited: Mar 30, 2015
  4. quizcanners

    quizcanners

    Joined:
    Feb 6, 2015
    Posts:
    109
    I removed pieces of code one by one, and this is what left:

    Code (CSharp):
    1. Shader "MyLit" {
    2. SubShader {
    3.     // Pass to render object as a shadow caster
    4.     Pass
    5.     {
    6.         Tags { "LightMode" = "ShadowCaster" }
    7.     }  
    8. }
    9. }
    10.  
    This is ALL of the FallBack shader code. There was 3 passes and more stuff, but removing this tag is what brakes it for CameraDepthTexture.
     
  5. UnityGuillaume

    UnityGuillaume

    Unity Technologies

    Joined:
    Mar 16, 2015
    Posts:
    123
    Rendering to CameraDepth is done, on mobile/forward, through a second pass using replacement shader (http://docs.unity3d.com/Manual/SL-ShaderReplacement.html).

    So the engine will cascade down on fallback until it find one having the proper tag. If it can't find it, it just don't render the object. Find it strange that the tag it's looking for is LightMode though...

    Was your first shader "Custom/DiffuseMy" having a RenderType tag?
     
  6. quizcanners

    quizcanners

    Joined:
    Feb 6, 2015
    Posts:
    109
    Yes:
    Code (CSharp):
    1.     Tags { "RenderType"="Opaque" }
    2.  
    And:
    Code (CSharp):
    1. Fallback "Mobile/VertexLit"
    This is from Unity 5 shaders.
     
    Last edited: Mar 30, 2015