Search Unity

Intentionally Render Nothing

Discussion in 'Shaders' started by Fenrisul, Sep 10, 2014.

  1. Fenrisul

    Fenrisul

    Joined:
    Jan 2, 2010
    Posts:
    618
    You know, I have no idea what the best way to do this is hahah.

    The use case is, I want to render a specific submesh of a mesh (readonly) with 3 submeshes. As far as I can tell the only way to do this with MeshRenderer is to put in dummy shaders in the material slots that I don't want.

    Is there an optimal "Don't render anything" method for a shader? o_O
     
  2. dandeentremont

    dandeentremont

    Joined:
    Jan 11, 2013
    Posts:
    24
    EDIT: Ignore my post, for it is dumb.
    Couldn't you just uncheck the "Mesh Renderer" component in the Unity Editor?
     
    Last edited: Sep 11, 2014
  3. Daniel_Brauer

    Daniel_Brauer

    Unity Technologies

    Joined:
    Aug 11, 2006
    Posts:
    3,355
    Have you tried an empty sub shader?
    Disabling the MeshRenderer would prevent anything from being rendered, including the sub mesh that Fenrisul is trying to isolate.
     
  4. Phantomx

    Phantomx

    Joined:
    Oct 30, 2012
    Posts:
    202
    I use this shader to render just nothing when I have a case like yours:
    Code (CSharp):
    1. Shader "Custom/Invisible" {
    2.   SubShader {
    3.     Pass {
    4.       CGPROGRAM
    5.       #pragma vertex vert
    6.       #pragma fragment frag
    7.    
    8.       struct v2f {
    9.           float4 pos : SV_POSITION;
    10.       };
    11.      
    12.       v2f vert ()
    13.       {
    14.           v2f o;
    15.           o.pos = fixed4(0,0,0,0);
    16.           return o;
    17.       }
    18.  
    19.       fixed4 frag (v2f i) : COLOR0 { return fixed4(0,0,0,0); }
    20.       ENDCG
    21.     }
    22.   }
    23. }
     
  5. Daniel_Brauer

    Daniel_Brauer

    Unity Technologies

    Joined:
    Aug 11, 2006
    Posts:
    3,355
    That should be pretty good. You might want to throw ZWrite Off and ColorMask 0 in there for good measure.

    Completely null shader option would be nice, though.
     
  6. Fenrisul

    Fenrisul

    Joined:
    Jan 2, 2010
    Posts:
    618
    Code (csharp):
    1.  
    2. Shader "Spine/HiddenPass" {
    3.     SubShader
    4.     {
    5.         Tags {"Queue" = "Geometry-1" }
    6.  
    7.         Lighting Off
    8.  
    9.         Pass
    10.  
    11.         {
    12.             ZWrite Off
    13.             ColorMask 0    
    14.         }
    15.     }
    16. }
    Yea, thats basically what I ended up doing. I would love it so much if leaving a material channel blank resulted in nothing being called but yea.

    Thanks :)
     
  7. Daniel_Brauer

    Daniel_Brauer

    Unity Technologies

    Joined:
    Aug 11, 2006
    Posts:
    3,355
    Alternately, you could copy the sub mesh you want into another mesh and just render that.
     
  8. Fenrisul

    Fenrisul

    Joined:
    Jan 2, 2010
    Posts:
    618
    Yea I wanted to avoid doing full submesh copies every single frame times say... 10... per object heh.

    I'm working on refactoring the renderer itself to pump directly into independent meshes with support for double buffering now... joy.
     
  9. jc_lvngstn

    jc_lvngstn

    Joined:
    Jul 19, 2006
    Posts:
    1,508
    If you just want to render a specific submesh, look at graphics.drawmesh. you can specify which submesh, which material, etc.
     
  10. Fenrisul

    Fenrisul

    Joined:
    Jan 2, 2010
    Posts:
    618
    Yeeeaaa I was trying to avoid that heh. Mostly because I don't think you can set Sorting Order/Layer with Graphics.
     
  11. jc_lvngstn

    jc_lvngstn

    Joined:
    Jul 19, 2006
    Posts:
    1,508
    It accepts a layer value, and works like everything else in my experience (sorting, etc).
    Thought...to be honest, it's been a while since I used it for true transparent objects, so I honestly may be mistaken here.
     
  12. Fenrisul

    Fenrisul

    Joined:
    Jan 2, 2010
    Posts:
    618
    It accepts a Layer value yea, but not Sorting Layer or Sorting Order if I remember / am reading right.