首页 > 代码库 > 公告板shader

公告板shader

Shader "Custom/LightPoint" {
    Properties {
        _MainTex ("Main Tex", 2D) = "white" {}
        _Color ("Color Tint", Color) = (1, 1, 1, 1)
    }
    SubShader {
        Tags {"Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" "DisableBatching"="True"}
        
        Pass { 
            Tags { "LightMode"="ForwardBase" }
            
            ZWrite On//深度写入
            Blend SrcAlpha OneMinusSrcAlpha//开启混合模式
            Offset 0,-10000
        
            CGPROGRAM
            
            #pragma vertex vert
            #pragma fragment frag
            
            #include "Lighting.cginc"
            
            sampler2D _MainTex;
            float4 _MainTex_ST;
            fixed4 _Color;
            
            struct a2v {
                float4 vertex : POSITION;
                float4 texcoord : TEXCOORD0;
                fixed4 texcoord1 : TEXCOORD1;
                float3 color:COLOR;
            };
            
            struct v2f {
                float4 pos : SV_POSITION;
                float2 uv : TEXCOORD0;
            };
            
            v2f vert (a2v v) {
                v2f o;
                float scaleX = unity_ObjectToWorld[0][0];//先用3个变量对变换的分量进行记录
                float scaleY = unity_ObjectToWorld[1][1];
                float scaleZ = unity_ObjectToWorld[2][2];
                unity_ObjectToWorld[0][0] = 1;
                unity_ObjectToWorld[1][1] = 1;
                unity_ObjectToWorld[2][2] = 1;

                v.texcoord1.x = v.texcoord.x * scaleX;//将第二套uv坐标进行缩放
                v.texcoord1.y = v.texcoord.y * scaleY;

                float3    centerOffs = float3(float2(0.5, 0.5)*scaleX - v.texcoord1.xy, 0);//得保证面片是整体缩放
                float3    centerLocal = v.vertex.xyz + centerOffs.xyz;

                centerLocal.x = v.vertex.x*scaleX + centerOffs.x;
                centerLocal.y = v.vertex.y*scaleY + centerOffs.y;
                centerLocal.z = v.vertex.z*scaleZ + centerOffs.z;

                float4 centerWolrd = mul(unity_ObjectToWorld, float4(centerLocal.xyz, 1.0));
                float4 centerView = mul(UNITY_MATRIX_V, centerWolrd);
                float4 viewP = centerView + float4(centerOffs.xy, 0.0, 0.0);

                o.pos = mul(UNITY_MATRIX_P, float4(viewP.xyz, 1));
                o.uv = TRANSFORM_TEX(v.texcoord,_MainTex);
                o.uv.y=1-o.uv.y;//上下翻转图像
                return o;
            }
            
            fixed4 frag (v2f i) : SV_Target {
                fixed4 c = tex2D (_MainTex, i.uv);
                c.rgb *= _Color.rgb;
                return c;
            }
            
            ENDCG
        }
    } 
    FallBack off
}

 

公告板shader