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.

4

1 回答 1

2

如果我没记错的话,你需要获取 BGRA 格式的像素数据,而不是 RGBA。你能检查它是否适合你吗?

你可以查看这篇文章。 创建将 HLSL 效果用于滤镜的 Lens 应用程序

问候,

彼得·沃洛申

于 2013-12-03T17:00:47.097 回答