Advertisement
axoila

PowerText.shader

Feb 20th, 2018
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.78 KB | None | 0 0
  1. Shader "Custom/PowerText"
  2. {
  3. Properties
  4. {
  5. _MainTex ("Texture", 2D) = "white" {}
  6. _Noise ("Noise", 2D) = "white" {}
  7. _Color ("Color", Color) = (1,1,1,1)
  8. _Frequency ("Shake Frequency", float) = 1
  9. _Amplitude ("Shake Intensity", float) = 10
  10. }
  11. SubShader
  12. {
  13. Tags { "RenderType"="Transparent" "Queue"="Transparent"}
  14. Blend SrcAlpha OneMinusSrcAlpha
  15. LOD 100
  16. ZWrite Off
  17. ZTest Off
  18.  
  19.  
  20. Pass
  21. {
  22. CGPROGRAM
  23. #pragma vertex vert
  24. #pragma fragment frag
  25. #pragma geometry geom
  26.  
  27. #include "UnityCG.cginc"
  28.  
  29. struct appdata
  30. {
  31. float4 vertex : POSITION;
  32. float2 uv : TEXCOORD0;
  33. float4 vertColor : COLOR;
  34. };
  35.  
  36. struct v2g
  37. {
  38. float2 uv : TEXCOORD0;
  39. float4 vertex : SV_POSITION;
  40. float4 vertColor : COLOR;
  41. };
  42.  
  43. struct g2f
  44. {
  45. float2 uv : TEXCOORD0;
  46. float4 vertex : SV_POSITION;
  47. float4 vertColor : COLOR;
  48. float2 charPos : TEXCOORD1;
  49. };
  50.  
  51. sampler2D _MainTex;
  52. sampler2D _Noise;
  53. float4 _MainTex_ST;
  54. float4 _Color;
  55.  
  56. float _Frequency;
  57. float _Amplitude;
  58.  
  59. float3 HUEtoRGB(in float H)
  60. {
  61. float R = abs(H * 6 - 3) - 1;
  62. float G = 2 - abs(H * 6 - 2);
  63. float B = 2 - abs(H * 6 - 4);
  64. return saturate(float3(R,G,B));
  65. }
  66.  
  67. v2g vert (appdata v)
  68. {
  69. v2g o;
  70. o.vertex = UnityObjectToClipPos(v.vertex);
  71. o.uv = TRANSFORM_TEX(v.uv, _MainTex);
  72. o.vertColor = v.vertColor;
  73. return o;
  74. }
  75.  
  76. [maxvertexcount(3)]
  77. void geom(triangle v2g IN[3], inout TriangleStream<g2f> triStream) {
  78. float4 offset = float4(0,0,0,0);
  79.  
  80. float3 EdgeA = IN[0].vertex - IN[1].vertex;
  81. float3 EdgeB = IN[1].vertex - IN[2].vertex;
  82. float3 EdgeC = IN[2].vertex - IN[0].vertex;
  83.  
  84. float3 center;
  85.  
  86. if(length(EdgeA) > length(EdgeB) && length(EdgeA) > length(EdgeC))
  87. center = IN[1].vertex + EdgeA * 0.5;
  88. else if (length(EdgeB) > length(EdgeC) && length(EdgeB) > length(EdgeA))
  89. center = IN[2].vertex + EdgeB * 0.5;
  90. else
  91. center = IN[0].vertex + EdgeC * 0.5;
  92.  
  93. if(IN[0].vertColor.r > 0){
  94. float2 offsetUV = float2(0, _Time.y * _Frequency) + center.xy * 1000;
  95. offset = tex2Dlod(_Noise, float4(offsetUV, 0,0))*2-1;
  96. offset *= _Amplitude;
  97. }
  98.  
  99. g2f o;
  100. [unroll]
  101. for(int i=0;i<3;i++){
  102. o.vertex = IN[i].vertex + offset;
  103. o.uv = IN[i].uv;
  104. o.vertColor = IN[i].vertColor;
  105. o.charPos = center;
  106. triStream.Append(o);
  107. }
  108. }
  109.  
  110. fixed4 frag (g2f i) : SV_Target
  111. {
  112. // sample the texture
  113. fixed4 col = 1;
  114. if(i.vertColor.g <= 0) {
  115. col = _Color;
  116. } else {
  117. col.rgb = HUEtoRGB(fmod(_Time.y + i.charPos.x, 1));
  118. }
  119. col.a = tex2D(_MainTex, i.uv).a;
  120.  
  121. return col;
  122. }
  123. ENDCG
  124. }
  125. }
  126. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement