Need Help with my Chroma Key Pixel Shader Algorithm
I’ve just uploaded a simple demo application that shows the Silverlight 3 Chroma Key Effect in action. If you don’t have the Silverlight 3 beta installed you will need to install it from here (the install link in the application will not work).
If you watch the demo, you’ll notice ghosting along the edges of the dancers – obviously I need help with my pixel shader algorithm:
float4 PS( VS_OUTPUT input ) : SV_Target
{
float4 color = tex2D( ImageSampler, input.UV );
if (abs(InputColor.r - color.r) <= Tolerance &&
abs(InputColor.g - color.g) <= Tolerance &&
abs(InputColor.b - color.b) <= Tolerance)
{
color.rgba = 0;
}
return color;
}
If anyone has suggestions on how to make this algorithm better – or has a better algorithm, please share it with me.
Thanks in advance.
Comments
Anonymous
May 15, 2009
PingBack from http://microsoft-sharepoint.simplynetdev.com/need-help-with-my-chroma-key-pixel-shader-algorithm/Anonymous
May 15, 2009
The comment has been removedAnonymous
May 18, 2009
In this Issue: Erik Mork , Mark Monster , Steve Strong , Rishi , Kirupa Chinnathambi ( 2 ), Timmy KokkeAnonymous
May 18, 2009
Very very nice! :) I attempted a WPF version a while ago, but HLSL / shader model 2.0 didn't allow enough statements to accomplish RGB -> HSV -> RGB conversion. Wonder if it could be done with multiple shaders + inputs somehow? (or maybe some close approximation of HSV?). I'll be watching this with great interest :)Anonymous
May 19, 2009
Interesting boko here on Chroma: http://books.google.co.nz/books?id=IpSRykrRamgC&pg=PA22&lpg=PA22&dq=HSV+chroma+tolerance&source=bl&ots=ptiPVPtJyC&sig=ryfxFXqnx4Epu45HBYb1fGk3mPs&hl=en&ei=RMcTSpveKovW6gOR-s28Dg&sa=X&oi=book_result&ct=result&resnum=1#PPA23,M1 Definitely worth trying HSV There is a great HSV -> RGB library here: http://www.markbetz.net/2009/01/21/color-tools-for-silverlight-2/Anonymous
May 25, 2009
Relative luminance (http://en.wikipedia.org/wiki/Luminance_%28relative%29) is a linear conversion from RGB, but it just makes the threshold more intuitive. Preprocessing is the way to go ideally, but I'm sure that's not an option. In general, for big calculations in shaders, you try using a texture as a look-up-table for parts of the calculations that won't fit in shader limits, but I don't think that helps here.Anonymous
July 22, 2009
Is this any better? http://daron.yondem.com/tr/PermaLink.aspx?guid=84d6a965-6c16-453f-be33-d89fd49fad1dAnonymous
February 04, 2010
The comment has been removedAnonymous
February 11, 2017
did you found a solution?