michael@0: float4x4 mLayerTransform; michael@0: float4 vRenderTargetOffset; michael@0: float4x4 mProjection; michael@0: michael@0: typedef float4 rect; michael@0: rect vTextureCoords; michael@0: rect vLayerQuad; michael@0: rect vMaskQuad; michael@0: michael@0: texture tex0; michael@0: sampler s2D; michael@0: sampler s2DWhite; michael@0: sampler s2DY; michael@0: sampler s2DCb; michael@0: sampler s2DCr; michael@0: sampler s2DMask; michael@0: michael@0: michael@0: float fLayerOpacity; michael@0: float4 fLayerColor; michael@0: michael@0: struct VS_INPUT { michael@0: float4 vPosition : POSITION; michael@0: }; michael@0: michael@0: struct VS_OUTPUT { michael@0: float4 vPosition : POSITION; michael@0: float2 vTexCoords : TEXCOORD0; michael@0: }; michael@0: michael@0: struct VS_OUTPUT_MASK { michael@0: float4 vPosition : POSITION; michael@0: float2 vTexCoords : TEXCOORD0; michael@0: float2 vMaskCoords : TEXCOORD1; michael@0: }; michael@0: michael@0: struct VS_OUTPUT_MASK_3D { michael@0: float4 vPosition : POSITION; michael@0: float2 vTexCoords : TEXCOORD0; michael@0: float3 vMaskCoords : TEXCOORD1; michael@0: }; michael@0: michael@0: VS_OUTPUT LayerQuadVS(const VS_INPUT aVertex) michael@0: { michael@0: VS_OUTPUT outp; michael@0: outp.vPosition = aVertex.vPosition; michael@0: michael@0: // We use 4 component floats to uniquely describe a rectangle, by the structure michael@0: // of x, y, width, height. This allows us to easily generate the 4 corners michael@0: // of any rectangle from the 4 corners of the 0,0-1,1 quad that we use as the michael@0: // stream source for our LayerQuad vertex shader. We do this by doing: michael@0: // Xout = x + Xin * width michael@0: // Yout = y + Yin * height michael@0: float2 position = vLayerQuad.xy; michael@0: float2 size = vLayerQuad.zw; michael@0: outp.vPosition.x = position.x + outp.vPosition.x * size.x; michael@0: outp.vPosition.y = position.y + outp.vPosition.y * size.y; michael@0: michael@0: outp.vPosition = mul(mLayerTransform, outp.vPosition); michael@0: outp.vPosition.xyz /= outp.vPosition.w; michael@0: outp.vPosition = outp.vPosition - vRenderTargetOffset; michael@0: outp.vPosition.xyz *= outp.vPosition.w; michael@0: michael@0: // adjust our vertices to match d3d9's pixel coordinate system michael@0: // which has pixel centers at integer locations michael@0: outp.vPosition.xy -= 0.5; michael@0: michael@0: outp.vPosition = mul(mProjection, outp.vPosition); michael@0: michael@0: position = vTextureCoords.xy; michael@0: size = vTextureCoords.zw; michael@0: outp.vTexCoords.x = position.x + aVertex.vPosition.x * size.x; michael@0: outp.vTexCoords.y = position.y + aVertex.vPosition.y * size.y; michael@0: michael@0: return outp; michael@0: } michael@0: michael@0: VS_OUTPUT_MASK LayerQuadVSMask(const VS_INPUT aVertex) michael@0: { michael@0: VS_OUTPUT_MASK outp; michael@0: float4 position = float4(0, 0, 0, 1); michael@0: michael@0: // We use 4 component floats to uniquely describe a rectangle, by the structure michael@0: // of x, y, width, height. This allows us to easily generate the 4 corners michael@0: // of any rectangle from the 4 corners of the 0,0-1,1 quad that we use as the michael@0: // stream source for our LayerQuad vertex shader. We do this by doing: michael@0: // Xout = x + Xin * width michael@0: // Yout = y + Yin * height michael@0: float2 size = vLayerQuad.zw; michael@0: position.x = vLayerQuad.x + aVertex.vPosition.x * size.x; michael@0: position.y = vLayerQuad.y + aVertex.vPosition.y * size.y; michael@0: michael@0: position = mul(mLayerTransform, position); michael@0: outp.vPosition.w = position.w; michael@0: outp.vPosition.xyz = position.xyz / position.w; michael@0: outp.vPosition = outp.vPosition - vRenderTargetOffset; michael@0: outp.vPosition.xyz *= outp.vPosition.w; michael@0: michael@0: // adjust our vertices to match d3d9's pixel coordinate system michael@0: // which has pixel centers at integer locations michael@0: outp.vPosition.xy -= 0.5; michael@0: michael@0: outp.vPosition = mul(mProjection, outp.vPosition); michael@0: michael@0: // calculate the position on the mask texture michael@0: outp.vMaskCoords.x = (position.x - vMaskQuad.x) / vMaskQuad.z; michael@0: outp.vMaskCoords.y = (position.y - vMaskQuad.y) / vMaskQuad.w; michael@0: michael@0: size = vTextureCoords.zw; michael@0: outp.vTexCoords.x = vTextureCoords.x + aVertex.vPosition.x * size.x; michael@0: outp.vTexCoords.y = vTextureCoords.y + aVertex.vPosition.y * size.y; michael@0: michael@0: return outp; michael@0: } michael@0: michael@0: VS_OUTPUT_MASK_3D LayerQuadVSMask3D(const VS_INPUT aVertex) michael@0: { michael@0: VS_OUTPUT_MASK_3D outp; michael@0: float4 position = float4(0, 0, 0, 1); michael@0: michael@0: // We use 4 component floats to uniquely describe a rectangle, by the structure michael@0: // of x, y, width, height. This allows us to easily generate the 4 corners michael@0: // of any rectangle from the 4 corners of the 0,0-1,1 quad that we use as the michael@0: // stream source for our LayerQuad vertex shader. We do this by doing: michael@0: // Xout = x + Xin * width michael@0: // Yout = y + Yin * height michael@0: float2 size = vLayerQuad.zw; michael@0: position.x = vLayerQuad.x + aVertex.vPosition.x * size.x; michael@0: position.y = vLayerQuad.y + aVertex.vPosition.y * size.y; michael@0: michael@0: position = mul(mLayerTransform, position); michael@0: outp.vPosition.w = position.w; michael@0: outp.vPosition.xyz = position.xyz / position.w; michael@0: outp.vPosition = outp.vPosition - vRenderTargetOffset; michael@0: outp.vPosition.xyz *= outp.vPosition.w; michael@0: michael@0: // adjust our vertices to match d3d9's pixel coordinate system michael@0: // which has pixel centers at integer locations michael@0: outp.vPosition.xy -= 0.5; michael@0: michael@0: outp.vPosition = mul(mProjection, outp.vPosition); michael@0: michael@0: // calculate the position on the mask texture michael@0: position.xyz /= position.w; michael@0: outp.vMaskCoords.x = (position.x - vMaskQuad.x) / vMaskQuad.z; michael@0: outp.vMaskCoords.y = (position.y - vMaskQuad.y) / vMaskQuad.w; michael@0: // correct for perspective correct interpolation, see comment in D3D10 shader michael@0: outp.vMaskCoords.z = 1; michael@0: outp.vMaskCoords *= position.w; michael@0: michael@0: size = vTextureCoords.zw; michael@0: outp.vTexCoords.x = vTextureCoords.x + aVertex.vPosition.x * size.x; michael@0: outp.vTexCoords.y = vTextureCoords.y + aVertex.vPosition.y * size.y; michael@0: michael@0: return outp; michael@0: } michael@0: michael@0: float4 ComponentPass1Shader(const VS_OUTPUT aVertex) : COLOR michael@0: { michael@0: float4 src = tex2D(s2D, aVertex.vTexCoords); michael@0: float4 alphas = 1.0 - tex2D(s2DWhite, aVertex.vTexCoords) + src; michael@0: alphas.a = alphas.g; michael@0: return alphas * fLayerOpacity; michael@0: } michael@0: michael@0: float4 ComponentPass2Shader(const VS_OUTPUT aVertex) : COLOR michael@0: { michael@0: float4 src = tex2D(s2D, aVertex.vTexCoords); michael@0: float4 alphas = 1.0 - tex2D(s2DWhite, aVertex.vTexCoords) + src; michael@0: src.a = alphas.g; michael@0: return src * fLayerOpacity; michael@0: } michael@0: michael@0: float4 RGBAShader(const VS_OUTPUT aVertex) : COLOR michael@0: { michael@0: return tex2D(s2D, aVertex.vTexCoords) * fLayerOpacity; michael@0: } michael@0: michael@0: float4 RGBShader(const VS_OUTPUT aVertex) : COLOR michael@0: { michael@0: float4 result; michael@0: result = tex2D(s2D, aVertex.vTexCoords); michael@0: result.a = 1.0; michael@0: return result * fLayerOpacity; michael@0: } michael@0: michael@0: float4 YCbCrShader(const VS_OUTPUT aVertex) : COLOR michael@0: { michael@0: float4 yuv; michael@0: float4 color; michael@0: michael@0: yuv.r = tex2D(s2DCr, aVertex.vTexCoords).a - 0.5; michael@0: yuv.g = tex2D(s2DY, aVertex.vTexCoords).a - 0.0625; michael@0: yuv.b = tex2D(s2DCb, aVertex.vTexCoords).a - 0.5; michael@0: michael@0: color.r = yuv.g * 1.164 + yuv.r * 1.596; michael@0: color.g = yuv.g * 1.164 - 0.813 * yuv.r - 0.391 * yuv.b; michael@0: color.b = yuv.g * 1.164 + yuv.b * 2.018; michael@0: color.a = 1.0f; michael@0: michael@0: return color * fLayerOpacity; michael@0: } michael@0: michael@0: float4 SolidColorShader(const VS_OUTPUT aVertex) : COLOR michael@0: { michael@0: return fLayerColor; michael@0: } michael@0: michael@0: float4 ComponentPass1ShaderMask(const VS_OUTPUT_MASK aVertex) : COLOR michael@0: { michael@0: float4 src = tex2D(s2D, aVertex.vTexCoords); michael@0: float4 alphas = 1.0 - tex2D(s2DWhite, aVertex.vTexCoords) + src; michael@0: alphas.a = alphas.g; michael@0: float2 maskCoords = aVertex.vMaskCoords; michael@0: float mask = tex2D(s2DMask, maskCoords).a; michael@0: return alphas * fLayerOpacity * mask; michael@0: } michael@0: michael@0: float4 ComponentPass2ShaderMask(const VS_OUTPUT_MASK aVertex) : COLOR michael@0: { michael@0: float4 src = tex2D(s2D, aVertex.vTexCoords); michael@0: float4 alphas = 1.0 - tex2D(s2DWhite, aVertex.vTexCoords) + src; michael@0: src.a = alphas.g; michael@0: float2 maskCoords = aVertex.vMaskCoords; michael@0: float mask = tex2D(s2DMask, maskCoords).a; michael@0: return src * fLayerOpacity * mask; michael@0: } michael@0: michael@0: float4 RGBAShaderMask(const VS_OUTPUT_MASK aVertex) : COLOR michael@0: { michael@0: float2 maskCoords = aVertex.vMaskCoords; michael@0: float mask = tex2D(s2DMask, maskCoords).a; michael@0: return tex2D(s2D, aVertex.vTexCoords) * fLayerOpacity * mask; michael@0: } michael@0: michael@0: float4 RGBAShaderMask3D(const VS_OUTPUT_MASK_3D aVertex) : COLOR michael@0: { michael@0: float2 maskCoords = aVertex.vMaskCoords.xy / aVertex.vMaskCoords.z; michael@0: float mask = tex2D(s2DMask, maskCoords).a; michael@0: return tex2D(s2D, aVertex.vTexCoords) * fLayerOpacity * mask; michael@0: } michael@0: michael@0: float4 RGBShaderMask(const VS_OUTPUT_MASK aVertex) : COLOR michael@0: { michael@0: float4 result; michael@0: result = tex2D(s2D, aVertex.vTexCoords); michael@0: result.a = 1.0; michael@0: float2 maskCoords = aVertex.vMaskCoords; michael@0: float mask = tex2D(s2DMask, maskCoords).a; michael@0: return result * fLayerOpacity * mask; michael@0: } michael@0: michael@0: float4 YCbCrShaderMask(const VS_OUTPUT_MASK aVertex) : COLOR michael@0: { michael@0: float4 yuv; michael@0: float4 color; michael@0: michael@0: yuv.r = tex2D(s2DCr, aVertex.vTexCoords).a - 0.5; michael@0: yuv.g = tex2D(s2DY, aVertex.vTexCoords).a - 0.0625; michael@0: yuv.b = tex2D(s2DCb, aVertex.vTexCoords).a - 0.5; michael@0: michael@0: color.r = yuv.g * 1.164 + yuv.r * 1.596; michael@0: color.g = yuv.g * 1.164 - 0.813 * yuv.r - 0.391 * yuv.b; michael@0: color.b = yuv.g * 1.164 + yuv.b * 2.018; michael@0: color.a = 1.0f; michael@0: michael@0: float2 maskCoords = aVertex.vMaskCoords; michael@0: float mask = tex2D(s2DMask, maskCoords).a; michael@0: return color * fLayerOpacity * mask; michael@0: } michael@0: michael@0: float4 SolidColorShaderMask(const VS_OUTPUT_MASK aVertex) : COLOR michael@0: { michael@0: float2 maskCoords = aVertex.vMaskCoords; michael@0: float mask = tex2D(s2DMask, maskCoords).a; michael@0: return fLayerColor * mask; michael@0: }