unity顯示物體線框,外邊框


親測可用,物體可以調節透明度跟顏色,根據需要調節

創建一個材質球,把材質調成這個shader就可以了

 

Shader "JaffHan/Wireframe" {
Properties {
        _Color("Color",Color)=(1.0,1.0,1.0,1.0)
        _EdgeColor("Edge Color",Color)=(1.0,1.0,1.0,1.0)
        _Width("Width",Range(0,1))=0.2
    }
SubShader {
    Tags { 
    "Queue"="Transparent" 
    "IgnoreProjector"="True" 
    "RenderType"="Transparent" 
    }
    Blend SrcAlpha OneMinusSrcAlpha
    LOD 200
    Cull Front
    zWrite off
    Pass {
    CGPROGRAM
    #pragma vertex vert
    #pragma fragment frag
    #pragma target 3.0
    #include "UnityCG.cginc"

    struct a2v {
        half4 uv : TEXCOORD0 ;
        half4 vertex : POSITION ;
    };

    struct v2f{
        half4 pos : SV_POSITION ;
        half4 uv : TEXCOORD0  ;            
    };
    fixed4 _Color;
    fixed4 _EdgeColor;
    float _Width;
    
    v2f vert(a2v v)
    {
        v2f o;
        o.uv = v.uv;
        o.pos=UnityObjectToClipPos(v.vertex);
        return o;
    }


    fixed4 frag(v2f i) : COLOR
    {
        fixed4 col;
        float lx = step(_Width, i.uv.x);
        float ly = step(_Width, i.uv.y);
        float hx = step(i.uv.x, 1.0 - _Width);
        float hy = step(i.uv.y, 1.0 - _Width);
        col = lerp(_EdgeColor, _Color, lx*ly*hx*hy);
        return col;
    }
    ENDCG
    }
    Blend SrcAlpha OneMinusSrcAlpha
    LOD 200 
    Cull Back
    zWrite off
    Pass {
    CGPROGRAM
    #pragma vertex vert
    #pragma fragment frag
    #pragma target 3.0
    #include "UnityCG.cginc"

    struct a2v {
        half4 uv : TEXCOORD0 ;
        half4 vertex : POSITION ;
    };

    struct v2f{
        half4 pos : SV_POSITION ;
        half4 uv : TEXCOORD0  ;            
    };
    fixed4 _Color;
    fixed4 _EdgeColor;
    float _Width;
    
    v2f vert(a2v v)
    {
        v2f o;
        o.uv = v.uv;
        o.pos=UnityObjectToClipPos(v.vertex);
        return o;
    }


    fixed4 frag(v2f i) : COLOR
    {
        fixed4 col;
        float lx = step(_Width, i.uv.x);
        float ly = step(_Width, i.uv.y);
        float hx = step(i.uv.x, 1.0 - _Width);
        float hy = step(i.uv.y, 1.0 - _Width);
        col = lerp(_EdgeColor, _Color, lx*ly*hx*hy);
        return col;
    }
    ENDCG
    }
} 
    FallBack "Diffuse"
}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



猜您在找 【Unity】透明物體顯示問題 [Unity2D]隱藏/顯示物體 Unity3D(九)UI界面控制物體顯示和隱藏 unity3d中怎么顯示/隱藏一個物體 通過css樣式去除 css:盒子模型邊框(邊框、內外邊距) Unity 物體移動的理解 Unity設置物體旋轉 CSS——【元素內邊距padding、元素外邊距margin、元素邊框border-width、元素大小width/height】與【元素顯示大小】的關系
 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM
標簽的外邊框 【Unity】偽線框渲染Shader的實現