Advertisement
gonzo98x

Shader

Jun 8th, 2023
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.74 KB | None | 0 0
  1. Shader "GlowCutout" {
  2. Properties{
  3. [HDR]_TintColor("Tint Color", Color) = (0.5,0.5,0.5,1)
  4. _TimeScale("Time Scale", Vector) = (1,1,1,1)
  5. _MainTex("Noise Texture", 2D) = "white" {}
  6. _BorderScale("Border Scale (XY) Offset (Z)", Vector) = (0.5,0.05,1,0)
  7. }
  8.  
  9. Category{
  10. Tags{ "Queue" = "Transparent" "IgnoreProjector" = "True" "RenderType" = "Transparent" }
  11. Blend SrcAlpha OneMinusSrcAlpha
  12. Cull Off
  13. ZWrite Off
  14. Offset -1, -1
  15.  
  16. SubShader{
  17. Pass{
  18.  
  19. CGPROGRAM
  20. #pragma vertex vert
  21. #pragma fragment frag
  22. #pragma multi_compile_instancing
  23. #pragma multi_compile_fog
  24.  
  25. #include "UnityCG.cginc"
  26.  
  27. sampler2D _MainTex;
  28. float4 _TintColor;
  29. float4 _TimeScale;
  30. float4 _BorderScale;
  31.  
  32. struct appdata_t {
  33. float4 vertex : POSITION;
  34. fixed4 color : COLOR;
  35. float2 texcoord : TEXCOORD0;
  36. float3 normal : NORMAL;
  37. UNITY_VERTEX_INPUT_INSTANCE_ID
  38. };
  39.  
  40. struct v2f {
  41. float4 vertex : POSITION;
  42. fixed4 color : COLOR;
  43. float2 texcoord : TEXCOORD0;
  44. float3 normal : NORMAL;
  45. float3 worldPosScaled : TEXCOORD1;
  46.  
  47. UNITY_FOG_COORDS(2)
  48. UNITY_VERTEX_INPUT_INSTANCE_ID
  49. UNITY_VERTEX_OUTPUT_STEREO
  50. };
  51.  
  52. float4 _MainTex_ST;
  53.  
  54. v2f vert(appdata_t v)
  55. {
  56. v2f o;
  57.  
  58. UNITY_SETUP_INSTANCE_ID(v);
  59. UNITY_TRANSFER_INSTANCE_ID(v, o);
  60. UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
  61.  
  62. v.vertex.xyz += v.normal / 100 * _BorderScale.z;
  63. o.vertex = UnityObjectToClipPos(v.vertex);
  64. o.color = 1;
  65. o.texcoord = TRANSFORM_TEX(v.texcoord,_MainTex);
  66. float3 worldPos = v.vertex * float3(length(unity_ObjectToWorld[0].xyz), length(unity_ObjectToWorld[1].xyz), length(unity_ObjectToWorld[2].xyz));
  67. o.worldPosScaled = worldPos.xyz * _MainTex_ST.x;
  68. o.normal = abs(v.normal);
  69.  
  70. UNITY_TRANSFER_FOG(o, o.vertex);
  71. return o;
  72. }
  73.  
  74. half2 tex2DTriplanar(sampler2D tex, float2 offset, float3 worldPos, float3 normal)
  75. {
  76. half2 yDiff = tex2D(tex, worldPos.xz + offset);
  77. half2 xDiff = tex2D(tex, worldPos.zy + offset);
  78. half2 zDiff = tex2D(tex, worldPos.xy + offset);
  79. normal = normal / (normal.x + normal.y + normal.z);
  80. return xDiff * normal.x + yDiff * normal.y + zDiff * normal.z;
  81. }
  82.  
  83. half4 frag(v2f i) : COLOR
  84. {
  85. UNITY_SETUP_INSTANCE_ID(i);
  86. half2 mask = tex2DTriplanar(_MainTex, _Time.xx * _TimeScale.xy, i.worldPosScaled, i.normal);
  87. half2 tex = tex2DTriplanar(_MainTex, mask + _Time.xx * _TimeScale.zw, i.worldPosScaled, i.normal);
  88. float4 res = 0;
  89. #if (!UNITY_COLORSPACE_GAMMA)
  90. //tex = pow(tex, 0.45);
  91.  
  92. #endif
  93. res.r = step(tex.r, _BorderScale.x);
  94. res.r -= step(tex.r, _BorderScale.x - _BorderScale.y);
  95. res.r *= tex.g;
  96.  
  97. res = res.r * i.color * _TintColor;
  98. res.a = saturate(res.a);
  99. res = res * _TintColor.a;
  100.  
  101. UNITY_APPLY_FOG(i.fogCoord, res);
  102.  
  103. return res;
  104. }
  105. ENDCG
  106. }
  107. }
  108. }
  109.  
  110. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement