问题
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