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

[Polybrush] Vertex Painting with Transparency

Discussion in 'World Building' started by stechmann, Nov 20, 2018.

  1. stechmann

    stechmann

    Joined:
    Feb 24, 2012
    Posts:
    34
    Hi,

    I am trying to create a Plane wich is part vertex painted, part transparent. In other words, I would like to have a transparent plane, then start painting on it with Polybrush. Wherever I don't put vertex paint on, I want the plane to remain transparent.

    I have tried doing this using the shader Polybrush/Standard Vertex Color.

    However, I am having a problem. While the shader does have an alpha setting in the inspector, modifying this setting does not seem to achieve anything. My plane always remains opaque.

    Can someone help me solve this?

    Is it perhaps a bug in the shader code?

    Thanks
     
  2. Flavelius

    Flavelius

    Joined:
    Jul 8, 2012
    Posts:
    943
    The builtin shader probably just doesn't support transparency.
    Here's something i stitched together that should work (it uses color for transparency, not the vertex alpha, as you said):
    Code (CSharp):
    1. Shader "Custom/VertexColoredTransparent" {
    2.     Properties {
    3.         _Color ("Color", Color) = (1,1,1,1)
    4.         _MainTex ("Albedo (RGB)", 2D) = "white" {}
    5.         _Glossiness ("Smoothness", Range(0,1)) = 0.5
    6.         _Metallic ("Metallic", Range(0,1)) = 0.0
    7.         _Cutoff("Alpha Cutoff", Range(0,1)) = 0.5
    8.     }
    9.     SubShader {
    10.         Tags { "RenderType"="Transparent" "Queue"="Transparent"}
    11.         LOD 200
    12.         blend SrcAlpha OneMinusSrcAlpha
    13.  
    14.         CGPROGRAM
    15.         // Physically based Standard lighting model, and enable shadows on all light types
    16.         #pragma surface surf Standard fullforwardshadows alphatest:_Cutoff addshadow
    17.  
    18.         // Use shader model 3.0 target, to get nicer looking lighting
    19.         #pragma target 3.0
    20.  
    21.         sampler2D _MainTex;
    22.  
    23.         struct Input {
    24.             float2 uv_MainTex;
    25.             float4 color:COLOR;
    26.         };
    27.  
    28.         half _Glossiness;
    29.         half _Metallic;
    30.         fixed4 _Color;
    31.  
    32.         // Add instancing support for this shader. You need to check 'Enable Instancing' on materials that use the shader.
    33.         // See https://docs.unity3d.com/Manual/GPUInstancing.html for more information about instancing.
    34.         // #pragma instancing_options assumeuniformscaling
    35.         UNITY_INSTANCING_BUFFER_START(Props)
    36.             // put more per-instance properties here
    37.         UNITY_INSTANCING_BUFFER_END(Props)
    38.  
    39.         void surf (Input IN, inout SurfaceOutputStandard o) {
    40.             // Albedo comes from a texture tinted by color
    41.             fixed4 c = tex2D (_MainTex, IN.uv_MainTex) * _Color*IN.color;
    42.             o.Albedo = c.rgb;
    43.             // Metallic and smoothness come from slider variables
    44.             o.Metallic = _Metallic;
    45.             o.Smoothness = _Glossiness;
    46.             o.Alpha = c.a*(1-IN.color);
    47.         }
    48.         ENDCG
    49.     }
    50.     FallBack "Transparent/Cutout/VertexLit"
    51. }
    52.  
     
    Last edited: Nov 20, 2018