2
0

Highlight.shader 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  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/Highlight"
  8. {
  9. Properties
  10. {
  11. _TintColor( "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. _MainTex( "MainTex", 2D ) = "white" {}
  15. }
  16. //-------------------------------------------------------------------------------------------------------------------------------------------------------------
  17. CGINCLUDE
  18. // Pragmas --------------------------------------------------------------------------------------------------------------------------------------------------
  19. #pragma target 5.0
  20. #if UNITY_VERSION >= 560
  21. #pragma only_renderers d3d11 vulkan glcore
  22. #else
  23. #pragma only_renderers d3d11 glcore
  24. #endif
  25. #pragma exclude_renderers gles
  26. #pragma multi_compile_instancing
  27. // Includes -------------------------------------------------------------------------------------------------------------------------------------------------
  28. #include "UnityCG.cginc"
  29. // Structs --------------------------------------------------------------------------------------------------------------------------------------------------
  30. struct VertexInput
  31. {
  32. float4 vertex : POSITION;
  33. float2 uv : TEXCOORD0;
  34. fixed4 color : COLOR;
  35. #if UNITY_VERSION >= 560
  36. UNITY_VERTEX_INPUT_INSTANCE_ID
  37. #endif
  38. };
  39. struct VertexOutput
  40. {
  41. float2 uv : TEXCOORD0;
  42. float4 vertex : SV_POSITION;
  43. fixed4 color : COLOR;
  44. #if UNITY_VERSION >= 560
  45. UNITY_VERTEX_OUTPUT_STEREO
  46. #endif
  47. };
  48. #if UNITY_VERSION >= 201810
  49. // Globals --------------------------------------------------------------------------------------------------------------------------------------------------
  50. UNITY_INSTANCING_BUFFER_START( Props )
  51. UNITY_DEFINE_INSTANCED_PROP( float4, _TintColor )
  52. UNITY_DEFINE_INSTANCED_PROP( sampler2D, _MainTex )
  53. UNITY_DEFINE_INSTANCED_PROP( float4, _MainTex_ST )
  54. UNITY_DEFINE_INSTANCED_PROP( float, _SeeThru )
  55. UNITY_DEFINE_INSTANCED_PROP( float, _Darken )
  56. UNITY_INSTANCING_BUFFER_END( Props )
  57. // MainVs ---------------------------------------------------------------------------------------------------------------------------------------------------
  58. VertexOutput MainVS( VertexInput i )
  59. {
  60. VertexOutput o;
  61. UNITY_SETUP_INSTANCE_ID( i );
  62. UNITY_INITIALIZE_OUTPUT( VertexOutput, o );
  63. UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO( o );
  64. #if UNITY_VERSION >= 540
  65. o.vertex = UnityObjectToClipPos( i.vertex );
  66. #else
  67. o.vertex = mul( UNITY_MATRIX_MVP, i.vertex );
  68. #endif
  69. o.uv = i.uv;
  70. o.color = i.color;
  71. return o;
  72. }
  73. // MainPs ---------------------------------------------------------------------------------------------------------------------------------------------------
  74. float4 MainPS( VertexOutput i ) : SV_Target
  75. {
  76. UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO( i );
  77. float4 vTexel = tex2D( UNITY_ACCESS_INSTANCED_PROP( Props, _MainTex ), i.uv ).rgba;
  78. float4 vColor = vTexel.rgba * UNITY_ACCESS_INSTANCED_PROP( Props, _TintColor.rgba ) * i.color.rgba;
  79. vColor.rgba = saturate( 2.0 * vColor.rgba );
  80. float flAlpha = vColor.a;
  81. vColor.rgb *= vColor.a;
  82. vColor.a = lerp( 0.0, UNITY_ACCESS_INSTANCED_PROP( Props, _Darken ), flAlpha );
  83. return vColor.rgba;
  84. }
  85. // MainPs ---------------------------------------------------------------------------------------------------------------------------------------------------
  86. float4 SeeThruPS( VertexOutput i ) : SV_Target
  87. {
  88. UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO( i );
  89. float4 vTexel = tex2D( UNITY_ACCESS_INSTANCED_PROP( Props, _MainTex ), i.uv ).rgba;
  90. float4 vColor = vTexel.rgba * UNITY_ACCESS_INSTANCED_PROP( Props, _TintColor.rgba ) * i.color.rgba * UNITY_ACCESS_INSTANCED_PROP( Props, _SeeThru );
  91. vColor.rgba = saturate( 2.0 * vColor.rgba );
  92. float flAlpha = vColor.a;
  93. vColor.rgb *= vColor.a;
  94. vColor.a = lerp( 0.0, UNITY_ACCESS_INSTANCED_PROP( Props, _Darken ), flAlpha * UNITY_ACCESS_INSTANCED_PROP( Props, _SeeThru ) );
  95. return vColor.rgba;
  96. }
  97. #else
  98. // Globals --------------------------------------------------------------------------------------------------------------------------------------------------
  99. sampler2D _MainTex;
  100. float4 _MainTex_ST;
  101. float4 _TintColor;
  102. float _SeeThru;
  103. float _Darken;
  104. // MainVs ---------------------------------------------------------------------------------------------------------------------------------------------------
  105. VertexOutput MainVS( VertexInput i )
  106. {
  107. VertexOutput o;
  108. #if UNITY_VERSION >= 540
  109. o.vertex = UnityObjectToClipPos(i.vertex);
  110. #else
  111. o.vertex = mul(UNITY_MATRIX_MVP, i.vertex);
  112. #endif
  113. o.uv = TRANSFORM_TEX( i.uv, _MainTex );
  114. o.color = i.color;
  115. return o;
  116. }
  117. // MainPs ---------------------------------------------------------------------------------------------------------------------------------------------------
  118. float4 MainPS( VertexOutput i ) : SV_Target
  119. {
  120. float4 vTexel = tex2D( _MainTex, i.uv ).rgba;
  121. float4 vColor = vTexel.rgba * _TintColor.rgba * i.color.rgba;
  122. vColor.rgba = saturate( 2.0 * vColor.rgba );
  123. float flAlpha = vColor.a;
  124. vColor.rgb *= vColor.a;
  125. vColor.a = lerp( 0.0, _Darken, flAlpha );
  126. return vColor.rgba;
  127. }
  128. // MainPs ---------------------------------------------------------------------------------------------------------------------------------------------------
  129. float4 SeeThruPS( VertexOutput i ) : SV_Target
  130. {
  131. float4 vTexel = tex2D( _MainTex, i.uv ).rgba;
  132. float4 vColor = vTexel.rgba * _TintColor.rgba * i.color.rgba * _SeeThru;
  133. vColor.rgba = saturate( 2.0 * vColor.rgba );
  134. float flAlpha = vColor.a;
  135. vColor.rgb *= vColor.a;
  136. vColor.a = lerp( 0.0, _Darken, flAlpha * _SeeThru );
  137. return vColor.rgba;
  138. }
  139. #endif
  140. ENDCG
  141. SubShader
  142. {
  143. Tags { "Queue" = "Transparent" "RenderType" = "Transparent" }
  144. LOD 100
  145. // Behind Geometry ---------------------------------------------------------------------------------------------------------------------------------------------------
  146. Pass
  147. {
  148. // Render State ---------------------------------------------------------------------------------------------------------------------------------------------
  149. Blend One OneMinusSrcAlpha
  150. Cull Off
  151. ZWrite Off
  152. ZTest Greater
  153. CGPROGRAM
  154. #pragma vertex MainVS
  155. #pragma fragment SeeThruPS
  156. ENDCG
  157. }
  158. Pass
  159. {
  160. // Render State ---------------------------------------------------------------------------------------------------------------------------------------------
  161. Blend One OneMinusSrcAlpha
  162. Cull Off
  163. ZWrite Off
  164. ZTest LEqual
  165. CGPROGRAM
  166. #pragma vertex MainVS
  167. #pragma fragment MainPS
  168. ENDCG
  169. }
  170. }
  171. }