1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196
| Shader "HHF/Example/SequenceEffect" { Properties { [Enum(UnityEngine.Rendering.BlendMode)]_SrcFactor("SrcFactor",int) = 1 [Enum(UnityEngine.Rendering.BlendMode)]_DstFactor("DstFactor",int) = 1 _BaseColor("Base Color",color) = (1,1,1,1) [NoScaleOffset]_BaseMap("BaseMap", 2D) = "white" {} _Sequence("Row(X) Column(Y) Speed(Z)", vector) = (3,3,3,0) [Enum(Billboard,1,VerticalBillboard,0)]_BillboardType("BillboardType",int) = 1 }
SubShader { Tags { "Queue" = "Transparent" "RenderType" = "Transparent" "IgnoreProjector" = "True" "RenderPipeline" = "UniversalPipeline" } Blend [_SrcFactor] [_DstFactor]
Pass { HLSLPROGRAM #pragma prefer_hlslcc gles #pragma exclude_renderers d3d11_9x #pragma vertex vert #pragma fragment frag #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Color.hlsl" #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl" #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl" #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/ShaderGraphFunctions.hlsl"
struct appdata { float4 vertex : POSITION; float2 uv : TEXCOORD0; };
struct v2f { float4 positionCS : SV_POSITION; float2 uv : TEXCOORD0; };
CBUFFER_START(UnityPerMaterial) half4 _BaseColor; half4 _Sequence; half _BillboardType; CBUFFER_END TEXTURE2D (_BaseMap); SAMPLER(sampler_BaseMap); float4 _BaseMap_ST;
v2f vert(appdata v) { v2f o = (v2f)0;
float3 viewDir = mul(GetWorldToObjectMatrix(), float4(_WorldSpaceCameraPos, 1)).xyz; viewDir = normalize(viewDir); viewDir.y *= _BillboardType; float3 upDir = float3(0, 1, 0); float3 rightDir = normalize(cross(viewDir, upDir)); upDir = cross(rightDir, viewDir);
float4x4 M = float4x4( rightDir.x, upDir.x, viewDir.x,0, rightDir.y, upDir.y, viewDir.y,0, rightDir.z, upDir.z, viewDir.z,0, 0,0,0,1 ); float3 newVertex = mul(M, v.vertex).xyz;
o.positionCS = TransformObjectToHClip(newVertex);
o.uv = float2(v.uv.x/_Sequence.y,v.uv.y/_Sequence.x+1/_Sequence.x*(_Sequence.x-1)); o.uv.x += frac(floor(_Time.y * _Sequence.z)/_Sequence.y); o.uv.y -= frac(floor(_Time.y * _Sequence.z/_Sequence.y)/_Sequence.x);
return o; }
half4 frag(v2f i) : SV_Target { half4 c; half4 baseMap = SAMPLE_TEXTURE2D(_BaseMap, sampler_BaseMap, i.uv); c = baseMap * _BaseColor; c.rgb *= c.a; return c; } ENDHLSL } }
SubShader { Tags { "Queue" = "Transparent" "RenderType" = "Transparent" "IgnoreProjector" = "True" }
Blend [_SrcFactor] [_DstFactor]
Pass { CGPROGRAM #pragma vertex vert #pragma fragment frag #include "UnityCG.cginc"
struct appdata { float4 vertex : POSITION; float2 uv : TEXCOORD0; };
struct v2f { float2 uv : TEXCOORD0; float4 positionCS : SV_POSITION; };
sampler2D _BaseMap; half4 _BaseColor; half4 _Sequence; fixed _BillboardType;
v2f vert (appdata v) { v2f o = (v2f)0;
float3 viewDir = mul(unity_WorldToObject,float4(_WorldSpaceCameraPos,1)); viewDir = normalize(viewDir); viewDir.y *= _BillboardType; float3 upDir = float3(0,1,0); float3 rightDir = normalize(cross(viewDir,upDir)); upDir = cross(rightDir,viewDir);
float4x4 M = float4x4( rightDir.x,upDir.x,viewDir.x,0, rightDir.y,upDir.y,viewDir.y,0, rightDir.z,upDir.z,viewDir.z,0, 0,0,0,1 ); float3 newVertex = mul(M, v.vertex).xyz;
o.positionCS = UnityObjectToClipPos(newVertex);
o.uv = float2(v.uv.x/_Sequence.y,v.uv.y/_Sequence.x+1/_Sequence.x*(_Sequence.x-1)); o.uv.x += frac(floor(_Time.y * _Sequence.z)/_Sequence.y); o.uv.y -= frac(floor(_Time.y * _Sequence.z/_Sequence.y)/_Sequence.x);
return o; }
fixed4 frag (v2f i) : SV_Target { half4 c; half4 baseMap = tex2D(_BaseMap, i.uv); c = baseMap * _BaseColor; c.rgb *= c.a; return c; } ENDCG } } }
|