Search Unity

  1. If you have experience with import & exporting custom (.unitypackage) packages, please help complete a survey (open until May 15, 2024).
    Dismiss Notice
  2. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice

How to do "nothing" in a frag program?

Discussion in 'Shaders' started by ArachnidAnimal, Nov 21, 2017.

  1. ArachnidAnimal

    ArachnidAnimal

    Joined:
    Mar 3, 2015
    Posts:
    1,874
    I'm trying to create a shader. It is the Unity standard specular shader with a grab pass and extra frag program at the end. How do I do nothing in the frag program as if it wasn't even there? Is it possible to do that?

    Code (csharp):
    1.  
    2. Shader "Standard (Specular setup)-FrostedGlass"
    3. {
    4.     Pass
    5.         {
    6.             Name "FORWARD"
    7.             Tags { "LightMode" = "ForwardBase" }
    8.            //...
    9.        }
    10.  
    11.       //..all of these original passes are in the program
    12.     //then at the end I have added:
    13.  
    14.         GrabPass
    15.          {
    16.               Tags{ "LightMode" = "Always" }
    17.           }
    18.  
    19.           Pass
    20.          {
    21.               Tags{ "LightMode" = "Always" }
    22.                CGPROGRAM
    23.                #pragma vertex vert
    24.                #pragma fragment frag
    25.  
    26.                struct appdata_t
    27.                {
    28.                          float4 vertex : POSITION;
    29.                          float2 texcoord: TEXCOORD0;
    30.                 };
    31.  
    32.                struct v2f
    33.                {
    34.                          float4 vertex : POSITION;
    35.                          float4 uvgrab : TEXCOORD0;
    36.                  };
    37.  
    38.                    //...
    39.                  fixed4 frag(v2f i) : COLOR      
    40.                  {
    41.                                //return some value so nothing happens. As if this "Frag" didn't even exist.
    42.                  }
    43.    }    
    44.  
     
  2. nat42

    nat42

    Joined:
    Jun 10, 2017
    Posts:
    353
    there's "discard", but it's expensive on mobile
     
    ArachnidAnimal likes this.
  3. sngdan

    sngdan

    Joined:
    Feb 7, 2014
    Posts:
    1,154
    What is the purpose of the shader if it is not meant to display anything? Do you want to use the gpu for processing?
     
  4. ArachnidAnimal

    ArachnidAnimal

    Joined:
    Mar 3, 2015
    Posts:
    1,874
    Ok. Thanks. That was what I was looking for.

    The shader is the standard shader + a frosted glass effect for transparent areas.
    Don't do frosted glass effect for areas which have full opacity. (discard)

    I got it somewhat usable at this point:
    blur.jpg
    .