| 1 | Shader "Oculus/Texture2D Blit" { |
| 2 | Properties{ |
| 3 | _MainTex("Base (RGB) Trans (A)", 2D) = "white" {} |
| 4 | _linearToSrgb("Perform linear-to-gamma conversion", Int) = 0 |
| 5 | _premultiply("Pre-multiply alpha", Int) = 0 |
| 6 | } |
| 7 | SubShader{ |
| 8 | Tags{ "Queue" = "Transparent" "IgnoreProjector" = "True" "RenderType" = "Transparent" } |
| 9 | |
| 10 | Pass{ |
| 11 | ZWrite Off |
| 12 | ColorMask RGBA |
| 13 | |
| 14 | CGPROGRAM |
| 15 | #pragma vertex vert |
| 16 | #pragma fragment frag |
| 17 | |
| 18 | #include "UnityCG.cginc" |
| 19 | |
| 20 | struct appdata_t |
| 21 | { |
| 22 | float4 vertex : POSITION; |
| 23 | float2 texcoord : TEXCOORD0; |
| 24 | }; |
| 25 | |
| 26 | struct v2f |
| 27 | { |
| 28 | float4 vertex : SV_POSITION; |
| 29 | half2 texcoord : TEXCOORD0; |
| 30 | }; |
| 31 | |
| 32 | sampler2D _MainTex; |
| 33 | float4 _MainTex_ST; |
| 34 | int _linearToSrgb; |
| 35 | int _premultiply; |
| 36 | |
| 37 | v2f vert (appdata_t v) |
| 38 | { |
| 39 | v2f o; |
| 40 | o.vertex = UnityObjectToClipPos(v.vertex); |
| 41 | o.texcoord = TRANSFORM_TEX(v.texcoord, _MainTex); |
| 42 | return o; |
| 43 | } |
| 44 | |
| 45 | fixed4 frag (v2f i) : COLOR |
| 46 | { |
| 47 | fixed4 col = tex2D(_MainTex, i.texcoord); |
| 48 | if (_linearToSrgb) |
| 49 | { |
| 50 | float3 S1 = sqrt(col.rgb); |
| 51 | float3 S2 = sqrt(S1); |
| 52 | float3 S3 = sqrt(S2); |
| 53 | col.rgb = 0.662002687 * S1 + 0.684122060 * S2 - 0.323583601 * S3 - 0.0225411470 * col.rgb; |
| 54 | } |
| 55 | |
| 56 | if (_premultiply) |
| 57 | col.rgb *= col.a; |
| 58 | |
| 59 | return col; |
| 60 | } |
| 61 | ENDCG |
| 62 | } |
| 63 | } |
| 64 | } |