HighlighGlobal.shader 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. //======= Copyright (c) Valve Corporation, All rights reserved. ===============
  2. //
  3. // Purpose: Used for the teleport markers
  4. //
  5. //=============================================================================
  6. // UNITY_SHADER_NO_UPGRADE
  7. Shader "Valve/VR/HighlightPlanar"
  8. {
  9. Properties
  10. {
  11. _Color( "Tint Color", Color ) = ( 1, 1, 1, 1 )
  12. _SeeThru( "SeeThru", Range( 0.0, 1.0 ) ) = 0.25
  13. _Darken( "Darken", Range( 0.0, 1.0 ) ) = 0.0
  14. _Scl("Mapping Scale", Float) = 2.0
  15. _MainTex( "MainTex", 2D ) = "white" {}
  16. }
  17. //-------------------------------------------------------------------------------------------------------------------------------------------------------------
  18. CGINCLUDE
  19. // Pragmas --------------------------------------------------------------------------------------------------------------------------------------------------
  20. #pragma target 5.0
  21. #pragma only_renderers d3d11 vulkan glcore
  22. #pragma exclude_renderers gles
  23. // Includes -------------------------------------------------------------------------------------------------------------------------------------------------
  24. #include "UnityCG.cginc"
  25. // Structs --------------------------------------------------------------------------------------------------------------------------------------------------
  26. struct VertexInput
  27. {
  28. float4 vertex : POSITION;
  29. float2 uv : TEXCOORD0;
  30. fixed4 color : COLOR;
  31. };
  32. struct VertexOutput
  33. {
  34. float2 uv : TEXCOORD0;
  35. float4 vertex : SV_POSITION;
  36. fixed4 color : COLOR;
  37. float3 pos : TEXCOORD1;
  38. };
  39. // Globals --------------------------------------------------------------------------------------------------------------------------------------------------
  40. sampler2D _MainTex;
  41. float4 _MainTex_ST;
  42. float4 _Color;
  43. float _SeeThru;
  44. float _Darken;
  45. float _Scl;
  46. // MainVs ---------------------------------------------------------------------------------------------------------------------------------------------------
  47. VertexOutput MainVS( VertexInput i )
  48. {
  49. VertexOutput o;
  50. #if UNITY_VERSION >= 540
  51. o.vertex = UnityObjectToClipPos(i.vertex);
  52. #else
  53. o.vertex = mul(UNITY_MATRIX_MVP, i.vertex);
  54. #endif
  55. o.uv = TRANSFORM_TEX( i.uv, _MainTex );
  56. o.pos = mul(unity_ObjectToWorld, i.vertex);
  57. o.color = i.color;
  58. return o;
  59. }
  60. // MainPs ---------------------------------------------------------------------------------------------------------------------------------------------------
  61. float4 MainPS( VertexOutput i ) : SV_Target
  62. {
  63. float4 vTexel = tex2D( _MainTex, i.pos.xz / _Scl).rgba;
  64. if (length(i.uv)==0) {
  65. vTexel = float4(1, 1, 1, 1);
  66. }
  67. float4 vColor = vTexel.rgba * _Color.rgba * i.color.rgba;
  68. vColor.rgba = saturate( 2.0 * vColor.rgba );
  69. float flAlpha = vColor.a;
  70. vColor.rgb *= vColor.a;
  71. vColor.a = lerp( 0.0, _Darken, flAlpha );
  72. return vColor.rgba;
  73. }
  74. // MainPs ---------------------------------------------------------------------------------------------------------------------------------------------------
  75. float4 SeeThruPS( VertexOutput i ) : SV_Target
  76. {
  77. float4 vTexel = tex2D( _MainTex, i.pos.xz /_Scl).rgba;
  78. float4 vColor = vTexel.rgba * _Color.rgba * i.color.rgba * _SeeThru;
  79. vColor.rgba = saturate( 2.0 * vColor.rgba );
  80. float flAlpha = vColor.a;
  81. vColor.rgb *= vColor.a;
  82. vColor.a = lerp( 0.0, _Darken, flAlpha * _SeeThru );
  83. return vColor.rgba;
  84. }
  85. ENDCG
  86. SubShader
  87. {
  88. Tags{ "Queue" = "Transparent" "RenderType" = "Transparent" }
  89. LOD 100
  90. // Behind Geometry ---------------------------------------------------------------------------------------------------------------------------------------------------
  91. Pass
  92. {
  93. // Render State ---------------------------------------------------------------------------------------------------------------------------------------------
  94. Blend One OneMinusSrcAlpha
  95. Cull Off
  96. ZWrite Off
  97. ZTest Greater
  98. CGPROGRAM
  99. #pragma vertex MainVS
  100. #pragma fragment SeeThruPS
  101. ENDCG
  102. }
  103. Pass
  104. {
  105. // Render State ---------------------------------------------------------------------------------------------------------------------------------------------
  106. Blend One OneMinusSrcAlpha
  107. Cull Off
  108. ZWrite Off
  109. ZTest LEqual
  110. CGPROGRAM
  111. #pragma vertex MainVS
  112. #pragma fragment MainPS
  113. ENDCG
  114. }
  115. }
  116. }