0

I am creating a Windows Phone 8 app and I'm working with camera. When I don't use any shader, my C# code works perfectly:

    void photoDevice_PreviewFrameAvailable(ICameraCaptureDevice sender, object args)
    {    
        sender.GetPreviewBufferArgb(captureData);
        previewTexture.SetData<int>(captureData);
    }
...
    spriteBatch.Begin();
    spriteBatch.Draw(previewTexture, new Vector2(backBufferXCenter, backBufferYCenter), null, Color.White, (float)Math.PI / 2.0f,
        new Vector2(textureXCenter, textureYCenter), new Vector2(xScale, yScale), SpriteEffects.None, 0.0f);
    spriteBatch.End();

I am getting camera input in realtime. However, I'm (just trying to passthrough the input) trying to use a pixel shader:

Texture2D MyTexture : register(t0);
sampler textureSampler = sampler_state{
 Texture = (MyTexture);
 Filter = MIN_MAG_MIP_LINEAR;
};
...
float4 pixelShader(float4 color : COLOR0,
                     float2 texCoord : TEXCOORD0) : SV_Target0
{
   float4 textureColor = tex2D(textureSampler, texCoord);
   return textureColor;
}

The shader runs fine (assigning it at the beginning of the sprite batch) with no exceptions etc but all I'm getting is red color. The whole output is pure red. What could be the reason? I am new to shaders and I'm trying to understand how they work, especially with samplers. Thank you.

Can Poyrazoğlu
  • 33,241
  • 48
  • 191
  • 389

1 Answers1

2

If I'm not wrong, you need to get the pixel data in BGRA format, not RGBA. Could you check if it works for you?

You can check this article. Creating a Lens application that uses HLSL effects for filters

Regards,

Pieter Voloshyn

Pieter Voloshyn
  • 196
  • 1
  • 7
  • I was actually following that article :) anyway, I've solved it after writing some parts of the code from scratch, and never found the real cause, it was probably a bug that I could never see back then. – Can Poyrazoğlu Dec 03 '13 at 21:46