Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Shader "Trail"
- {
- Properties
- {
- _Color("Main Color", Color) = (1,1,1,1)
- _Width("Width", float) = 0.2
- }
- SubShader
- {
- Tags
- {
- "Queue" = "Transparent"
- "IgnoreProjector" = "True"
- "RenderType" = "Opaque"
- }
- Pass
- {
- Cull Back
- Lighting Off
- ZWrite Off
- Blend OneMinusDstColor OneMinusSrcColor
- CGPROGRAM
- #pragma vertex vert
- #pragma fragment frag
- #include "MyriadCG.cginc"
- uniform fixed4 _Color;
- uniform float2 _Trail[600];
- uniform int _Samples;
- uniform float _Width;
- uniform float2 _Ref;
- struct v2f
- {
- float4 vertex : SV_POSITION;
- };
- inline float unlerp(float min, float max, float value)
- {
- return clamp((value - min) / (max - min), 0, 1);
- }
- v2f vert(uint index : SV_VertexID)
- {
- int sign = ((index % 2) * 2) - 1;
- int current = clamp(floor((float)index * 0.5), 0, _Samples);
- int prev = current + 1;
- float2 prevPosition = mul(unity_WorldToObject, _Trail[current] - _Ref);
- float2 currentPosition= mul(unity_WorldToObject, _Trail[prev] - _Ref);
- float2 direction = normalize(currentPosition - prevPosition);
- float2 perpendicular = float2(-direction.y, direction.x) * sign;
- v2f output;
- output.vertex = UnityObjectToClipPos(float4(currentPosition + (perpendicular * 0.2 * 0.5 * unlerp(0, _Samples, current)), 0, 0));
- return output;
- }
- fixed4 frag(void) : COLOR
- {
- return _Color;
- }
- ENDCG
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement