views:

285

answers:

1

How to create Simple HLSL Silverlight filter for blending/playing with/mixing 2 images?

I need some working example of a filter which would take as an input 2 images\objects and return 1 image - result of some calculations.

I want to bring to Silverlight blend modes!)

+1  A: 

Well the first thing you would do is define a .FX file. In that you need code like the following:

uniform extern texture Image1;
uniform extern texture Image2;
sampler2D BG_Image1_Sampler = sampler_state
{
    Texture = (Image1);
    MinFilter = LINEAR;
    MagFilter = LINEAR;
    MipFilter = LINEAR;
};
sampler2D BG_Image2_Sampler = sampler_state
{
    Texture = (Image2);
    MinFilter = LINEAR;
    MagFilter = LINEAR;
    MipFilter = LINEAR;
};

float4 MyCalcFunction(float2 TexCoords : TEXCOORD0) : COLOR0
{
    float4 outColor;
    //calculations here

    return outColor;
}

technique BlurGlow
{
    pass P0
    {
        PixelShader = compile ps_2_0 MyCalcFunction();
    }
}

I'm unsure of how to use the FX file with silverlight but that should get you started!

RCIX
Hm... Your filter does not work in Silverlight nor in WPF... BTW I tested with Shazzam. And because I’m nub in Silverlight filters (I used Pixel bender HYDRA before for Flash) I do not know how to make it work=(
Blender
Hmm.... I'm not sure then, i thought the HLSL would be similar between XNA and Silverlight. Sorry!
RCIX