1. 程式人生 > >UnityShader 學習筆記 10 高階紋理之鏡子

UnityShader 學習筆記 10 高階紋理之鏡子



Shader "_MyShader/7_Advanced/3_Mirror"

{

    Properties {

        _MainTex ("Texture", 2D) = "white" {}

    }

    SubShader {

        Tags { "RenderType"="Opaque" "Queue" = "Geometry" }

        Pass

        {

            Tags{"LightMode"="ForwardBase"}

            CGPROGRAM

            #pragma vertex vert

            #pragma fragment frag



            #include "UnityCG.cginc"

            #include "Lighting.cginc"

            #include "AutoLight.cginc"



            sampler2D _MainTex;

            float4 _MainTex_ST;



            struct a2v

            {

                float4 vertex:POSITION;

                float3 texcoord:TEXCOORD0;

            };

            struct v2f

            {

                float4 pos:SV_POSITION;

                float2 uv:TEXCOORD0;

            };



            v2f vert(a2v v)

            {

                v2f o;

                o.pos = mul(UNITY_MATRIX_MVP,v.vertex);

                o.uv = v.texcoord;

                //倒轉紋理座標的x軸分量

                o.uv.x = 1 - o.uv.x;

                return o;

            }



            fixed4 frag(v2f i):SV_Target

            {

                return tex2D(_MainTex,i.uv);

            }





            ENDCG

        }

    }

    FallBack "Diffuse"

}