XNA Creators Club Online
Page 1 of 1 (4 items)
Sort Posts: Previous Next

Apply Pixel shader effect to 2D sprite

Last post 11/20/2009 2:24 PM by Catalin Zima. 3 replies.
  • 11/20/2009 11:11 AM

    Apply Pixel shader effect to 2D sprite

    I have following shader file(.fx) and i am using this using DirectX/C#

    float brightness;
    float contrast;
    sampler TextureSampler :register(s0);


    float4 TextureColor(in float2 texCoord : TEXCOORD0) : COLOR
    {
    float4 texCol1 = tex2D(TextureSampler, texCoord);
    float4 outColor = texCol1 + brightness;
    outColor*=contrast;
    return outColor;
    }

    technique TransformTexture
    {
    pass P0
    {
    CullMode = None;
    PixelShader = compile ps_2_0 TextureColor();
    }
    }

    it work fine when i was drawing my texture using vertex buffer like.
    _effect.Technique = "TransformTexture";
    //_effect.SetValue("Texture1", _text);
    bHandle = _effect.GetParameter(null, "brightness");
    cHandle = _effect.GetParameter(null, "contrast");


    vertexBuffer = new VertexBuffer(typeof(CustomVertex.PositionColoredTextured),
    4,_device,Usage.WriteOnly,
    CustomVertex.PositionColoredTextured.Format,Pool.Managed);

    _effect.SetValue(bHandle,.5f);
    _effect.SetValue(cHandle, .5f);
    _effect.CommitChanges();
    _device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.Black, 1, 0);
    _device.BeginScene();
    _effect.Begin(0);
    _effect.BeginPass(0);
    if (texture != null)
    {
    _device.SetTexture(0, texture);
    }
    _device.SetStreamSource(0, vertexBuffer, 0);
    _device.VertexFormat = CustomVertex.PositionColoredTextured.Format;
    _device.DrawPrimitives(PrimitiveType.TriangleStrip, 0, 2);
    if (texture != null)
    {
    _device.SetTexture(0, null);
    }
    _effect.EndPass();
    _effect.End();
    _device.EndScene();
    _device.Present(pnl1);

    but it not showing any effect on my texture when i am drawing using sprite like

    sprite=new sprite(device);
    _device.BeginScene();
    _effect.Begin(0);
    _effect.BeginPass(0);
    _sprite.Draw(_text, Vector3.Empty, Vector3.Empty, Color.White.ToArgb());
    _sprite.End();
    _effect.EndPass();
    _effect.End();
    _device.EndScene();
    _device.Present(pnl1);

    What i was doing wrong, please help me or any example or link of applying effect on sprite would be great.

    Many Thank in advance
  • 11/20/2009 11:57 AM In reply to

    Re: Apply Pixel shader effect to 2D sprite

  • 11/20/2009 12:36 PM In reply to

    Re: Apply Pixel shader effect to 2D sprite

    Thnx for reply, sample mention was showing effect for XNA i am using Managed DirectX/C# is there any sample for DirectX? i m not sure it will work for directx
  • 11/20/2009 2:24 PM In reply to

    Re: Apply Pixel shader effect to 2D sprite

    Oh, sorry. I didn't notice this was in the DirectX forums...

Page 1 of 1 (4 items) Previous Next
var gDomain='m.webtrends.com'; var gDcsId='dcschd84w10000w4lw9hcqmsz_8n3x'; var gTrackEvents=1; var gFpc='WT_FPC'; /*<\/scr"+"ipt>");} /*]]>*/
DCSIMG