无缝贴图使用该shader,在移动过程中可以无限延伸,保持固定位置。
Shader "TransparentWire"
{
Properties
{
_Texture0("Texture 0", 2D) = "white" {}
_YNormal("YNormal", Float) = 0.5
_XNormal("XNormal", Float) = 0.5
_Multiply("Multiply", Float) = 2
_Texture1("Texture 1", 2D) = "white" {}
_alpha("alpha",Float)=1
[HideInInspector] _texcoord( "", 2D ) = "white" {}
}
SubShader
{
Tags { "RenderType"="Opaque" }
LOD 100
CGINCLUDE
#pragma target 3.0
ENDCG
Blend SrcAlpha OneMinusSrcAlpha
AlphaToMask Off
Cull Back
ColorMask RGBA
ZWrite Off
ZTest LEqual
Offset 0 , 0
Pass
{
Name "Unlit"
Tags { "LightMode"="ForwardBase" }
CGPROGRAM
#ifndef UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX
//only defining to not throw compilation error over Unity 5.5
#define UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input)
#endif
#pragma vertex vert
#pragma fragment frag
#pragma multi_compile_instancing
#include "UnityCG.cginc"
#define ASE_NEEDS_FRAG_WORLD_POSITION
struct appdata
{
float4 vertex : POSITION;
float4 color : COLOR;
half3 ase_normal : NORMAL;
float4 ase_texcoord : TEXCOORD0;
UNITY_VERTEX_INPUT_INSTANCE_ID
};
struct v2f
{
float4 vertex : SV_POSITION;
#ifdef ASE_NEEDS_FRAG_WORLD_POSITION
float3 worldPos : TEXCOORD0;
#endif
float4 ase_texcoord1 : TEXCOORD1;
float4 ase_texcoord2 : TEXCOORD2;
UNITY_VERTEX_INPUT_INSTANCE_ID
UNITY_VERTEX_OUTPUT_STEREO
};
uniform sampler2D _Texture0;
uniform half _XNormal;
uniform half _YNormal;
uniform half _Multiply;
uniform sampler2D _Texture1;
uniform half4 _Texture1_ST;
uniform half _alpha;
v2f vert ( appdata v )
{
v2f o;
UNITY_SETUP_INSTANCE_ID(v);
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
UNITY_TRANSFER_INSTANCE_ID(v, o);
half3 ase_worldNormal = UnityObjectToWorldNormal(v.ase_normal);
o.ase_texcoord1.xyz = ase_worldNormal;
o.ase_texcoord2.xy = v.ase_texcoord.xy;
//setting value to unused interpolator channels and avoid initialization warnings
o.ase_texcoord1.w = 0;
o.ase_texcoord2.zw = 0;
float3 vertexValue = float3(0, 0, 0);
#if ASE_ABSOLUTE_VERTEX_POS
vertexValue = v.vertex.xyz;
#endif
vertexValue = vertexValue;
#if ASE_ABSOLUTE_VERTEX_POS
v.vertex.xyz = vertexValue;
#else
v.vertex.xyz += vertexValue;
#endif
o.vertex = UnityObjectToClipPos(v.vertex);
#ifdef ASE_NEEDS_FRAG_WORLD_POSITION
o.worldPos = mul(unity_ObjectToWorld, v.vertex).xyz;
#endif
return o;
}
fixed4 frag (v2f i ) : SV_Target
{
UNITY_SETUP_INSTANCE_ID(i);
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(i);
fixed4 finalColor;
#ifdef ASE_NEEDS_FRAG_WORLD_POSITION
float3 WorldPosition = i.worldPos;
#endif
half3 ase_worldNormal = i.ase_texcoord1.xyz;
half3 normalizedWorldNormal = normalize( ase_worldNormal );
half3 temp_output_83_0 = abs( normalizedWorldNormal );
half3 temp_output_98_0 = ( _Multiply * WorldPosition );
half temp_output_113_0 = (temp_output_98_0).x;
half temp_output_114_0 = (temp_output_98_0).y;
half2 appendResult77 = (half2(temp_output_113_0 , temp_output_114_0));
half temp_output_115_0 = (temp_output_98_0).z;
half2 appendResult78 = (half2(temp_output_113_0 , temp_output_115_0));
half2 ifLocalVar70 = 0;
if( _YNormal >= (temp_output_83_0).y )
ifLocalVar70 = appendResult77;
else
ifLocalVar70 = appendResult78;
half2 appendResult79 = (half2(temp_output_114_0 , temp_output_115_0));
half2 ifLocalVar72 = 0;
if( _XNormal >= (temp_output_83_0).x )
ifLocalVar72 = ifLocalVar70;
else
ifLocalVar72 = appendResult79;
float2 uv_Texture1 = i.ase_texcoord2.xy * _Texture1_ST.xy + _Texture1_ST.zw;
finalColor = ( tex2D( _Texture0, ifLocalVar72 ) * tex2D( _Texture1, uv_Texture1 ).r *_alpha);
return finalColor;
}
ENDCG
}
}
CustomEditor "ASEMaterialInspector"
}
|