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

Shader to edit color and transparency of vertices in a mesh

Discussion in 'Shaders' started by jetese, Sep 5, 2019.

  1. jetese

    jetese

    Joined:
    Mar 15, 2018
    Posts:
    1
    Hello,

    I'm trying to do a shader to be able to set the color and transparency of each vertex in a mesh.
    I set the mesh.colors (color + alpha) and I use this shader to show it in the Mesh. The color of vertices is working well but the transparency doesn't work and I have no idea what I'm doing wrong.

    Code (CSharp):
    1. Shader "Custom/TransparentVertex" {
    2.      Properties{
    3.          _Glossiness("Smoothness", Range(0,1)) = 0.5
    4.      }
    5.      SubShader{
    6.          Tags{ "RenderType" = "Transparent"    }
    7.          Blend SrcAlpha OneMinusSrcAlpha
    8.          LOD 200
    9.          Pass{
    10.              Cull Off          
    11.          }
    12.          CGPROGRAM
    13.          #pragma surface surf Standard vertex:vert fullforwardshadows alpha:fade
    14.          #pragma target 3.0
    15.          struct Input {
    16.              float4 vertexColor;
    17.          };
    18.          void vert(inout appdata_full v, out Input o)
    19.          {
    20.              o.vertexColor = v.color;
    21.          }
    22.          half _Glossiness;
    23.          fixed4 _Color;
    24.          void surf(Input IN, inout SurfaceOutputStandard o)
    25.          {
    26.              o.Albedo =  IN.vertexColor;
    27.              o.Smoothness = _Glossiness;
    28.              o.Alpha = IN.vertexColor.w;
    29.          }
    30.          ENDCG
    31.      }
    32.      FallBack "Diffuse"
    33. }
    If I set o.Alpha = 0, I just remove the smoothness.
    I tried to add "Queue"="Transparent" but it isn't the solution and I don't want to set it for other reasons.
     
  2. ChrisDunneBW

    ChrisDunneBW

    Joined:
    Jan 9, 2019
    Posts:
    1
    Hey mate, did you manage to find a solution, I am working on something similar at the moment and pretty much have got to the same point
     
  3. Invertex

    Invertex

    Joined:
    Nov 7, 2013
    Posts:
    1,539
    Remove lines 9/10/11, it seems to be resulting in a default diffuse or unlit pass or something since there's nothing in it except
    Cull Off
    .
    Also, in the Tags line, add
    "Queue"="Transparent"
    to ensure the material run in the correct queue for transparencies.