Bug 716439; shaders for the dx9 backend. r-Bas

This commit is contained in:
Nicholas Cameron 2012-03-07 10:09:19 +13:00
Родитель ebda58df7d
Коммит 64cda729f2
3 изменённых файлов: 1394 добавлений и 0 удалений

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

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

Просмотреть файл

@ -14,4 +14,22 @@ fxc LayerManagerD3D9Shaders.hlsl -EYCbCrShader -nologo -Tps_2_0 -Fh$tempfile -Vn
cat $tempfile >> LayerManagerD3D9Shaders.h
fxc LayerManagerD3D9Shaders.hlsl -ESolidColorShader -nologo -Tps_2_0 -Fh$tempfile -VnSolidColorShaderPS
cat $tempfile >> LayerManagerD3D9Shaders.h
fxc LayerManagerD3D9Shaders.hlsl -ELayerQuadVSMask -nologo -Fh$tempfile -VnLayerQuadVSMask
cat $tempfile >> LayerManagerD3D9Shaders.h
fxc LayerManagerD3D9Shaders.hlsl -ELayerQuadVSMask3D -nologo -Fh$tempfile -VnLayerQuadVSMask3D
cat $tempfile >> LayerManagerD3D9Shaders.h
fxc LayerManagerD3D9Shaders.hlsl -ERGBAShaderMask -nologo -Tps_2_0 -Fh$tempfile -VnRGBAShaderPSMask
cat $tempfile >> LayerManagerD3D9Shaders.h
fxc LayerManagerD3D9Shaders.hlsl -ERGBAShaderMask3D -nologo -Tps_2_0 -Fh$tempfile -VnRGBAShaderPSMask3D
cat $tempfile >> LayerManagerD3D9Shaders.h
fxc LayerManagerD3D9Shaders.hlsl -EComponentPass1ShaderMask -nologo -Tps_2_0 -Fh$tempfile -VnComponentPass1ShaderPSMask
cat $tempfile >> LayerManagerD3D9Shaders.h
fxc LayerManagerD3D9Shaders.hlsl -EComponentPass2ShaderMask -nologo -Tps_2_0 -Fh$tempfile -VnComponentPass2ShaderPSMask
cat $tempfile >> LayerManagerD3D9Shaders.h
fxc LayerManagerD3D9Shaders.hlsl -ERGBShaderMask -nologo -Tps_2_0 -Fh$tempfile -VnRGBShaderPSMask
cat $tempfile >> LayerManagerD3D9Shaders.h
fxc LayerManagerD3D9Shaders.hlsl -EYCbCrShaderMask -nologo -Tps_2_0 -Fh$tempfile -VnYCbCrShaderPSMask
cat $tempfile >> LayerManagerD3D9Shaders.h
fxc LayerManagerD3D9Shaders.hlsl -ESolidColorShaderMask -nologo -Tps_2_0 -Fh$tempfile -VnSolidColorShaderPSMask
cat $tempfile >> LayerManagerD3D9Shaders.h
rm $tempfile