Search Unity

Shader that uses Vertex Colors and Renders some as Transparent

Discussion in 'Shaders' started by unity_20hy8tc1LSZG4Q, Jun 18, 2019.

  1. unity_20hy8tc1LSZG4Q

    unity_20hy8tc1LSZG4Q

    Joined:
    May 13, 2019
    Posts:
    3
    Hello everyone,

    I was looking to see if I could get some help on a problem I've been spending a while trying to solve. I have an imported .fbx mesh that's colored by vertex colors.

    Here's a screenshot of the mesh I'm using. https://imgur.com/a/FY8Z38r

    Here's the shader I'm using on that GameObject's material.

    Shader "Custom/VertexColor" { // Where it will appear inside of the Shader Dropdown Menu of the Material / Name of the shader

    SubShader{
    Tags { "RenderType" = "Opaque" }
    LOD 200


    CGPROGRAM
    #pragma surface surf Lambert vertex:vert
    #pragma target 3.0

    struct Input {
    float4 vertColor;
    };

    float _CutoutThresh;

    void vert(inout appdata_full v, out Input o) {
    UNITY_INITIALIZE_OUTPUT(Input, o);
    o.vertColor = v.color;
    }

    void surf(Input IN, inout SurfaceOutput o) {

    #include "UnityCG.cginc

    o.Albedo = IN.vertColor.rgb;
    clip(IN.vertColor.r = 0.3); // Discards any pixel whose interpolated vertex color in the red channel is less than 0.5
    }
    ENDCG
    }
    FallBack "Diffuse"
    }

    I want to be able to make all blue parts of the mesh render as transparent. However, the shader above doesn't work, even though I think it should. Does anyone have any ideas?
     
  2. AlexHell

    AlexHell

    Joined:
    Oct 2, 2014
    Posts:
    167
    wtf?