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.

74 lines
2.2 KiB

  1. Shader "VRTK/VRTK_TunnelEffect"
  2. {
  3. Properties
  4. {
  5. _Color("Color Tint", Color) = (0,0,0,1)
  6. _MainTex ("Texture", 2D) = "white" {}
  7. _AngularVelocity ("Angular Velocity", Float) = 0
  8. _FeatherSize ("Feather Size", Float) = 0.1
  9. _SecondarySkyBox("Cage SkyBox", Cube) = "" {}
  10. }
  11. SubShader
  12. {
  13. // No culling or depth
  14. Cull Off ZWrite Off ZTest Always
  15. Pass
  16. {
  17. CGPROGRAM
  18. #pragma vertex vert
  19. #pragma fragment frag
  20. #include "UnityCG.cginc"
  21. struct appdata
  22. {
  23. float4 vertex : POSITION;
  24. float2 uv : TEXCOORD0;
  25. };
  26. struct v2f
  27. {
  28. float2 uv : TEXCOORD0;
  29. float4 vertex : SV_POSITION;
  30. };
  31. v2f vert (appdata v)
  32. {
  33. v2f o;
  34. o.vertex = UnityObjectToClipPos(v.vertex);
  35. o.uv = v.uv;
  36. return o;
  37. }
  38. sampler2D _MainTex;
  39. float4 _MainTex_ST;
  40. float _AngularVelocity;
  41. float _FeatherSize;
  42. half4 _Color;
  43. samplerCUBE _SecondarySkyBox;
  44. float4x4 _EyeProjection[2];
  45. float4x4 _EyeToWorld[2];
  46. fixed4 frag (v2f i) : SV_Target
  47. {
  48. float2 uv = UnityStereoScreenSpaceUVAdjust(i.uv, _MainTex_ST);
  49. fixed4 col = tex2D(_MainTex, uv);
  50. float2 coords = (i.uv - 0.5) * 2;
  51. float4 viewPos = mul(_EyeProjection[unity_StereoEyeIndex], float4(coords, 0, 1));
  52. viewPos.xyz /= viewPos.w;
  53. float radius = length(viewPos.xy / (_ScreenParams.xy / 2)) / 2;
  54. float avMin = (1 - _AngularVelocity) - _FeatherSize;
  55. float avMax = (1 - _AngularVelocity) + _FeatherSize;
  56. float t = saturate((radius - avMin) / (avMax - avMin));
  57. float3 rayDir = mul(_EyeToWorld[unity_StereoEyeIndex], viewPos).xyz;
  58. half4 skyData = texCUBE(_SecondarySkyBox, normalize(rayDir));
  59. return lerp(col, skyData * _Color, t);
  60. }
  61. ENDCG
  62. }
  63. }
  64. }