Assignment for RMIT Mixed Reality in 2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

129 lines
4.0 KiB

  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. #pragma only_renderers d3d11 vulkan
  21. #pragma exclude_renderers gles
  22. // Includes -------------------------------------------------------------------------------------------------------------------------------------------------
  23. #include "UnityCG.cginc"
  24. // Structs --------------------------------------------------------------------------------------------------------------------------------------------------
  25. struct VertexInput
  26. {
  27. float4 vertex : POSITION;
  28. float2 uv : TEXCOORD0;
  29. fixed4 color : COLOR;
  30. };
  31. struct VertexOutput
  32. {
  33. float2 uv : TEXCOORD0;
  34. float4 vertex : SV_POSITION;
  35. fixed4 color : COLOR;
  36. };
  37. // Globals --------------------------------------------------------------------------------------------------------------------------------------------------
  38. sampler2D _MainTex;
  39. float4 _MainTex_ST;
  40. float4 _TintColor;
  41. float _SeeThru;
  42. float _Darken;
  43. // MainVs ---------------------------------------------------------------------------------------------------------------------------------------------------
  44. VertexOutput MainVS( VertexInput i )
  45. {
  46. VertexOutput o;
  47. #if UNITY_VERSION >= 540
  48. o.vertex = UnityObjectToClipPos(i.vertex);
  49. #else
  50. o.vertex = mul(UNITY_MATRIX_MVP, i.vertex);
  51. #endif
  52. o.uv = TRANSFORM_TEX( i.uv, _MainTex );
  53. o.color = i.color;
  54. return o;
  55. }
  56. // MainPs ---------------------------------------------------------------------------------------------------------------------------------------------------
  57. float4 MainPS( VertexOutput i ) : SV_Target
  58. {
  59. float4 vTexel = tex2D( _MainTex, i.uv ).rgba;
  60. float4 vColor = vTexel.rgba * _TintColor.rgba * i.color.rgba;
  61. vColor.rgba = saturate( 2.0 * vColor.rgba );
  62. float flAlpha = vColor.a;
  63. vColor.rgb *= vColor.a;
  64. vColor.a = lerp( 0.0, _Darken, flAlpha );
  65. return vColor.rgba;
  66. }
  67. // MainPs ---------------------------------------------------------------------------------------------------------------------------------------------------
  68. float4 SeeThruPS( VertexOutput i ) : SV_Target
  69. {
  70. float4 vTexel = tex2D( _MainTex, i.uv ).rgba;
  71. float4 vColor = vTexel.rgba * _TintColor.rgba * i.color.rgba * _SeeThru;
  72. vColor.rgba = saturate( 2.0 * vColor.rgba );
  73. float flAlpha = vColor.a;
  74. vColor.rgb *= vColor.a;
  75. vColor.a = lerp( 0.0, _Darken, flAlpha * _SeeThru );
  76. return vColor.rgba;
  77. }
  78. ENDCG
  79. SubShader
  80. {
  81. Tags{ "Queue" = "Transparent" "RenderType" = "Transparent" }
  82. LOD 100
  83. // Behind Geometry ---------------------------------------------------------------------------------------------------------------------------------------------------
  84. Pass
  85. {
  86. // Render State ---------------------------------------------------------------------------------------------------------------------------------------------
  87. Blend One OneMinusSrcAlpha
  88. Cull Off
  89. ZWrite Off
  90. ZTest Greater
  91. CGPROGRAM
  92. #pragma vertex MainVS
  93. #pragma fragment SeeThruPS
  94. ENDCG
  95. }
  96. Pass
  97. {
  98. // Render State ---------------------------------------------------------------------------------------------------------------------------------------------
  99. Blend One OneMinusSrcAlpha
  100. Cull Off
  101. ZWrite Off
  102. ZTest LEqual
  103. CGPROGRAM
  104. #pragma vertex MainVS
  105. #pragma fragment MainPS
  106. ENDCG
  107. }
  108. }
  109. }