PDA

View Full Version : [MPC] PS filters ...


Seb.26
10th March 2006, 17:33
Hi ! :cool:

[Edit] ... See next post ...

Have fun ...

MPC forever !

Seb.26
13th March 2006, 11:05
EdgeSharpen v1.1 ( more readable ... )
sampler s0 : register(s0);
float4 p0 : register(c0);
float4 p1 : register(c1);

#define width (p0[0])
#define height (p0[1])
#define counter (p0[2])
#define clock (p0[3])
#define one_over_width (p1[0])
#define one_over_height (p1[1])

#define PI acos(-1)

#define Edge_width 2.0
#define Edge_threshold 0.2

#define Sharpen_width 1.2
#define Sharpen_val0 2.0
#define Sharpen_val1 0.125

float4 main(float2 tex : TEXCOORD0) : COLOR
{
// Read current pixel color
float4 Res = tex2D( s0, tex );

// Edge detection width vector
float dx = Edge_width / height;
float dy = Edge_width / width;

// Read corners color
float4 c2 = tex2D(s0, tex + float2( 0,-dy) );
float4 c3 = tex2D(s0, tex + float2(-dx,0) );
float4 c4 = tex2D(s0, tex + float2( dx,0) );
float4 c5 = tex2D(s0, tex + float2( 0, dy) );

// Compute vector lenght
float4 c0 = Res*4 - c2 - c3 - c4 - c5;

// If vector lenght > Edge_threshold : sharp this pixel
if( length(c0) > Edge_threshold )
{
// Compute sharpen's width vector
dx = Sharpen_width / width;
dy = Sharpen_width / height;

// Read 8 around pixels color
float4 c1 = tex2D(s0, tex + float2(-dx,-dy)) ;
c2 = tex2D(s0, tex + float2(0,-dy)) ;
c3 = tex2D(s0, tex + float2(-dx,0)) ;
c4 = tex2D(s0, tex + float2(dx,0));
c5 = tex2D(s0, tex + float2(0,dy)) ;
float4 c6 = tex2D(s0, tex + float2(dx,dy)) ;
float4 c7 = tex2D(s0, tex + float2(-dx,+dy));
float4 c8 = tex2D(s0, tex + float2(+dx,-dy)) ;

float4 c9 =Res * Sharpen_val0;

Res = c9 - (c1 + c2 + c3 + c4 + c5 + c6 + c7 + c8 ) * Sharpen_val1 ;

// Uncomment next line to see detected Edges in red ...
//Res = float4( 1.0, 0.0, 0.0, 0.0 );

}

return Res;
}

DisplayLessThan16 : hightlight pixel where R, G or B are < 16 ( to detect 16-235 color mapping )
sampler s0 : register(s0);
float4 p0 : register(c0);
float4 p1 : register(c1);

#define width (p0[0])
#define height (p0[1])
#define counter (p0[2])
#define clock (p0[3])
#define one_over_width (p1[0])
#define one_over_height (p1[1])

#define PI acos(-1)
#define Value_16 (16.0/255.0)

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

if( c0[0]<Value_16 )
c0 = float4( 0, 1, 0, 0 );
else if( c0[1]<Value_16 )
c0 = float4( 0, 1, 0, 0 );
else if( c0[2]<Value_16 )
c0 = float4( 0, 1, 0, 0 );

return c0;
}

Remap 16-235 to 0-255
sampler s0 : register(s0);
float4 p0 : register(c0);
float4 p1 : register(c1);

#define width (p0[0])
#define height (p0[1])
#define counter (p0[2])
#define clock (p0[3])
#define one_over_width (p1[0])
#define one_over_height (p1[1])

#define PI acos(-1)

#define Const_1 (16.0/255.0)
#define Const_2 (255.0/219.0)

float4 main(float2 tex : TEXCOORD0) : COLOR
{
return( ( tex2D( s0, tex ) - Const_1 ) * Const_2 );
}

That's all folks ...

More filters next time ... :D

Seb.

breez
13th March 2006, 12:24
Remap 16-235 -> 0-255 works well. There is a very slight difference to ffdshow's method (when done with HQ RGB32 conversion) with darker hues, but same amount of banding (minimal, can spot it with a test ramp).

Maybe I'll start using it if ATI fixes their VMR9 colorspace conversion someday :D (have to use ffdshow for now and I get the levels as a freebie aside the conversion).

Seb.26
13th March 2006, 18:07
Remap 16-235 -> 0-255 works well. There is a very slight difference to ffdshow's method
Sorry for my bad English, but could you develop a little this "difference" please ?
Does my 16->235 filter is bad ?!
...It's as simple as possible : << x = (x-16)*(255/219) >>

breez
13th March 2006, 21:08
Sorry for my bad English, but could you develop a little this "difference" please ?
Does my 16->235 filter is bad ?!
...It's as simple as possible : << x = (x-16)*(255/219) >>

I can't know which (ffdshow's or your's) is right :) I don't think the difference matters much at all (really small).

Seb.26
14th March 2006, 09:45
DisplayLessThan16 updated : MPC don"t like '||' char ...

slavickas
15th March 2006, 18:11
OT: is there simple tutorial programming shaders for MPC...

Seb.26
16th March 2006, 12:55
OT: is there simple tutorial programming shaders for MPC...
Try on M$ web site ... search for HLSL ... ;)