| 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 | |
| 11 | Pass{ |
| 12 | ZWrite Off |
| 13 | ColorMask RGBA |
| 14 | |
| 15 | CGPROGRAM |
| 16 | #pragma vertex vert |
| 17 | #pragma fragment frag |
| 18 | |
| 19 | #include "UnityCG.cginc" |
| 20 | |
| 21 | struct appdata_t |
| 22 | { |
| 23 | float4 vertex : POSITION; |
| 24 | float2 texcoord : TEXCOORD0; |
| 25 | }; |
| 26 | |
| 27 | struct v2f |
| 28 | { |
| 29 | float4 vertex : SV_POSITION; |
| 30 | half3 cubedir : TEXCOORD0; |
| 31 | }; |
| 32 | |
| 33 | samplerCUBE _MainTex; |
| 34 | float4 _MainTex_ST; |
| 35 | int _face; |
| 36 | int _linearToSrgb; |
| 37 | int _premultiply; |
| 38 | |
| 39 | v2f vert (appdata_t va) |
| 40 | { |
| 41 | v2f vo; |
| 42 | vo.vertex = UnityObjectToClipPos(va.vertex); |
| 43 | |
| 44 | //Face bases, assuming +x, -x, +z, -z, +y, -y with origin at bottom-left. |
| 45 | 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} }; |
| 46 | 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} }; |
| 47 | 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} }; |
| 48 | |
| 49 | //Map the input UV to the corresponding face basis. |
| 50 | vo.cubedir = o[_face] + 2.0*va.texcoord.x * u[_face] + 2.0*(1.0 - va.texcoord.y) * v[_face]; |
| 51 | |
| 52 | return vo; |
| 53 | } |
| 54 | |
| 55 | fixed4 frag (v2f vi) : COLOR |
| 56 | { |
| 57 | fixed4 col = texCUBE(_MainTex, vi.cubedir); |
| 58 | |
| 59 | if (_linearToSrgb) |
| 60 | { |
| 61 | float3 S1 = sqrt(col.rgb); |
| 62 | float3 S2 = sqrt(S1); |
| 63 | float3 S3 = sqrt(S2); |
| 64 | col.rgb = 0.662002687 * S1 + 0.684122060 * S2 - 0.323583601 * S3 - 0.0225411470 * col.rgb; |
| 65 | } |
| 66 | |
| 67 | if (_premultiply) |
| 68 | col.rgb *= col.a; |
| 69 | |
| 70 | return col; |
| 71 | } |
| 72 | ENDCG |
| 73 | } |
| 74 | } |
| 75 | } |