Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Scale horizontally to an intermediate target, then vertically to the …

…final target. Each step is materialized by a shader pass.

The intermediate render target now has the source height and the destination width, which is reflected in the vertex coordinates and the vertex coordinates stepping parameter.
  • Loading branch information...
commit 0d983d87e7c7f8854c4ea6cebab0c057d4d7dd06 1 parent dceffd2
CrystalP CrystalP authored
89 system/shaders/convolutionsep-4x4_d3d.fx
View
@@ -22,7 +22,8 @@
texture g_Texture;
texture g_KernelTexture;
texture g_IntermediateTexture;
-float2 g_StepXY;
+float2 g_StepXY_P0;
+float2 g_StepXY_P1;
sampler RGBSampler =
sampler_state {
@@ -82,84 +83,84 @@ half4 weight(float pos)
#endif
}
-half3 pixel(float xpos, float ypos)
+half3 pixel(sampler samp, float xpos, float ypos)
{
- return tex2D(RGBSampler, float2(xpos, ypos)).rgb;
+ return tex2D(samp, float2(xpos, ypos)).rgb;
}
+// Code for first pass - horizontal
+
half3 getLine(float ypos, float4 xpos, half4 linetaps)
{
return
- pixel(xpos.r, ypos) * linetaps.r +
- pixel(xpos.g, ypos) * linetaps.g +
- pixel(xpos.b, ypos) * linetaps.b +
- pixel(xpos.a, ypos) * linetaps.a;
+ pixel(RGBSampler, xpos.r, ypos) * linetaps.r +
+ pixel(RGBSampler, xpos.g, ypos) * linetaps.g +
+ pixel(RGBSampler, xpos.b, ypos) * linetaps.b +
+ pixel(RGBSampler, xpos.a, ypos) * linetaps.a;
}
PS_OUTPUT CONVOLUTION4x4Horiz(VS_OUTPUT In)
{
PS_OUTPUT OUT;
- float2 pos = In.TextureUV + g_StepXY * 0.5;
- float2 f = frac(pos / g_StepXY);
+ float2 pos = In.TextureUV + g_StepXY_P0 * 0.5;
+ float2 f = frac(pos / g_StepXY_P0);
- half4 linetaps = weight(1.0 - f.x);
- half4 columntaps = weight(1.0 - f.y);
+ half4 linetaps = weight(1.0 - f.x);
// kernel generation code made sure taps add up to 1, no need to adjust here.
- float2 xystart = (-1.0 - f) * g_StepXY + In.TextureUV;
+ float2 xystart;
+ xystart.x = (-1.0 - f.x) * g_StepXY_P0.x + In.TextureUV.x;
+ xystart.y = In.TextureUV.y;
+
float4 xpos = float4(
xystart.x,
- xystart.x + g_StepXY.x,
- xystart.x + g_StepXY.x * 2.0,
- xystart.x + g_StepXY.x * 3.0);
-
- OUT.RGBColor.rgb =
- getLine(xystart.y , xpos, linetaps) * columntaps.r +
- getLine(xystart.y + g_StepXY.y , xpos, linetaps) * columntaps.g +
- getLine(xystart.y + g_StepXY.y * 2.0, xpos, linetaps) * columntaps.b +
- getLine(xystart.y + g_StepXY.y * 3.0, xpos, linetaps) * columntaps.a;
+ xystart.x + g_StepXY_P0.x,
+ xystart.x + g_StepXY_P0.x * 2.0,
+ xystart.x + g_StepXY_P0.x * 3.0);
+ OUT.RGBColor.rgb = getLine(xystart.y, xpos, linetaps);
OUT.RGBColor.a = 1.0;
+
return OUT;
}
+// Code for second pass - vertical
+
+half3 getRow(float xpos, float4 ypos, half4 columntaps)
+{
+ return
+ pixel(IntermediateSampler, xpos, ypos.r) * columntaps.r +
+ pixel(IntermediateSampler, xpos, ypos.g) * columntaps.g +
+ pixel(IntermediateSampler, xpos, ypos.b) * columntaps.b +
+ pixel(IntermediateSampler, xpos, ypos.a) * columntaps.a;
+}
+
PS_OUTPUT CONVOLUTION4x4Vert(VS_OUTPUT In)
{
PS_OUTPUT OUT;
- float2 pos = In.TextureUV + g_StepXY * 0.5;
- float2 f = frac(pos / g_StepXY);
+ float2 pos = In.TextureUV + g_StepXY_P1 * 0.5;
+ float2 f = frac(pos / g_StepXY_P1);
- half4 linetaps = weight(1.0 - f.x);
half4 columntaps = weight(1.0 - f.y);
// kernel generation code made sure taps add up to 1, no need to adjust here.
- float2 xystart = (-1.0 - f) * g_StepXY + In.TextureUV;
- float4 xpos = float4(
- xystart.x,
- xystart.x + g_StepXY.x,
- xystart.x + g_StepXY.x * 2.0,
- xystart.x + g_StepXY.x * 3.0);
+ float2 xystart;
+ xystart.x = In.TextureUV.x;
+ xystart.y = (-1.0 - f.y) * g_StepXY_P1.y + In.TextureUV.y;
- OUT.RGBColor.rgb =
- getLine(xystart.y , xpos, linetaps) * columntaps.r +
- getLine(xystart.y + g_StepXY.y , xpos, linetaps) * columntaps.g +
- getLine(xystart.y + g_StepXY.y * 2.0, xpos, linetaps) * columntaps.b +
- getLine(xystart.y + g_StepXY.y * 3.0, xpos, linetaps) * columntaps.a;
+ float4 ypos = float4(
+ xystart.y,
+ xystart.y + g_StepXY_P1.y,
+ xystart.y + g_StepXY_P1.y * 2.0,
+ xystart.y + g_StepXY_P1.y * 3.0);
+ OUT.RGBColor.rgb = getRow(xystart.x, ypos, columntaps);
OUT.RGBColor.a = 1.0;
- return OUT;
-}
-PS_OUTPUT Nothing(VS_OUTPUT In)
-{
- PS_OUTPUT OUT;
-
- OUT.RGBColor.rgb = tex2D(IntermediateSampler, In.TextureUV).rgb;
- OUT.RGBColor.a = 1.0;
return OUT;
}
@@ -174,7 +175,7 @@ technique SCALER_T
}
pass P1
{
- PixelShader = compile ps_3_0 Nothing();
+ PixelShader = compile ps_3_0 CONVOLUTION4x4Vert();
ZEnable = False;
FillMode = Solid;
FogEnable = False;
111 system/shaders/convolutionsep-6x6_d3d.fx
View
@@ -22,7 +22,8 @@
texture g_Texture;
texture g_KernelTexture;
texture g_IntermediateTexture;
-float2 g_StepXY;
+float2 g_StepXY_P0;
+float2 g_StepXY_P1;
sampler RGBSampler =
sampler_state {
@@ -82,98 +83,96 @@ half3 weight(float pos)
#endif
}
-half3 pixel(float xpos, float ypos)
+half3 pixel(sampler samp, float xpos, float ypos)
{
- return tex2D(RGBSampler, float2(xpos, ypos)).rgb;
+ return tex2D(samp, float2(xpos, ypos)).rgb;
}
+// Code for first pass - horizontal
+
half3 getLine(float ypos, float3 xpos1, float3 xpos2, half3 linetaps1, half3 linetaps2)
{
return
- pixel(xpos1.r, ypos) * linetaps1.r +
- pixel(xpos1.g, ypos) * linetaps2.r +
- pixel(xpos1.b, ypos) * linetaps1.g +
- pixel(xpos2.r, ypos) * linetaps2.g +
- pixel(xpos2.g, ypos) * linetaps1.b +
- pixel(xpos2.b, ypos) * linetaps2.b;
+ pixel(RGBSampler, xpos1.r, ypos) * linetaps1.r +
+ pixel(RGBSampler, xpos1.g, ypos) * linetaps2.r +
+ pixel(RGBSampler, xpos1.b, ypos) * linetaps1.g +
+ pixel(RGBSampler, xpos2.r, ypos) * linetaps2.g +
+ pixel(RGBSampler, xpos2.g, ypos) * linetaps1.b +
+ pixel(RGBSampler, xpos2.b, ypos) * linetaps2.b;
}
PS_OUTPUT CONVOLUTION6x6Horiz(VS_OUTPUT In)
{
PS_OUTPUT OUT;
- float2 pos = In.TextureUV + g_StepXY * 0.5;
- float2 f = frac(pos / g_StepXY);
+ float2 pos = In.TextureUV + g_StepXY_P0 * 0.5;
+ float2 f = frac(pos / g_StepXY_P0);
- half3 linetaps1 = weight((1.0 - f.x) / 2.0);
- half3 linetaps2 = weight((1.0 - f.x) / 2.0 + 0.5);
- half3 columntaps1 = weight((1.0 - f.y) / 2.0);
- half3 columntaps2 = weight((1.0 - f.y) / 2.0 + 0.5);
+ half3 linetaps1 = weight((1.0 - f.x) / 2.0);
+ half3 linetaps2 = weight((1.0 - f.x) / 2.0 + 0.5);
// kernel generation code made sure taps add up to 1, no need to adjust here.
- float2 xystart = (-2.0 - f) * g_StepXY + In.TextureUV;
+ float2 xystart;
+ xystart.x = (-2.0 - f.x) * g_StepXY_P0.x + In.TextureUV.x;
+ xystart.y = In.TextureUV.y;
+
float3 xpos1 = float3(
xystart.x,
- xystart.x + g_StepXY.x,
- xystart.x + g_StepXY.x * 2.0);
+ xystart.x + g_StepXY_P0.x,
+ xystart.x + g_StepXY_P0.x * 2.0);
float3 xpos2 = half3(
- xystart.x + g_StepXY.x * 3.0,
- xystart.x + g_StepXY.x * 4.0,
- xystart.x + g_StepXY.x * 5.0);
-
- OUT.RGBColor.rgb = getLine(xystart.y , xpos1, xpos2, linetaps1, linetaps2) * columntaps1.r +
- getLine(xystart.y + g_StepXY.y , xpos1, xpos2, linetaps1, linetaps2) * columntaps2.r +
- getLine(xystart.y + g_StepXY.y * 2.0, xpos1, xpos2, linetaps1, linetaps2) * columntaps1.g +
- getLine(xystart.y + g_StepXY.y * 3.0, xpos1, xpos2, linetaps1, linetaps2) * columntaps2.g +
- getLine(xystart.y + g_StepXY.y * 4.0, xpos1, xpos2, linetaps1, linetaps2) * columntaps1.b +
- getLine(xystart.y + g_StepXY.y * 5.0, xpos1, xpos2, linetaps1, linetaps2) * columntaps2.b;
+ xystart.x + g_StepXY_P0.x * 3.0,
+ xystart.x + g_StepXY_P0.x * 4.0,
+ xystart.x + g_StepXY_P0.x * 5.0);
+ OUT.RGBColor.rgb = getLine(xystart.y, xpos1, xpos2, linetaps1, linetaps2);
OUT.RGBColor.a = 1.0;
+
return OUT;
}
+// Code for second pass - vertical
+
+half3 getRow(float xpos, float3 ypos1, float3 ypos2, half3 columntaps1, half3 columntaps2)
+{
+ return
+ pixel(IntermediateSampler, xpos, ypos1.r) * columntaps1.r +
+ pixel(IntermediateSampler, xpos, ypos1.g) * columntaps2.r +
+ pixel(IntermediateSampler, xpos, ypos1.b) * columntaps1.g +
+ pixel(IntermediateSampler, xpos, ypos2.r) * columntaps2.g +
+ pixel(IntermediateSampler, xpos, ypos2.g) * columntaps1.b +
+ pixel(IntermediateSampler, xpos, ypos2.b) * columntaps2.b;
+}
+
PS_OUTPUT CONVOLUTION6x6Vert(VS_OUTPUT In)
{
PS_OUTPUT OUT;
- float2 pos = In.TextureUV + g_StepXY * 0.5;
- float2 f = frac(pos / g_StepXY);
+ float2 pos = In.TextureUV + g_StepXY_P1 * 0.5;
+ float2 f = frac(pos / g_StepXY_P1);
- half3 linetaps1 = weight((1.0 - f.x) / 2.0);
- half3 linetaps2 = weight((1.0 - f.x) / 2.0 + 0.5);
half3 columntaps1 = weight((1.0 - f.y) / 2.0);
half3 columntaps2 = weight((1.0 - f.y) / 2.0 + 0.5);
// kernel generation code made sure taps add up to 1, no need to adjust here.
- float2 xystart = (-2.0 - f) * g_StepXY + In.TextureUV;
- float3 xpos1 = float3(
- xystart.x,
- xystart.x + g_StepXY.x,
- xystart.x + g_StepXY.x * 2.0);
- float3 xpos2 = half3(
- xystart.x + g_StepXY.x * 3.0,
- xystart.x + g_StepXY.x * 4.0,
- xystart.x + g_StepXY.x * 5.0);
+ float2 xystart;
+ xystart.x = In.TextureUV.x;
+ xystart.y = (-2.0 - f.y) * g_StepXY_P1.y + In.TextureUV.y;
- OUT.RGBColor.rgb = getLine(xystart.y , xpos1, xpos2, linetaps1, linetaps2) * columntaps1.r +
- getLine(xystart.y + g_StepXY.y , xpos1, xpos2, linetaps1, linetaps2) * columntaps2.r +
- getLine(xystart.y + g_StepXY.y * 2.0, xpos1, xpos2, linetaps1, linetaps2) * columntaps1.g +
- getLine(xystart.y + g_StepXY.y * 3.0, xpos1, xpos2, linetaps1, linetaps2) * columntaps2.g +
- getLine(xystart.y + g_StepXY.y * 4.0, xpos1, xpos2, linetaps1, linetaps2) * columntaps1.b +
- getLine(xystart.y + g_StepXY.y * 5.0, xpos1, xpos2, linetaps1, linetaps2) * columntaps2.b;
+ float3 ypos1 = float3(
+ xystart.y,
+ xystart.y + g_StepXY_P1.y,
+ xystart.y + g_StepXY_P1.y * 2.0);
+ float3 ypos2 = half3(
+ xystart.y + g_StepXY_P1.y * 3.0,
+ xystart.y + g_StepXY_P1.y * 4.0,
+ xystart.y + g_StepXY_P1.y * 5.0);
+ OUT.RGBColor.rgb = getRow(xystart.x, ypos1, ypos2, columntaps1, columntaps2);
OUT.RGBColor.a = 1.0;
- return OUT;
-}
-PS_OUTPUT Nothing(VS_OUTPUT In)
-{
- PS_OUTPUT OUT;
-
- OUT.RGBColor.rgb = tex2D(IntermediateSampler, In.TextureUV).rgb;
- OUT.RGBColor.a = 1.0;
return OUT;
}
@@ -188,7 +187,7 @@ technique SCALER_T
}
pass P1
{
- PixelShader = compile ps_3_0 Nothing();
+ PixelShader = compile ps_3_0 CONVOLUTION6x6Vert();
ZEnable = False;
FillMode = Solid;
FogEnable = False;
22 xbmc/cores/VideoRenderers/VideoShaders/WinVideoFilter.cpp
View
@@ -653,12 +653,13 @@ void CConvolutionShaderSeparable::Render(CD3DTexture &sourceTexture,
{
LPDIRECT3DDEVICE9 pD3DDevice = g_Windowing.Get3DDevice();
- if(m_destWidth != destWidth || m_destHeight != destHeight)
- CreateIntermediateRenderTarget(destWidth, destHeight);
+ if(m_destWidth != destWidth || m_sourceHeight != sourceHeight)
+ CreateIntermediateRenderTarget(destWidth, sourceHeight);
PrepareParameters(sourceWidth, sourceHeight, destWidth, destHeight, sourceRect, destRect);
- float texSteps[] = { 1.0f/(float)sourceWidth, 1.0f/(float)sourceHeight};
- SetShaderParameters(sourceTexture, &texSteps[0], sizeof(texSteps)/sizeof(texSteps[0]));
+ float texSteps1[] = { 1.0f/(float)sourceWidth, 1.0f/(float)sourceHeight};
+ float texSteps2[] = { 1.0f/(float)destWidth, 1.0f/(float)(sourceHeight)};
+ SetShaderParameters(sourceTexture, &texSteps1[0], sizeof(texSteps1)/sizeof(texSteps1[0]), &texSteps2[0], sizeof(texSteps2)/sizeof(texSteps2[0]));
// This part should be cleaned up, but how?
std::vector<LPDIRECT3DSURFACE9> rts;
@@ -813,12 +814,12 @@ void CConvolutionShaderSeparable::PrepareParameters(unsigned int sourceWidth, un
v[1].tv = sourceRect.y1 / sourceHeight;
v[2].x = destRect.x2 - destRect.x1;
- v[2].y = destRect.y2 - destRect.y1;
+ v[2].y = sourceRect.y2 - sourceRect.y1;
v[2].tu = sourceRect.x2 / sourceWidth;
v[2].tv = sourceRect.y2 / sourceHeight;
v[3].x = 0;
- v[3].y = destRect.y2 - destRect.y1;
+ v[3].y = sourceRect.y2 - sourceRect.y1;
v[3].tu = sourceRect.x1 / sourceWidth;
v[3].tv = sourceRect.y2 / sourceHeight;
@@ -835,12 +836,12 @@ void CConvolutionShaderSeparable::PrepareParameters(unsigned int sourceWidth, un
v[6].x = destRect.x2;
v[6].y = destRect.y2;
v[6].tu = (destRect.x2 - destRect.x1) / m_destWidth;
- v[6].tv = (destRect.y2 - destRect.y1) / m_destHeight;
+ v[6].tv = (sourceRect.y2 - sourceRect.y1) / m_sourceHeight;
v[7].x = destRect.x1;
v[7].y = destRect.y2;
v[7].tu = 0;
- v[7].tv = (destRect.y2 - destRect.y1) / m_destHeight;
+ v[7].tv = (sourceRect.y2 - sourceRect.y1) / m_sourceHeight;
// -0.5 offset to compensate for D3D rasterization
// set z and rhw
@@ -856,13 +857,14 @@ void CConvolutionShaderSeparable::PrepareParameters(unsigned int sourceWidth, un
}
}
-void CConvolutionShaderSeparable::SetShaderParameters(CD3DTexture &sourceTexture, float* texSteps, int texStepsCount)
+void CConvolutionShaderSeparable::SetShaderParameters(CD3DTexture &sourceTexture, float* texSteps1, int texStepsCount1, float* texSteps2, int texStepsCount2)
{
m_effect.SetTechnique( "SCALER_T" );
m_effect.SetTexture( "g_Texture", sourceTexture ) ;
m_effect.SetTexture( "g_KernelTexture", m_HQKernelTexture );
m_effect.SetTexture( "g_IntermediateTexture", m_IntermediateTarget ) ;
- m_effect.SetFloatArray("g_StepXY", texSteps, texStepsCount);
+ m_effect.SetFloatArray("g_StepXY_P0", texSteps1, texStepsCount1);
+ m_effect.SetFloatArray("g_StepXY_P1", texSteps2, texStepsCount2);
}
2  xbmc/cores/VideoRenderers/VideoShaders/WinVideoFilter.h
View
@@ -167,7 +167,7 @@ class CConvolutionShaderSeparable : public CConvolutionShader
unsigned int destWidth, unsigned int destHeight,
CRect sourceRect,
CRect destRect);
- virtual void SetShaderParameters(CD3DTexture &sourceTexture, float* texSteps, int texStepsCount);
+ virtual void SetShaderParameters(CD3DTexture &sourceTexture, float* texSteps1, int texStepsCount1, float* texSteps2, int texStepsCount2);
private:
CD3DTexture m_IntermediateTarget;
Please sign in to comment.
Something went wrong with that request. Please try again.