如何直接应用SharpDX.Toolkit.Graphics.Effect?

时间:2013-09-18 20:39:20

标签: c# windows-phone-8 hlsl sharpdx

我正在使用SharpDX api为Windows Phone 8 / Windows 8创建一个图像编辑器,并尝试将自定义效果(SharpDX.Toolkit.Graphics.Effect)应用于WriteableBitmap。

效果本身已应用,但结果看起来很奇怪。在我看来,纹理是减少和倒置的。

应用效果的代码如下所示。

private void ApplyEffect()
{
    GraphicsDevice graphicsDevice = GraphicsDevice.New();

    RenderTarget2D renderTarget = RenderTarget2D.New( graphicsDevice, _originalBitmap.PixelWidth, _originalBitmap.PixelHeight, PixelFormat.B8G8R8A8.UNorm );

    Texture2D texture = Texture2D.New( graphicsDevice, _originalBitmap.PixelWidth, _originalBitmap.PixelHeight, PixelFormat.B8G8R8A8.UNorm );
    texture.SetData<int>( _originalBitmap.Pixels );

    Effect effect = new Effect( graphicsDevice, SimpleEffectTest.Effects.Invert.EffectBytecode );

    graphicsDevice.SetRenderTargets( renderTarget );

    SpriteBatch spriteBatch = new SpriteBatch( graphicsDevice );
    spriteBatch.Begin( SpriteSortMode.Deferred, effect );
    spriteBatch.Draw( texture, Vector2.Zero, Color.White );
    spriteBatch.End();

    renderTarget.GetData<int>( _resultBitmap.Pixels );
}

你知道我在这里做错了吗?

SimpleEffectTest project

致以最诚挚的问候,

Pieter Voloshyn

----更新----

经过多次测试后,我终于找到了我做错了什么。我更改了主像素着色器功能参数。

float4 PS(
    float4 pos  : SV_POSITION,
    float4 posScene : SCENE_POSITION,
    float2 texCoord : TEXCOORD0
) : SV_TARGET0

float4 PS(
    float4 color    : COLOR0,
    float2 texCoord : TEXCOORD0
) : SV_Target

谢谢!

0 个答案:

没有答案