Unity創建一Sphere默認是看不到球體內部的,所以需要用 Cull Front 修改剔除的方向,這就會帶來一個新的問題,所播放的視頻是像鏡子一樣翻轉着的,所以要改變它的UV坐標使其翻轉過來 float u_x=1-i.uv.x; float u_y=i.uv.y;i.uv=float2(u_x,u_y);
1 Shader "Unlit/UnlitShader" 2 { 3 Properties 4 { 5 _MainTex ("Texture", 2D) = "white" {} 6 } 7 SubShader 8 { 9 Tags { "RenderType"="Opaque" } 10 LOD 100 11 Cull Front //剔除正面,用於看到球體的內 12 13 Pass 14 { 15 CGPROGRAM 16 #pragma vertex vert 17 #pragma fragment frag 18 #pragma multi_compile_fog 19 20 #include "UnityCG.cginc" 21 22 struct appdata 23 { 24 float4 vertex : POSITION; 25 float2 uv : TEXCOORD0; 26 }; 27 28 struct v2f 29 { 30 float2 uv : TEXCOORD0; 31 UNITY_FOG_COORDS(1) 32 float4 vertex : SV_POSITION; 33 }; 34 35 sampler2D _MainTex; 36 float4 _MainTex_ST; 37 38 v2f vert (appdata v) 39 { 40 v2f o; 41 o.vertex = UnityObjectToClipPos(v.vertex); 42 o.uv = TRANSFORM_TEX(v.uv, _MainTex); 43 UNITY_TRANSFER_FOG(o,o.vertex); 44 return o; 45 } 46 47 fixed4 frag (v2f i) : SV_Target 48 { 49 50 float u_x=1-i.uv.x; //因為球的內部是像鏡子一樣反着的 51 float u_y=i.uv.y; //所以要改變其uv坐標 52 i.uv=float2(u_x,u_y); //只改變x,就行了, 53 54 55 fixed4 col = tex2D(_MainTex, i.uv); 56 UNITY_APPLY_FOG(i.fogCoord, col); 57 return col; 58 } 59 ENDCG 60 } 61 } 62 }