1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/gfx/layers/d3d9/LayerManagerD3D9Shaders.hlsl Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,277 @@ 1.4 +float4x4 mLayerTransform; 1.5 +float4 vRenderTargetOffset; 1.6 +float4x4 mProjection; 1.7 + 1.8 +typedef float4 rect; 1.9 +rect vTextureCoords; 1.10 +rect vLayerQuad; 1.11 +rect vMaskQuad; 1.12 + 1.13 +texture tex0; 1.14 +sampler s2D; 1.15 +sampler s2DWhite; 1.16 +sampler s2DY; 1.17 +sampler s2DCb; 1.18 +sampler s2DCr; 1.19 +sampler s2DMask; 1.20 + 1.21 + 1.22 +float fLayerOpacity; 1.23 +float4 fLayerColor; 1.24 + 1.25 +struct VS_INPUT { 1.26 + float4 vPosition : POSITION; 1.27 +}; 1.28 + 1.29 +struct VS_OUTPUT { 1.30 + float4 vPosition : POSITION; 1.31 + float2 vTexCoords : TEXCOORD0; 1.32 +}; 1.33 + 1.34 +struct VS_OUTPUT_MASK { 1.35 + float4 vPosition : POSITION; 1.36 + float2 vTexCoords : TEXCOORD0; 1.37 + float2 vMaskCoords : TEXCOORD1; 1.38 +}; 1.39 + 1.40 +struct VS_OUTPUT_MASK_3D { 1.41 + float4 vPosition : POSITION; 1.42 + float2 vTexCoords : TEXCOORD0; 1.43 + float3 vMaskCoords : TEXCOORD1; 1.44 +}; 1.45 + 1.46 +VS_OUTPUT LayerQuadVS(const VS_INPUT aVertex) 1.47 +{ 1.48 + VS_OUTPUT outp; 1.49 + outp.vPosition = aVertex.vPosition; 1.50 + 1.51 + // We use 4 component floats to uniquely describe a rectangle, by the structure 1.52 + // of x, y, width, height. This allows us to easily generate the 4 corners 1.53 + // of any rectangle from the 4 corners of the 0,0-1,1 quad that we use as the 1.54 + // stream source for our LayerQuad vertex shader. We do this by doing: 1.55 + // Xout = x + Xin * width 1.56 + // Yout = y + Yin * height 1.57 + float2 position = vLayerQuad.xy; 1.58 + float2 size = vLayerQuad.zw; 1.59 + outp.vPosition.x = position.x + outp.vPosition.x * size.x; 1.60 + outp.vPosition.y = position.y + outp.vPosition.y * size.y; 1.61 + 1.62 + outp.vPosition = mul(mLayerTransform, outp.vPosition); 1.63 + outp.vPosition.xyz /= outp.vPosition.w; 1.64 + outp.vPosition = outp.vPosition - vRenderTargetOffset; 1.65 + outp.vPosition.xyz *= outp.vPosition.w; 1.66 + 1.67 + // adjust our vertices to match d3d9's pixel coordinate system 1.68 + // which has pixel centers at integer locations 1.69 + outp.vPosition.xy -= 0.5; 1.70 + 1.71 + outp.vPosition = mul(mProjection, outp.vPosition); 1.72 + 1.73 + position = vTextureCoords.xy; 1.74 + size = vTextureCoords.zw; 1.75 + outp.vTexCoords.x = position.x + aVertex.vPosition.x * size.x; 1.76 + outp.vTexCoords.y = position.y + aVertex.vPosition.y * size.y; 1.77 + 1.78 + return outp; 1.79 +} 1.80 + 1.81 +VS_OUTPUT_MASK LayerQuadVSMask(const VS_INPUT aVertex) 1.82 +{ 1.83 + VS_OUTPUT_MASK outp; 1.84 + float4 position = float4(0, 0, 0, 1); 1.85 + 1.86 + // We use 4 component floats to uniquely describe a rectangle, by the structure 1.87 + // of x, y, width, height. This allows us to easily generate the 4 corners 1.88 + // of any rectangle from the 4 corners of the 0,0-1,1 quad that we use as the 1.89 + // stream source for our LayerQuad vertex shader. We do this by doing: 1.90 + // Xout = x + Xin * width 1.91 + // Yout = y + Yin * height 1.92 + float2 size = vLayerQuad.zw; 1.93 + position.x = vLayerQuad.x + aVertex.vPosition.x * size.x; 1.94 + position.y = vLayerQuad.y + aVertex.vPosition.y * size.y; 1.95 + 1.96 + position = mul(mLayerTransform, position); 1.97 + outp.vPosition.w = position.w; 1.98 + outp.vPosition.xyz = position.xyz / position.w; 1.99 + outp.vPosition = outp.vPosition - vRenderTargetOffset; 1.100 + outp.vPosition.xyz *= outp.vPosition.w; 1.101 + 1.102 + // adjust our vertices to match d3d9's pixel coordinate system 1.103 + // which has pixel centers at integer locations 1.104 + outp.vPosition.xy -= 0.5; 1.105 + 1.106 + outp.vPosition = mul(mProjection, outp.vPosition); 1.107 + 1.108 + // calculate the position on the mask texture 1.109 + outp.vMaskCoords.x = (position.x - vMaskQuad.x) / vMaskQuad.z; 1.110 + outp.vMaskCoords.y = (position.y - vMaskQuad.y) / vMaskQuad.w; 1.111 + 1.112 + size = vTextureCoords.zw; 1.113 + outp.vTexCoords.x = vTextureCoords.x + aVertex.vPosition.x * size.x; 1.114 + outp.vTexCoords.y = vTextureCoords.y + aVertex.vPosition.y * size.y; 1.115 + 1.116 + return outp; 1.117 +} 1.118 + 1.119 +VS_OUTPUT_MASK_3D LayerQuadVSMask3D(const VS_INPUT aVertex) 1.120 +{ 1.121 + VS_OUTPUT_MASK_3D outp; 1.122 + float4 position = float4(0, 0, 0, 1); 1.123 + 1.124 + // We use 4 component floats to uniquely describe a rectangle, by the structure 1.125 + // of x, y, width, height. This allows us to easily generate the 4 corners 1.126 + // of any rectangle from the 4 corners of the 0,0-1,1 quad that we use as the 1.127 + // stream source for our LayerQuad vertex shader. We do this by doing: 1.128 + // Xout = x + Xin * width 1.129 + // Yout = y + Yin * height 1.130 + float2 size = vLayerQuad.zw; 1.131 + position.x = vLayerQuad.x + aVertex.vPosition.x * size.x; 1.132 + position.y = vLayerQuad.y + aVertex.vPosition.y * size.y; 1.133 + 1.134 + position = mul(mLayerTransform, position); 1.135 + outp.vPosition.w = position.w; 1.136 + outp.vPosition.xyz = position.xyz / position.w; 1.137 + outp.vPosition = outp.vPosition - vRenderTargetOffset; 1.138 + outp.vPosition.xyz *= outp.vPosition.w; 1.139 + 1.140 + // adjust our vertices to match d3d9's pixel coordinate system 1.141 + // which has pixel centers at integer locations 1.142 + outp.vPosition.xy -= 0.5; 1.143 + 1.144 + outp.vPosition = mul(mProjection, outp.vPosition); 1.145 + 1.146 + // calculate the position on the mask texture 1.147 + position.xyz /= position.w; 1.148 + outp.vMaskCoords.x = (position.x - vMaskQuad.x) / vMaskQuad.z; 1.149 + outp.vMaskCoords.y = (position.y - vMaskQuad.y) / vMaskQuad.w; 1.150 + // correct for perspective correct interpolation, see comment in D3D10 shader 1.151 + outp.vMaskCoords.z = 1; 1.152 + outp.vMaskCoords *= position.w; 1.153 + 1.154 + size = vTextureCoords.zw; 1.155 + outp.vTexCoords.x = vTextureCoords.x + aVertex.vPosition.x * size.x; 1.156 + outp.vTexCoords.y = vTextureCoords.y + aVertex.vPosition.y * size.y; 1.157 + 1.158 + return outp; 1.159 +} 1.160 + 1.161 +float4 ComponentPass1Shader(const VS_OUTPUT aVertex) : COLOR 1.162 +{ 1.163 + float4 src = tex2D(s2D, aVertex.vTexCoords); 1.164 + float4 alphas = 1.0 - tex2D(s2DWhite, aVertex.vTexCoords) + src; 1.165 + alphas.a = alphas.g; 1.166 + return alphas * fLayerOpacity; 1.167 +} 1.168 + 1.169 +float4 ComponentPass2Shader(const VS_OUTPUT aVertex) : COLOR 1.170 +{ 1.171 + float4 src = tex2D(s2D, aVertex.vTexCoords); 1.172 + float4 alphas = 1.0 - tex2D(s2DWhite, aVertex.vTexCoords) + src; 1.173 + src.a = alphas.g; 1.174 + return src * fLayerOpacity; 1.175 +} 1.176 + 1.177 +float4 RGBAShader(const VS_OUTPUT aVertex) : COLOR 1.178 +{ 1.179 + return tex2D(s2D, aVertex.vTexCoords) * fLayerOpacity; 1.180 +} 1.181 + 1.182 +float4 RGBShader(const VS_OUTPUT aVertex) : COLOR 1.183 +{ 1.184 + float4 result; 1.185 + result = tex2D(s2D, aVertex.vTexCoords); 1.186 + result.a = 1.0; 1.187 + return result * fLayerOpacity; 1.188 +} 1.189 + 1.190 +float4 YCbCrShader(const VS_OUTPUT aVertex) : COLOR 1.191 +{ 1.192 + float4 yuv; 1.193 + float4 color; 1.194 + 1.195 + yuv.r = tex2D(s2DCr, aVertex.vTexCoords).a - 0.5; 1.196 + yuv.g = tex2D(s2DY, aVertex.vTexCoords).a - 0.0625; 1.197 + yuv.b = tex2D(s2DCb, aVertex.vTexCoords).a - 0.5; 1.198 + 1.199 + color.r = yuv.g * 1.164 + yuv.r * 1.596; 1.200 + color.g = yuv.g * 1.164 - 0.813 * yuv.r - 0.391 * yuv.b; 1.201 + color.b = yuv.g * 1.164 + yuv.b * 2.018; 1.202 + color.a = 1.0f; 1.203 + 1.204 + return color * fLayerOpacity; 1.205 +} 1.206 + 1.207 +float4 SolidColorShader(const VS_OUTPUT aVertex) : COLOR 1.208 +{ 1.209 + return fLayerColor; 1.210 +} 1.211 + 1.212 +float4 ComponentPass1ShaderMask(const VS_OUTPUT_MASK aVertex) : COLOR 1.213 +{ 1.214 + float4 src = tex2D(s2D, aVertex.vTexCoords); 1.215 + float4 alphas = 1.0 - tex2D(s2DWhite, aVertex.vTexCoords) + src; 1.216 + alphas.a = alphas.g; 1.217 + float2 maskCoords = aVertex.vMaskCoords; 1.218 + float mask = tex2D(s2DMask, maskCoords).a; 1.219 + return alphas * fLayerOpacity * mask; 1.220 +} 1.221 + 1.222 +float4 ComponentPass2ShaderMask(const VS_OUTPUT_MASK aVertex) : COLOR 1.223 +{ 1.224 + float4 src = tex2D(s2D, aVertex.vTexCoords); 1.225 + float4 alphas = 1.0 - tex2D(s2DWhite, aVertex.vTexCoords) + src; 1.226 + src.a = alphas.g; 1.227 + float2 maskCoords = aVertex.vMaskCoords; 1.228 + float mask = tex2D(s2DMask, maskCoords).a; 1.229 + return src * fLayerOpacity * mask; 1.230 +} 1.231 + 1.232 +float4 RGBAShaderMask(const VS_OUTPUT_MASK aVertex) : COLOR 1.233 +{ 1.234 + float2 maskCoords = aVertex.vMaskCoords; 1.235 + float mask = tex2D(s2DMask, maskCoords).a; 1.236 + return tex2D(s2D, aVertex.vTexCoords) * fLayerOpacity * mask; 1.237 +} 1.238 + 1.239 +float4 RGBAShaderMask3D(const VS_OUTPUT_MASK_3D aVertex) : COLOR 1.240 +{ 1.241 + float2 maskCoords = aVertex.vMaskCoords.xy / aVertex.vMaskCoords.z; 1.242 + float mask = tex2D(s2DMask, maskCoords).a; 1.243 + return tex2D(s2D, aVertex.vTexCoords) * fLayerOpacity * mask; 1.244 +} 1.245 + 1.246 +float4 RGBShaderMask(const VS_OUTPUT_MASK aVertex) : COLOR 1.247 +{ 1.248 + float4 result; 1.249 + result = tex2D(s2D, aVertex.vTexCoords); 1.250 + result.a = 1.0; 1.251 + float2 maskCoords = aVertex.vMaskCoords; 1.252 + float mask = tex2D(s2DMask, maskCoords).a; 1.253 + return result * fLayerOpacity * mask; 1.254 +} 1.255 + 1.256 +float4 YCbCrShaderMask(const VS_OUTPUT_MASK aVertex) : COLOR 1.257 +{ 1.258 + float4 yuv; 1.259 + float4 color; 1.260 + 1.261 + yuv.r = tex2D(s2DCr, aVertex.vTexCoords).a - 0.5; 1.262 + yuv.g = tex2D(s2DY, aVertex.vTexCoords).a - 0.0625; 1.263 + yuv.b = tex2D(s2DCb, aVertex.vTexCoords).a - 0.5; 1.264 + 1.265 + color.r = yuv.g * 1.164 + yuv.r * 1.596; 1.266 + color.g = yuv.g * 1.164 - 0.813 * yuv.r - 0.391 * yuv.b; 1.267 + color.b = yuv.g * 1.164 + yuv.b * 2.018; 1.268 + color.a = 1.0f; 1.269 + 1.270 + float2 maskCoords = aVertex.vMaskCoords; 1.271 + float mask = tex2D(s2DMask, maskCoords).a; 1.272 + return color * fLayerOpacity * mask; 1.273 +} 1.274 + 1.275 +float4 SolidColorShaderMask(const VS_OUTPUT_MASK aVertex) : COLOR 1.276 +{ 1.277 + float2 maskCoords = aVertex.vMaskCoords; 1.278 + float mask = tex2D(s2DMask, maskCoords).a; 1.279 + return fLayerColor * mask; 1.280 +}