How to apply a SharpDX.Toolkit.Graphics.Effect directly?

孤者浪人 提交于 2019-12-11 07:54:32

问题


I'm creating an image editor for Windows Phone 8 / Windows 8 using SharpDX api and trying to apply a custom effect (SharpDX.Toolkit.Graphics.Effect) to a WriteableBitmap.

The effect itself is applied, but the result looks strange. Seems to me that the texture was reduced and inverted.

The code to apply the effect is written below.

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 );
}

Do you know what I'm doing wrong here?

SimpleEffectTest project

Best regards,

Pieter Voloshyn

---- UPDATE ----

After many tests I finally found what I did wrong. I changed the main pixel shader function parameters.

From

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

To

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

Thanks!

来源:https://stackoverflow.com/questions/18881946/how-to-apply-a-sharpdx-toolkit-graphics-effect-directly

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!