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.

141 lines
4.2 KiB

  1. // Unity built-in shader source. Copyright (c) 2016 Unity Technologies. MIT license (see license.txt)
  2. Shader "Skybox/6 Sided - Arbitrary Rotation" {
  3. Properties{
  4. _Tint("Tint Color", Color) = (.5, .5, .5, .5)
  5. [Gamma] _Exposure("Exposure", Range(0, 8)) = 1.0
  6. _Rotation("Rotation", Range(0, 360)) = 0
  7. _RotationAxis("Rotation axis", Vector) = (0, 1, 0)
  8. [NoScaleOffset] _FrontTex("Front [+Z] (HDR)", 2D) = "grey" {}
  9. [NoScaleOffset] _BackTex("Back [-Z] (HDR)", 2D) = "grey" {}
  10. [NoScaleOffset] _LeftTex("Left [+X] (HDR)", 2D) = "grey" {}
  11. [NoScaleOffset] _RightTex("Right [-X] (HDR)", 2D) = "grey" {}
  12. [NoScaleOffset] _UpTex("Up [+Y] (HDR)", 2D) = "grey" {}
  13. [NoScaleOffset] _DownTex("Down [-Y] (HDR)", 2D) = "grey" {}
  14. }
  15. SubShader{
  16. Tags { "Queue" = "Background" "RenderType" = "Background" "PreviewType" = "Skybox" }
  17. Cull Off ZWrite Off
  18. CGINCLUDE
  19. #include "UnityCG.cginc"
  20. half4 _Tint;
  21. half _Exposure;
  22. float _Rotation;
  23. float3 _RotationAxis;
  24. float3 RotateAroundYInDegrees(float3 vertex, float degrees)
  25. {
  26. float alpha = degrees * UNITY_PI / 180.0;
  27. float sina, cosa;
  28. sincos(alpha, sina, cosa);
  29. float2x2 m = float2x2(cosa, -sina, sina, cosa);
  30. return float3(mul(m, vertex.xz), vertex.y).xzy;
  31. }
  32. float4x4 rotationMatrix(float3 axis, float angle)
  33. {
  34. axis = normalize(axis);
  35. float s = sin(angle);
  36. float c = cos(angle);
  37. float oc = 1.0 - c;
  38. return float4x4(oc * axis.x * axis.x + c, oc * axis.x * axis.y - axis.z * s, oc * axis.z * axis.x + axis.y * s, 0.0,
  39. oc * axis.x * axis.y + axis.z * s, oc * axis.y * axis.y + c, oc * axis.y * axis.z - axis.x * s, 0.0,
  40. oc * axis.z * axis.x - axis.y * s, oc * axis.y * axis.z + axis.x * s, oc * axis.z * axis.z + c, 0.0,
  41. 0.0, 0.0, 0.0, 1.0);
  42. }
  43. struct appdata_t {
  44. float4 vertex : POSITION;
  45. float2 texcoord : TEXCOORD0;
  46. UNITY_VERTEX_INPUT_INSTANCE_ID
  47. };
  48. struct v2f {
  49. float4 vertex : SV_POSITION;
  50. float2 texcoord : TEXCOORD0;
  51. UNITY_VERTEX_OUTPUT_STEREO
  52. };
  53. v2f vert(appdata_t v)
  54. {
  55. v2f o;
  56. UNITY_SETUP_INSTANCE_ID(v);
  57. UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
  58. //float3 rotated = RotateAroundYInDegrees(v.vertex, _Rotation);
  59. float3 rotated = mul(rotationMatrix(normalize(_RotationAxis.xyz), _Rotation * UNITY_PI / 180.0), v.vertex).xyz;
  60. o.vertex = UnityObjectToClipPos(rotated);
  61. o.texcoord = v.texcoord;
  62. return o;
  63. }
  64. half4 skybox_frag(v2f i, sampler2D smp, half4 smpDecode)
  65. {
  66. half4 tex = tex2D(smp, i.texcoord);
  67. half3 c = DecodeHDR(tex, smpDecode);
  68. c = c * _Tint.rgb * unity_ColorSpaceDouble.rgb;
  69. c *= _Exposure;
  70. return half4(c, 1);
  71. }
  72. ENDCG
  73. Pass {
  74. CGPROGRAM
  75. #pragma vertex vert
  76. #pragma fragment frag
  77. #pragma target 2.0
  78. sampler2D _FrontTex;
  79. half4 _FrontTex_HDR;
  80. half4 frag(v2f i) : SV_Target { return skybox_frag(i,_FrontTex, _FrontTex_HDR); }
  81. ENDCG
  82. }
  83. Pass{
  84. CGPROGRAM
  85. #pragma vertex vert
  86. #pragma fragment frag
  87. #pragma target 2.0
  88. sampler2D _BackTex;
  89. half4 _BackTex_HDR;
  90. half4 frag(v2f i) : SV_Target { return skybox_frag(i,_BackTex, _BackTex_HDR); }
  91. ENDCG
  92. }
  93. Pass{
  94. CGPROGRAM
  95. #pragma vertex vert
  96. #pragma fragment frag
  97. #pragma target 2.0
  98. sampler2D _LeftTex;
  99. half4 _LeftTex_HDR;
  100. half4 frag(v2f i) : SV_Target { return skybox_frag(i,_LeftTex, _LeftTex_HDR); }
  101. ENDCG
  102. }
  103. Pass{
  104. CGPROGRAM
  105. #pragma vertex vert
  106. #pragma fragment frag
  107. #pragma target 2.0
  108. sampler2D _RightTex;
  109. half4 _RightTex_HDR;
  110. half4 frag(v2f i) : SV_Target { return skybox_frag(i,_RightTex, _RightTex_HDR); }
  111. ENDCG
  112. }
  113. Pass{
  114. CGPROGRAM
  115. #pragma vertex vert
  116. #pragma fragment frag
  117. #pragma target 2.0
  118. sampler2D _UpTex;
  119. half4 _UpTex_HDR;
  120. half4 frag(v2f i) : SV_Target { return skybox_frag(i,_UpTex, _UpTex_HDR); }
  121. ENDCG
  122. }
  123. Pass{
  124. CGPROGRAM
  125. #pragma vertex vert
  126. #pragma fragment frag
  127. #pragma target 2.0
  128. sampler2D _DownTex;
  129. half4 _DownTex_HDR;
  130. half4 frag(v2f i) : SV_Target { return skybox_frag(i,_DownTex, _DownTex_HDR); }
  131. ENDCG
  132. }
  133. }
  134. }