You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

232 lines
4.8 KiB

  1. Shader "Hidden/LinearMaterial"
  2. {
  3. Properties
  4. {
  5. _MainTex( "Texture", any ) = "" {}
  6. _BackGround( "Back", 2D) = "white" {}
  7. }
  8. SubShader
  9. {
  10. Lighting Off
  11. Blend SrcAlpha OneMinusSrcAlpha
  12. Cull Off
  13. ZWrite Off
  14. ZTest Always
  15. Pass {
  16. CGPROGRAM
  17. #pragma vertex vert
  18. #pragma fragment frag
  19. #pragma target 2.0
  20. #include "UnityCG.cginc"
  21. sampler2D _MainTex;
  22. uniform float4 _MainTex_ST;
  23. float4 _Mask;
  24. uniform float4x4 unity_GUIClipTextureMatrix;
  25. sampler2D _GUIClipTexture;
  26. struct appdata_t {
  27. float4 vertex : POSITION;
  28. float2 texcoord : TEXCOORD0;
  29. };
  30. struct v2f {
  31. float4 vertex : SV_POSITION;
  32. float2 texcoord : TEXCOORD0;
  33. float2 clipUV : TEXCOORD1;
  34. };
  35. v2f vert( appdata_t v )
  36. {
  37. v2f o;
  38. o.vertex = UnityObjectToClipPos( v.vertex );
  39. o.texcoord = TRANSFORM_TEX( v.texcoord.xy, _MainTex );
  40. float3 eyePos = UnityObjectToViewPos( v.vertex );
  41. o.clipUV = mul( unity_GUIClipTextureMatrix, float4( eyePos.xy, 0, 1.0 ) );
  42. return o;
  43. }
  44. fixed4 frag( v2f i ) : SV_Target
  45. {
  46. float4 c = tex2D( _MainTex, i.texcoord );
  47. c.rgb *= _Mask.rgb;
  48. c.a = tex2D( _GUIClipTexture, i.clipUV ).a;
  49. return c;
  50. }
  51. ENDCG
  52. }
  53. Pass { // sphere preview = true, alpha mask = false
  54. CGPROGRAM
  55. #pragma vertex vert
  56. #pragma fragment frag
  57. #pragma target 2.0
  58. #include "UnityCG.cginc"
  59. sampler2D _MainTex;
  60. uniform float4 _MainTex_ST;
  61. float _InvertedZoom;
  62. float4 _Mask;
  63. uniform float4x4 unity_GUIClipTextureMatrix;
  64. sampler2D _GUIClipTexture;
  65. struct appdata_t {
  66. float4 vertex : POSITION;
  67. float2 texcoord : TEXCOORD0;
  68. };
  69. struct v2f {
  70. float4 vertex : SV_POSITION;
  71. float2 texcoord : TEXCOORD0;
  72. float2 clipUV : TEXCOORD1;
  73. };
  74. v2f vert( appdata_t v )
  75. {
  76. v2f o;
  77. o.vertex = UnityObjectToClipPos( v.vertex );
  78. o.texcoord = TRANSFORM_TEX( v.texcoord.xy, _MainTex );
  79. float3 eyePos = UnityObjectToViewPos( v.vertex );
  80. o.clipUV = mul( unity_GUIClipTextureMatrix, float4( eyePos.xy, 0, 1.0 ) );
  81. return o;
  82. }
  83. fixed4 frag( v2f i ) : SV_Target
  84. {
  85. float2 p = 2 * i.texcoord - 1;
  86. float r = sqrt( dot( p,p ) );
  87. float alpha = saturate( ( 1 - r )*( 45 * _InvertedZoom + 5 ) );
  88. float4 c = tex2D( _MainTex, i.texcoord );
  89. c.rgb *= _Mask.rgb;
  90. c.rgb *= alpha;
  91. c.a = tex2D( _GUIClipTexture, i.clipUV ).a;
  92. return c;
  93. }
  94. ENDCG
  95. }
  96. Pass {
  97. CGPROGRAM
  98. #pragma vertex vert
  99. #pragma fragment frag
  100. #pragma target 2.0
  101. #include "UnityCG.cginc"
  102. sampler2D _MainTex;
  103. sampler2D _BackGround;
  104. uniform float4 _MainTex_ST;
  105. uniform float4 _BackGround_ST;
  106. float _InvertedZoom;
  107. float4 _Mask;
  108. uniform float4x4 unity_GUIClipTextureMatrix;
  109. sampler2D _GUIClipTexture;
  110. struct appdata_t {
  111. float4 vertex : POSITION;
  112. float2 texcoord : TEXCOORD0;
  113. };
  114. struct v2f {
  115. float4 vertex : SV_POSITION;
  116. float2 texcoord : TEXCOORD0;
  117. float2 clipUV : TEXCOORD1;
  118. };
  119. v2f vert( appdata_t v )
  120. {
  121. v2f o;
  122. o.vertex = UnityObjectToClipPos( v.vertex );
  123. o.texcoord = TRANSFORM_TEX( v.texcoord.xy, _MainTex );
  124. float3 eyePos = UnityObjectToViewPos( v.vertex );
  125. o.clipUV = mul( unity_GUIClipTextureMatrix, float4( eyePos.xy, 0, 1.0 ) );
  126. return o;
  127. }
  128. fixed4 frag( v2f i ) : SV_Target
  129. {
  130. float3 back = tex2D( _BackGround, ( i.texcoord * 2 - 1 ) * _InvertedZoom).b;
  131. float4 c = tex2D( _MainTex, i.texcoord );
  132. c.rgb *= _Mask.rgb;
  133. c.rgb = lerp( back, c.rgb, c.a );
  134. c.a = tex2D( _GUIClipTexture, i.clipUV ).a;
  135. return c;
  136. }
  137. ENDCG
  138. }
  139. Pass {
  140. CGPROGRAM
  141. #pragma vertex vert
  142. #pragma fragment frag
  143. #pragma target 2.0
  144. #include "UnityCG.cginc"
  145. sampler2D _MainTex;
  146. sampler2D _BackGround;
  147. uniform float4 _MainTex_ST;
  148. uniform float4 _BackGround_ST;
  149. float _InvertedZoom;
  150. float4 _Mask;
  151. uniform float4x4 unity_GUIClipTextureMatrix;
  152. sampler2D _GUIClipTexture;
  153. struct appdata_t {
  154. float4 vertex : POSITION;
  155. float2 texcoord : TEXCOORD0;
  156. };
  157. struct v2f {
  158. float4 vertex : SV_POSITION;
  159. float2 texcoord : TEXCOORD0;
  160. float2 clipUV : TEXCOORD1;
  161. };
  162. v2f vert( appdata_t v )
  163. {
  164. v2f o;
  165. o.vertex = UnityObjectToClipPos( v.vertex );
  166. o.texcoord = TRANSFORM_TEX( v.texcoord.xy, _MainTex );
  167. float3 eyePos = UnityObjectToViewPos( v.vertex );
  168. o.clipUV = mul( unity_GUIClipTextureMatrix, float4( eyePos.xy, 0, 1.0 ) );
  169. return o;
  170. }
  171. fixed4 frag( v2f i ) : SV_Target
  172. {
  173. float2 p = 2 * i.texcoord - 1;
  174. float3 back = tex2D( _BackGround, p * _InvertedZoom).b;
  175. float r = sqrt( dot( p,p ) );
  176. float alpha = saturate( ( 1 - r )*( 45 * _InvertedZoom + 5 ) );
  177. float4 c = 0;
  178. c = tex2D( _MainTex, i.texcoord );
  179. c.rgb *= _Mask.rgb;
  180. c.rgb = lerp( back, c.rgb, c.a * alpha);
  181. c.a = tex2D( _GUIClipTexture, i.clipUV ).a;
  182. return c;
  183. }
  184. ENDCG
  185. }
  186. }
  187. Fallback Off
  188. }