Deinterlacing

is it possible to adapte this code (from media player classic) to vvvv :

sampler s0 : register(s0);
float4 p0 : register(c0);
float4 p1 : register(c1);

  • define width (p00)

  • define height (p01)

  • define counter (p02)

  • define clock (p03)

  • define one_over_width (p10)

  • define one_over_height (p11)

  • define PI acos(-1)

float4 main(float2 tex : TEXCOORD0) : COLOR
{
float4 c0 = tex2D(s0, tex);

float2 h = float2(0, 1/height);
float4 c1 = tex2D(s0, tex-h);
float4 c2 = tex2D(s0, tex+h);
c0 = (c0*2+c1+c2)/4;

return c0;
}

{CODE(ln=>1)}float4 main(float2 tex : TEXCOORD0) : COLOR
{
float4 c0 = tex2D(s0, tex);

float2 h = float2(0, 1/height);
float4 c1 = tex2D(s0, tex-h);
float4 c2 = tex2D(s0, tex+h);
c0 = (c0*2+c1+c2)/4;

return c0;
}
^

thats a pixel shader code, c+p this into an effect file, modify the techniqie to use “main” as pixel shader, and rename the sampler to s0, this should work. but i dont understand the defines at the beginning, only height is used by the code, i am sure there is missing something…

It works but with blend method.
the better will be Bob method : http://www.hthoma.de/video/interlace/index.html

{CODE(ln=>1)}-------------------------------------------------------------------------------------------------------------------------------------
// PARAMETERS:
// -------------------------------------------------------------------------------------------------------------------------------------

float4x4 tW: WORLD;
float4x4 tV: VIEW;
float4x4 tP: PROJECTION;
float4x4 tWVP: WORLDVIEWPROJECTION;

texture Tex;
float4x4 tTex ;
float reglage = 0.001936;

sampler s0 = sampler_state
{
Texture = (Tex);
MipFilter = LINEAR;
MinFilter = LINEAR;
MagFilter = LINEAR;
};

// -------------------------------------------------------------------------------------------------------------------------------------
// VERTEXSHADERS
// -------------------------------------------------------------------------------------------------------------------------------------
struct vs2ps
{
float4 Pos : POSITION;
float2 TexCd : TEXCOORD0;
};

vs2ps VS(
float4 PosO : POSITION,
float4 TexCd : TEXCOORD0)
{
vs2ps Out = (vs2ps)0;

Out.Pos = mul(PosO, tWVP);

Out.TexCd = mul(TexCd, tTex);

return Out;

}

// -------------------------------------------------------------------------------------------------------------------------------------
// PIXELSHADERS:
// -------------------------------------------------------------------------------------------------------------------------------------

float4 main(float2 tex : TEXCOORD0) : COLOR
{
float4 dtot = tex2D(s0, tex);

float2 h = float2(0, reglage);
float4 dpair = tex2D(s0, tex-h);
float4 dimpair = tex2D(s0, tex+h);
dtot = (dtot*2+dpair+dimpair)/4;

return dtot;
}

// -------------------------------------------------------------------------------------------------------------------------------------
// TECHNIQUES:
// -------------------------------------------------------------------------------------------------------------------------------------

technique Remi
{
pass P0
{
VertexShader = compile vs_1_1 VS();
PixelShader = compile ps_1_4 main();
}
}
^

I want to work line by line and not by pixel. Is it possible ?

sure, 1/NrOfLines is the size of a line. with that value you can work line by line…

ok but where in the code ?

hm… i guess:

float reglage = 1/NrOfLines;

Hi,

I’ve tried to do a kind of Bob deinterlacing:

The code is this one:
{CODE(ln=>1)}
// this is a very basic template. use it to start writing your own effects.
// if you want effects with lighting start from one of the GouraudXXXX or PhongXXXX effects

// --------------------------------------------------------------------------------------------------
// PARAMETERS:
// --------------------------------------------------------------------------------------------------

