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.

75 lines
2.0 KiB

  1. Shader "Oculus/Cubemap Blit" {
  2. Properties{
  3. _MainTex("Base (RGB) Trans (A)", CUBE) = "white" {}
  4. _face("Face", Int) = 0
  5. _linearToSrgb("Perform linear-to-gamma conversion", Int) = 0
  6. _premultiply("Cubemap Blit", Int) = 0
  7. }
  8. SubShader{
  9. Tags{ "Queue" = "Transparent" "IgnoreProjector" = "True" "RenderType" = "Transparent" }
  10. Pass{
  11. ZWrite Off
  12. ColorMask RGBA
  13. CGPROGRAM
  14. #pragma vertex vert
  15. #pragma fragment frag
  16. #include "UnityCG.cginc"
  17. struct appdata_t
  18. {
  19. float4 vertex : POSITION;
  20. float2 texcoord : TEXCOORD0;
  21. };
  22. struct v2f
  23. {
  24. float4 vertex : SV_POSITION;
  25. half3 cubedir : TEXCOORD0;
  26. };
  27. samplerCUBE _MainTex;
  28. float4 _MainTex_ST;
  29. int _face;
  30. int _linearToSrgb;
  31. int _premultiply;
  32. v2f vert (appdata_t va)
  33. {
  34. v2f vo;
  35. vo.vertex = UnityObjectToClipPos(va.vertex);
  36. //Face bases, assuming +x, -x, +z, -z, +y, -y with origin at bottom-left.
  37. float3 o[6] = { {1.0, -1.0, 1.0}, {-1.0, -1.0, -1.0}, {-1.0, 1.0, 1.0}, {-1.0, -1.0, -1.0}, {-1.0, -1.0, 1.0}, { 1.0, -1.0, -1.0} };
  38. float3 u[6] = { {0.0, 0.0, -1.0}, { 0.0, 0.0, 1.0}, { 1.0, 0.0, 0.0}, { 1.0, 0.0, 0.0}, { 1.0, 0.0, 0.0}, {-1.0, 0.0, 0.0} };
  39. float3 v[6] = { {0.0, 1.0, 0.0}, { 0.0, 1.0, 0.0}, { 0.0, 0.0, -1.0}, { 0.0, 0.0, 1.0}, { 0.0, 1.0, 0.0}, { 0.0, 1.0, 0.0} };
  40. //Map the input UV to the corresponding face basis.
  41. vo.cubedir = o[_face] + 2.0*va.texcoord.x * u[_face] + 2.0*(1.0 - va.texcoord.y) * v[_face];
  42. return vo;
  43. }
  44. fixed4 frag (v2f vi) : COLOR
  45. {
  46. fixed4 col = texCUBE(_MainTex, vi.cubedir);
  47. if (_linearToSrgb)
  48. {
  49. float3 S1 = sqrt(col.rgb);
  50. float3 S2 = sqrt(S1);
  51. float3 S3 = sqrt(S2);
  52. col.rgb = 0.662002687 * S1 + 0.684122060 * S2 - 0.323583601 * S3 - 0.0225411470 * col.rgb;
  53. }
  54. if (_premultiply)
  55. col.rgb *= col.a;
  56. return col;
  57. }
  58. ENDCG
  59. }
  60. }
  61. }