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

cannot make shader transparent....

Discussion in 'Shaders' started by woodlee, Feb 25, 2017.

  1. woodlee

    woodlee

    Joined:
    Dec 1, 2014
    Posts:
    5
    i want to make my shader transparent by color's alpha ,but it's no effect...
    so,i need help:(

    Shader "Custom/testShader" {
    Properties {
    _MainTex ("Base (RGB)", 2D) = "white" {}
    _MainTint ("Diffuse Tint", Color) = (1, 1, 1, 1)
    _ScrollXSpeed ("X Scroll Speed", Range(0, 10)) = 2
    _ScrollYSpeed ("Y Scroll Speed", Range(0, 10)) = 2
    _LightFactor ("Light", Range(0,1)) = 0
    }
    SubShader {
    Tags {
    "Queue"="Transparent"
    "RenderType"="Transparent" }
    LOD 200

    CGPROGRAM
    #pragma surface surf BasicDiffuse
    // #pragma surface surf Lambert
    fixed4 _MainTint;
    fixed _ScrollXSpeed;
    fixed _ScrollYSpeed;
    fixed _LightFactor;
    sampler2D _MainTex;

    struct Input {
    float2 uv_MainTex;
    };

    inline float4 LightingBasicDiffuse(SurfaceOutput s, fixed3 lightDir, fixed atten){
    float difLight = dot(s.Normal,lightDir);
    float hLambert = difLight * 0.5 + 0.5;

    float4 col;
    col.rgb = s.Albedo * _LightColor0.rgb * (hLambert );
    col.a = s.Alpha;
    return col;
    }

    void surf (Input IN, inout SurfaceOutput o) {

    fixed2 scrolledUV = IN.uv_MainTex;
    fixed xScrollValue = _ScrollXSpeed * _Time;
    fixed yScrollValue = _ScrollYSpeed * _Time;
    scrolledUV += fixed2(xScrollValue, yScrollValue);
    half4 c = tex2D (_MainTex, scrolledUV);
    o.Albedo = c.rgb * _MainTint*(1+_LightFactor);
    o.Alpha =_MainTint.a;
    }
    ENDCG
    }
    FallBack "Diffuse"
    }
     
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,329
  3. woodlee

    woodlee

    Joined:
    Dec 1, 2014
    Posts:
    5