//transforms
float4x4 tW: WORLD; //the models world matrix
float4x4 tV: VIEW; //view matrix as set via Renderer (EX9)
float4x4 tP: PROJECTION;
float4x4 tWVP: WORLDVIEWPROJECTION;

//texture transformation marked with semantic TEXTUREMATRIX to achieve symmetric transformations
float4x4 tTex: TEXTUREMATRIX ;

//resolution

float width = 720;
float height = 576;

bool oddFirst ;

//texture
texture Tex ;
//--------------------------------------------------------------------------------------
// Texture samplers
//--------------------------------------------------------------------------------------
sampler BaseTextureSampler = sampler_state
{
Texture = ;
MinFilter = Linear;
MagFilter = Linear;
MipFilter = Linear;
};

//--------------------------------------------------------------------------------------
// Vertex shader output structure
//--------------------------------------------------------------------------------------
struct VS_OUTPUT
{
float4 vPos : POSITION; // vertex position
float2 TextureUV : TEXCOORD0; // vertex texture coords
//define new var pixel
float2 Pix : TEXCOORD1;
};

//--------------------------------------------------------------------------------------
// This shader computes standard transform
//--------------------------------------------------------------------------------------
VS_OUTPUT RenderVS( float4 vPos : POSITION,
float3 vTexCoord0 : TEXCOORD0 )
{
VS_OUTPUT Out = (VS_OUTPUT)0;

Out.vPos = mul(vPos, tWVP);
Out.TextureUV = mul(vTexCoord0, tTex);

//une ligne c'est la hauteur de la texture 1/Height
Out.Pix.x = 1/float (width);
Out.Pix.y = 1/float (height);


return Out;

}

//--------------------------------------------------------------------------------------
// Pixel shader output structure
//--------------------------------------------------------------------------------------
struct PS_OUTPUT
{
float4 RGBColor : COLOR0; // Pixel color
};

// Bob Deinterlacing
//--------------------------------------------------------------------------------------
// This shader outputs the pixel’s color by using the texture’s color
//--------------------------------------------------------------------------------------
PS_OUTPUT RenderPS( VS_OUTPUT In )
{
PS_OUTPUT Output;

Output.RGBColor =  tex2D(BaseTextureSampler, float2 (In.TextureUV.x,
                                                     In.TextureUV.y));

//alterne la passe paire et impaire
if (oddFirst==1)
{
    //dedouble lignes paires
    if (int (In.TextureUV.y*576)%2 == 1) //sur une ligne impair
    {
       Output.RGBColor = tex2D(BaseTextureSampler, float2 (In.TextureUV.x,
                                                  In.TextureUV.y-In.Pix.y));

    }

 }
 else
 {
    //dedouble lignes impaires
    if (int (In.TextureUV.y*576)%2 == 0) //sur une ligne paire
    {
       Output.RGBColor = tex2D(BaseTextureSampler, float2 (In.TextureUV.x,
                                                  In.TextureUV.y+In.Pix.y));

    }

 }

return Output;

}

//--------------------------------------------------------------------------------------
// Renders scene to render target
//--------------------------------------------------------------------------------------
technique BobDeinterlacing
{
pass P0
{
VertexShader = compile vs_1_1 RenderVS( );
PixelShader = compile ps_2_0 RenderPS( );
}
}
^

I would like to change the oddFirst boolean value after each pass. I’ve already tried to put a “oddFirst = !oddFirst;” line at the end of the pixelshader code but it seems that not possible to change global value between passes.

testBob Deinterlace.zip (2.8 kB)

you could create a float input, and toggle it from vvvv

better solution is connecting it to the missing newFrame output pin on the videotexture i have on my wishlist for joreg.

where we wanted to easily test the same with a framecounter node first.

What do you think about that version?
How could I maintain the order of the fields?

BOB Deinterlacing Shader by Thiv.zip (5.4 kB)

Sorry, forget these two previous zip files.
Download only this next one:

If you need interlaced video go >> ici

A+

BOB Deinterlacing Shader by Thiv.zip (5.8 kB)

cool test videos…