You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Not sure if this is the right place to ask generic questions about Direct2D, but here goes nothing.
I'm trying to use a pixel shader effect in Vortice's Direct2D, with the objective of drawing (R 10%, G 20%, B 30%, A 40%) rectangles on an (R 10%, G 10%, B 10%, A 100%) background. So far, the only rectangle I haven't managed to draw correctly is the one output from the shader. 😭
Draw the first rectangle using ID2D1DeviceContext6.FillRectangle():
// D2DeviceContext is ID2D1DeviceContext6
D2DeviceContext.FillRectangle(new RectangleF(x, y,64,64), OnscreenBrush);
Draw the second rectangle on an offscreen ID2D1BitmapRenderTarget, then draw this offscreen canvas using ID2D1DeviceContext6.DrawBitmap():
// OffscreenBuffer is ID2D1BitmapRenderTarget, of size 64 x 64// OffscreenBrush is ID2D1SolidColorBrush// D2DeviceContext is ID2D1DeviceContext6
OffscreenBuffer.BeginDraw();
OffscreenBuffer.Clear(Colors.Transparent);
OffscreenBuffer.FillRectangle(new RectangleF(0,0,64,64), OffscreenBrush);
OffscreenBuffer.EndDraw();
D2DeviceContext.DrawBitmap(
bitmap: OffscreenBuffer.Bitmap,
opacity:1,
interpolationMode: BitmapInterpolationMode.Linear,
sourceRectangle:new RectangleF(0,0,64,64),
destinationRectangle:new RectangleF(x, y,64,64));
Draw the third rectangle from the same offscreen render target, then draw this offscreen canvas using ID2D1DeviceContext6.DrawImage() (instead of previously ID2D1DeviceContext6.DrawBitmap()):
// D2DeviceContext is ID2D1DeviceContext6// OffscreenBuffer is ID2D1BitmapRenderTarget
D2DeviceContext.DrawImage(
image: OffscreenBuffer.Bitmap,
compositeMode: CompositeMode.SourceOver,
interpolationMode: Direct2D1.InterpolationMode.NearestNeighbor,
targetOffset:new Vector2(x, y));
Draw the fourth rectangle by passing the offscreen render target to a pixel-shader-powered ID2D1Effect, then draw the effect's output using ID2D1DeviceContext6.DrawImage():
// D2DeviceContext is ID2D1DeviceContext6// TextHightlightShader is TextHightlightShader, which extends ID2D1Effect
D2DeviceContext.DrawImage(
image: TextHightlightShader.Output,
compositeMode: CompositeMode.SourceOver,
interpolationMode: Direct2D1.InterpolationMode.NearestNeighbor,
targetOffset:new Vector2(x, y));
The shader doesn't use its input, aside from determining the size of the output. The shader just returns a hard-coded (R 10%, G 20%, B 30%, A 40%) color.
What I get
Expectations
Reality
All rectangles drawn the same.
The rectangle from the pixel shader is off: in fact each color channel seems to have been additioned.
At first I thought CompositeMode.SourceOver was to blame, but I can't explain how similar calls to .DrawImage() output different results when passed an ID2D1Bitmap (third rectangle) and an ID2D1Image (fourth rectangle). This leads me to believe that the issue isn't caused by the Vortice wrapper, nor the way the final result is drawn, but lies somewhere in relation to the pixel shader...
Not sure if this is the right place to ask generic questions about Direct2D, but here goes nothing.
I'm trying to use a pixel shader effect in Vortice's Direct2D, with the objective of drawing (R 10%, G 20%, B 30%, A 40%) rectangles on an (R 10%, G 10%, B 10%, A 100%) background. So far, the only rectangle I haven't managed to draw correctly is the one output from the shader. 😭
What I do
👉 Repro repo
Draw the first rectangle using
ID2D1DeviceContext6.FillRectangle()
:Draw the second rectangle on an offscreen
ID2D1BitmapRenderTarget
, then draw this offscreen canvas usingID2D1DeviceContext6.DrawBitmap()
:Draw the third rectangle from the same offscreen render target, then draw this offscreen canvas using
ID2D1DeviceContext6.DrawImage()
(instead of previouslyID2D1DeviceContext6.DrawBitmap()
):Draw the fourth rectangle by passing the offscreen render target to a pixel-shader-powered
ID2D1Effect
, then draw the effect's output usingID2D1DeviceContext6.DrawImage()
:The shader doesn't use its input, aside from determining the size of the output. The shader just returns a hard-coded (R 10%, G 20%, B 30%, A 40%) color.
What I get
At first I thought
CompositeMode.SourceOver
was to blame, but I can't explain how similar calls to.DrawImage()
output different results when passed anID2D1Bitmap
(third rectangle) and anID2D1Image
(fourth rectangle). This leads me to believe that the issue isn't caused by the Vortice wrapper, nor the way the final result is drawn, but lies somewhere in relation to the pixel shader...The shader effect code
The text was updated successfully, but these errors were encountered: