SeeThru.shader 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. //======= Copyright (c) Valve Corporation, All rights reserved. ===============
  2. //
  3. // Purpose: Used for objects that can be seen through objects in front of them
  4. //
  5. //=============================================================================
  6. // UNITY_SHADER_NO_UPGRADE
  7. Shader "Valve/VR/SeeThru"
  8. {
  9. Properties
  10. {
  11. _Color( "Color", Color ) = ( 1, 1, 1, 1 )
  12. }
  13. SubShader
  14. {
  15. Tags{ "Queue" = "Geometry+1" "RenderType" = "Transparent" }
  16. LOD 100
  17. Pass
  18. {
  19. // Render State ---------------------------------------------------------------------------------------------------------------------------------------------
  20. Blend SrcAlpha OneMinusSrcAlpha // Alpha blending
  21. Cull Off
  22. ZWrite Off
  23. ZTest Greater
  24. Stencil
  25. {
  26. Ref 2
  27. Comp notequal
  28. Pass replace
  29. Fail keep
  30. }
  31. CGPROGRAM
  32. #pragma target 5.0
  33. #if UNITY_VERSION >= 560
  34. #pragma only_renderers d3d11 vulkan glcore
  35. #else
  36. #pragma only_renderers d3d11 glcore
  37. #endif
  38. #pragma exclude_renderers gles
  39. #pragma multi_compile_instancing
  40. #pragma vertex MainVS
  41. #pragma fragment MainPS
  42. // Includes -------------------------------------------------------------------------------------------------------------------------------------------------
  43. #include "UnityCG.cginc"
  44. // Structs --------------------------------------------------------------------------------------------------------------------------------------------------
  45. struct VertexInput
  46. {
  47. float4 vertex : POSITION;
  48. float2 uv : TEXCOORD0;
  49. #if UNITY_VERSION >= 560
  50. UNITY_VERTEX_INPUT_INSTANCE_ID
  51. #endif
  52. };
  53. struct VertexOutput
  54. {
  55. float2 uv : TEXCOORD0;
  56. float4 vertex : SV_POSITION;
  57. #if UNITY_VERSION >= 560
  58. UNITY_VERTEX_OUTPUT_STEREO
  59. #endif
  60. };
  61. #if UNITY_VERSION >= 201810
  62. // Globals --------------------------------------------------------------------------------------------------------------------------------------------------
  63. UNITY_INSTANCING_BUFFER_START( Props )
  64. UNITY_DEFINE_INSTANCED_PROP( float4, _Color )
  65. UNITY_DEFINE_INSTANCED_PROP( sampler2D, _MainTex )
  66. UNITY_DEFINE_INSTANCED_PROP( float4, _MainTex_ST )
  67. UNITY_INSTANCING_BUFFER_END( Props )
  68. // MainVs ---------------------------------------------------------------------------------------------------------------------------------------------------
  69. VertexOutput MainVS( VertexInput i )
  70. {
  71. VertexOutput o;
  72. UNITY_SETUP_INSTANCE_ID( i );
  73. UNITY_INITIALIZE_OUTPUT( VertexOutput, o );
  74. UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO( o );
  75. o.vertex = UnityObjectToClipPos(i.vertex);
  76. o.uv = TRANSFORM_TEX( i.uv, UNITY_ACCESS_INSTANCED_PROP( Props, _MainTex ) );
  77. return o;
  78. }
  79. // MainPs ---------------------------------------------------------------------------------------------------------------------------------------------------
  80. float4 MainPS( VertexOutput i ) : SV_Target
  81. {
  82. UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO( i );
  83. float4 vColor = UNITY_ACCESS_INSTANCED_PROP( Props, _Color.rgba );
  84. return vColor.rgba;
  85. }
  86. #else
  87. // Globals --------------------------------------------------------------------------------------------------------------------------------------------------
  88. sampler2D _MainTex;
  89. float4 _MainTex_ST;
  90. float4 _Color;
  91. // MainVs ---------------------------------------------------------------------------------------------------------------------------------------------------
  92. VertexOutput MainVS( VertexInput i )
  93. {
  94. VertexOutput o;
  95. #if UNITY_VERSION >= 540
  96. o.vertex = UnityObjectToClipPos(i.vertex);
  97. #else
  98. o.vertex = mul(UNITY_MATRIX_MVP, i.vertex);
  99. #endif
  100. o.uv = TRANSFORM_TEX( i.uv, _MainTex );
  101. return o;
  102. }
  103. // MainPs ---------------------------------------------------------------------------------------------------------------------------------------------------
  104. float4 MainPS( VertexOutput i ) : SV_Target
  105. {
  106. float4 vColor = _Color.rgba;
  107. return vColor.rgba;
  108. }
  109. #endif
  110. ENDCG
  111. }
  112. }
  113. }