unity-shader面片上画圆

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/y90o08u28/article/details/87263194

circleshader1

Shader "Unlit/CircleAdd"
{
    Properties
    {
        _MainTex("Texture", Color) = (1,1,1,1)
        _MainTex2("Texture2", Color) = (1,0,0,1)

        _Radius1("_Radius1",Range(0, 1)) = 0.01
        _Radius2("_Radius2",Range(0, 1)) = 0.01
        _Radius3("_Radius3",Range(0, 1)) = 0.01
        _Radius4("_Radius4",Range(0, 1)) = 0.01
        _Radius5("_Radius5",Range(0, 1)) = 0.01

        _Pox1("_Pox1",Range(0, 1)) = 0.01
        _Pox2("_Pox2",Range(0, 1)) = 0.02
        _Pox3("_Pox3",Range(0, 1)) = 0.03
        _Pox4("_Pox4",Range(0, 1)) = 0.04
        _Pox5("_Pox5",Range(0, 1)) = 0.05

        _Poy1("_Poy1",Range(0, 1)) = 0.01
        _Poy2("_Poy2",Range(0, 1)) = 0.02
        _Poy3("_Poy3",Range(0, 1)) = 0.03
        _Poy4("_Poy4",Range(0, 1)) = 0.04
        _Poy5("_Poy5",Range(0, 1)) = 0.05
    }
    SubShader
    {
        Tags { "RenderType"="Opaque" }
        LOD 100

        Pass
        {
            ZWrite Off
            Blend SrcAlpha OneMinusSrcAlpha

            CGPROGRAM
            #pragma vertex vert
            #pragma fragment frag
            // make fog work
            #pragma multi_compile_fog

            #include "UnityCG.cginc"

            struct appdata
            {
                float4 vertex : POSITION;
                float2 uv : TEXCOORD0;
            };

            struct v2f
            {
                float2 uv : TEXCOORD0;
                float4 vertex : SV_POSITION;
            };

            half4 _MainTex, _MainTex2;
            float _Pox1, _Pox2, _Pox3, _Pox4, _Pox5;
            float _Poy1, _Poy2, _Poy3, _Poy4, _Poy5;
            float _Radius1, _Radius2, _Radius3, _Radius4, _Radius5;

            v2f vert (appdata v)
            {
                v2f o;
                o.vertex = UnityObjectToClipPos(v.vertex);
                o.uv = v.uv;
                //o.uv = TRANSFORM_TEX(v.uv, _MainTex);
                return o;
            }


            float DrawCircle(float x,float y,float r, v2f i) {
                float x_r = i.uv.x - x;
                float y_r = i.uv.y - y;
                float dis = (x_r)*(x_r)+(y_r)*(y_r);
                if (dis <= r)
                {
                    if (r - dis  < 0.002)
                    {
                        return (r - dis) / 0.002;
                    }
                    else {
                        return 1;
                    }
                }
                else {
                    return 0;
                }
                


            }
            fixed4 frag (v2f i) : SV_Target
            {
                float c1 = DrawCircle(_Pox1,_Poy1,_Radius1,i);
                if (c1==1)
                {
                    return _MainTex2;
                }
                else {
                    float c2 = DrawCircle(_Pox2, _Poy2, _Radius2, i);
                    if (c2==1) {
                        return _MainTex2;
                    }
                    else {
                        if(c2<c1)
                            c2 = c1;
                        float c3 = DrawCircle(_Pox3, _Poy3, _Radius3, i);
                        if (c3==1)
                        {
                            return _MainTex2;
                        }
                        else {
                            if (c3 < c2)
                                c3 = c2;
                            float c4 = DrawCircle(_Pox4, _Poy4, _Radius4, i);
                            if (c4==1)
                            {
                                return _MainTex2;
                            }
                            else {
                                if(c4<c3)
                                c4= c3;
                                float c5 = DrawCircle(_Pox5, _Poy5, _Radius5, i);
                                if (c5==1)
                                {
                                    return _MainTex2;
                                }
                                else {
                                    if(c5<c4)
                                    c5 = c4;
                                    return _MainTex2* c5+ _MainTex*(1- c5);
                                }
                            }
                        }
                    }
                }
            }
            ENDCG
        }
    }
}
 

本人qq:344810449,一起研究技术。

猜你喜欢

转载自blog.csdn.net/y90o08u28/article/details/87263194
今日推荐