SciFiHologramShader.shader 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. // Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'
  2. // Upgrade NOTE: replaced '_Object2World' with 'unity_ObjectToWorld'
  3. Shader "Zololgo/Sci-Fi Hologram"
  4. {
  5. Properties
  6. {
  7. _Brightness ("Brightness", Range(0,4)) = 1
  8. _Fade ("Fade", Range(0,1)) = 0
  9. _RimColor ("Tint", Color) = (0.5,0.5,0.5,1)
  10. _RimStrenght ("Rim strength", Range(0,2)) = 0
  11. _RimFalloff ("Rim falloff", Range(0,1)) = 1
  12. _Color ("Tint", Color) = (0.5,0.5,0.5,1)
  13. _MainTex ("Color(RGB) Fade(A)", 2D) = "grey" {}
  14. _Scanlines ("Scanlines", 2D) = "white" {}
  15. _Scan2 ("Scanlines 2 ", 2D) = "white" {}
  16. _ScanStr ("Strength", Range(0,1)) = 1
  17. _ScanStr2 ("Strength", Range(0,1)) = 0
  18. }
  19. SubShader
  20. {
  21. Tags { "RenderType"="Transparent" "Queue"="Transparent"}
  22. LOD 100
  23. Pass
  24. {
  25. zwrite off
  26. blend one one
  27. cull off
  28. CGPROGRAM
  29. #pragma vertex vert
  30. #pragma fragment frag
  31. #include "UnityCG.cginc"
  32. #pragma multi_compile SCAN2_OFF SCAN2_ON
  33. sampler2D _MainTex, _Scanlines, _Scan2;
  34. float4 _Color, _RimColor, _MainTex_ST, _Scanlines_ST, _Scan2_ST;
  35. float _Fade, _RimStrenght, _Brightness, _RimFalloff, _ScanStr, _ScanStr2;
  36. struct appdata
  37. {
  38. float4 vertex : POSITION;
  39. float4 normal : NORMAL;
  40. float4 color : COLOR;
  41. float2 uv_main : TEXCOORD0;
  42. };
  43. struct v2f
  44. {
  45. float4 vertex : SV_POSITION;
  46. float4 color : COLOR;
  47. float2 uv_main : TEXCOORD0;
  48. float2 scanlines_uv : TEXCOORD1;
  49. float2 scan2_uv : TEXCOORD2;
  50. };
  51. v2f vert (appdata v)
  52. {
  53. v2f o;
  54. o.vertex = UnityObjectToClipPos(v.vertex);
  55. o.uv_main = TRANSFORM_TEX(v.uv_main, _MainTex);
  56. float4 screenPosOrigin = ComputeScreenPos(UnityObjectToClipPos(half4(0,0,0,1)));
  57. float4 screenPos = ComputeScreenPos(o.vertex);
  58. float dis = length(ObjSpaceViewDir(half4(0,0,0,0)));
  59. float3 worldPos = mul(unity_ObjectToWorld, v.vertex).xyz;
  60. float2 flicker_uv = screenPos.xy / screenPos.w - screenPosOrigin.xy / screenPosOrigin.w;
  61. flicker_uv.y = worldPos.y; // y-on világkoordináta, flicker térbleiséghez kell
  62. o.scanlines_uv = flicker_uv * _Scanlines_ST.xy + frac(_Time.x*_Scanlines_ST.zw);
  63. o.scan2_uv = o.scanlines_uv;
  64. #if SCAN2_ON
  65. o.scan2_uv = flicker_uv * _Scan2_ST.xy + frac(_Time.x*_Scan2_ST.zw);
  66. #endif
  67. float3 viewDir = normalize(ObjSpaceViewDir(v.vertex));
  68. float fresnel_rim = 1 - abs(dot(v.normal, viewDir));
  69. float fresnel_dissolve = 1 - dot(v.normal, viewDir);
  70. o.color = _Color*max(0,lerp(1,(0.5-fresnel_dissolve),_Fade*2.0)) + lerp(0,smoothstep(1 - _RimFalloff, 1.0, fresnel_rim), _RimStrenght) * _RimColor * 2.0;
  71. return o;
  72. }
  73. fixed4 frag (v2f i) : SV_Target
  74. {
  75. fixed4 main = tex2D(_MainTex, i.uv_main) * _Brightness;
  76. fixed4 rim = i.color;
  77. fixed4 pri = tex2D (_Scanlines, i.scanlines_uv) * _ScanStr;
  78. fixed4 msk = fixed4(0,0,0,0);
  79. #if SCAN2_ON
  80. msk = tex2D (_Scan2, i.scan2_uv) * _ScanStr2;
  81. #endif
  82. return main * max(pri,msk) * rim * fixed4(0.5,0.5,0.5,0.5);
  83. }
  84. ENDCG
  85. }
  86. }
  87. CustomEditor "SciFiHologramShaderGUI"
  88. }