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 10011 Cull Front //剔除正面,用于看到球体的内12 13 Pass14 {15 CGPROGRAM16 #pragma vertex vert17 #pragma fragment frag18 #pragma multi_compile_fog19 20 #include "UnityCG.cginc"21 22 struct appdata23 {24 float4 vertex : POSITION;25 float2 uv : TEXCOORD0;26 };27 28 struct v2f29 {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_Target48 {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 ENDCG60 }61 }62 }