[WASAPI] fix supported sample rates enumeration for devices without 16bit formats
[xbmc.git] / system / shaders / guishader_common.hlsl
blob0dd01c54760a256e0b3fbea4783ea2786c463504
1 /*
2  *      Copyright (C) 2005-2015 Team Kodi
3  *      http://kodi.tv
4  *
5  *  This Program is free software; you can redistribute it and/or modify
6  *  it under the terms of the GNU General Public License as published by
7  *  the Free Software Foundation; either version 2, or (at your option)
8  *  any later version.
9  *
10  *  This Program is distributed in the hope that it will be useful,
11  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  *  GNU General Public License for more details.
14  *
15  *  You should have received a copy of the GNU General Public License
16  *  along with XBMC; see the file COPYING.  If not, see
17  *  <http://www.gnu.org/licenses/>.
18  *
19  */
21 struct VS_INPUT
23   float4 pos : POSITION;
24   float4 color: COLOR0;
25   float2 tex : TEXCOORD0;
26   float2 tex2 : TEXCOORD1;
29 struct PS_INPUT
31   float4 pos : SV_POSITION;
32   float4 color: COLOR0;
33   float2 tex : TEXCOORD0;
34   float2 tex2 : TEXCOORD1;
37 SamplerState LinearSampler : register(s0)
39   Filter = MIN_MAG_MIP_LINEAR;
40   AddressU = CLAMP;
41   AddressV = CLAMP;
42   Comparison = NEVER;
45 cbuffer cbWorld : register(b0)
47   float4x4 worldViewProj;
48   float blackLevel;
49   float colorRange;
50   float sdrPeakLum;
51   int PQ;
54 inline float3 transferPQ(float3 x)
56   static const float ST2084_m1 = 2610.0f / (4096.0f * 4.0f);
57   static const float ST2084_m2 = (2523.0f / 4096.0f) * 128.0f;
58   static const float ST2084_c1 = 3424.0f / 4096.0f;
59   static const float ST2084_c2 = (2413.0f / 4096.0f) * 32.0f;
60   static const float ST2084_c3 = (2392.0f / 4096.0f) * 32.0f;
61   static const float3x3 matx =
62   {
63     0.627402, 0.329292, 0.043306,
64     0.069095, 0.919544, 0.011360,
65     0.016394, 0.088028, 0.895578
66   };
67   // REC.709 to linear
68   x = pow(x, 1.0f / 0.45f);
69   // REC.709 to BT.2020
70   x = mul(matx, x);
71   // linear to PQ
72   x = pow(x / sdrPeakLum, ST2084_m1);
73   x = (ST2084_c1 + ST2084_c2 * x) / (1.0f + ST2084_c3 * x);
74   x = pow(x, ST2084_m2);
75   return x;
78 inline float4 tonemapHDR(float4 color)
80   return (PQ) ? float4(transferPQ(color.rgb), color.a) : color;
83 inline float4 adjustColorRange(float4 color)
85   return float4(blackLevel + colorRange * color.rgb, color.a);
88 #define STEREO_LEFT_EYE_INDEX  0
89 #define STEREO_RIGHT_EYE_INDEX 1
91 #ifdef STEREO_MODE_SHADER
93 inline float4 StereoInterlaced(PS_INPUT input, int eye)
95   uint pixelY = abs(trunc(input.tex.y * g_viewPortHeigh));
96   uint odd = pixelY % 2;
98   if ((odd == 0 && !eye) || (odd != 0 && eye))
99     return float4(texView.Sample(LinearSampler, input.tex).rgb, 1.0);
100   else
101     return float4(0.0, 0.0, 0.0, 0.0);
104 inline float4 StereoCheckerboard(PS_INPUT input, int eye)
106   uint pixelX = abs(trunc(input.tex.x * g_viewPortWidth));
107   uint pixelY = abs(trunc(input.tex.y * g_viewPortHeigh));
108   uint odd = (pixelX + pixelY) % 2;
110   if ((odd == 0 && !eye) || (odd != 0 && eye))
111     return float4(texView.Sample(LinearSampler, input.tex).rgb, 1.0);
112   else
113     return float4(0.0, 0.0, 0.0, 0.0);
116 #endif