一个透明的shader

杨航最近在学Unity3D

Shader "Custom/xiankuang" {
 Properties {

    _LineColor ("Line Color", Color) = (1,1,1,1)
    _GridColor ("Grid Color", Color) = (1,1,1,0)
    _LineWidth ("Line Width", float) = 0.2
 }
 SubShader {
   Pass
    {
    //Tags { "RenderType" = "Transparent" }
   // Blend SrcAlpha OneMinusSrcAlpha//这句可以注释掉,能够避免线框太粗出现的模糊效果。
    //AlphaTest Greater 0.5
    //Cull Off//这句是后加的,取消遮挡消隐,体现出透明
    
    CGPROGRAM
    #pragma vertex vert
    #pragma fragment frag
    
    uniform float4 _LineColor;
    uniform float4 _GridColor;
    uniform float _LineWidth;
    
    // vertex input: position, uv1, uv2
    struct appdata
    {
    float4 vertex : POSITION;
    float4 texcoord1 : TEXCOORD0;
    float4 color : COLOR;
    };
    
    struct v2f
    {
    float4 pos : POSITION;
    float4 texcoord1 : TEXCOORD0;
    float4 color : COLOR;
    };
    
    v2f vert (appdata v)
    {
    v2f o;
    o.pos = mul( UNITY_MATRIX_MVP, v.vertex);
    o.texcoord1 = v.texcoord1;
    o.color = v.color;
    return o;
    }
    
    fixed4 frag(v2f i) : COLOR
    {
    fixed4 answer;
    
    float lx = step(_LineWidth, i.texcoord1.x);
    float ly = step(_LineWidth, i.texcoord1.y);
    float hx = step(i.texcoord1.x, 1.0 - _LineWidth);
    float hy = step(i.texcoord1.y, 1.0 - _LineWidth);
    
    answer = lerp(_LineColor, _GridColor, lx*ly*hx*hy);
    
    return answer;
    }
    ENDCG
    }
    }
    Fallback "Vertex Colored", 1
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值