문제

I am trying to blend two images using Direct2D however only the latest Direct2D supports Effects and thus blending options. But I would like to avoid using the latest version due to compatibility issues.

  1. With that being said, is there any way to recreate the blending mode (hard-light) in Direct2D without Effects class and still keep it hardware accelerated.

  2. If not, would a purely software side rendering adversely affect performance?

  3. How can I access the pixels in D2D and do pixel by pixel manipulations?

Thank you

도움이 되었습니까?

해결책

First, what version of DirectX are you using?

1- You can write your own shaders and change the rendering pipeline to use your shaders, but this may be a lot of work if you've never done this before. This link discusses the rendering pipeline in DX11, and this link discusses it in DX 9. Look at this if you're working in DX9.

2- Purely software manipulation would be outstandingly slow, unless it is a one-time manipulation. But if it's shading or lighting you're trying to do, software rendering is out of the question. This also heavily depends on the number of images and the size of each image. I mean, if you're doing it on tiny 16x16 images per frame, it would be possible. But if you're talking about 128x128 per frame this is going to be a lot, especially because manipulating in-memory graphics involves locks and critical sections, so it's a time-consuming process.

3- This heavily depends on what version of DX you're using and how you're going about things, but check the MSDN's API reference articles on DirectX for this. I guarantee with a little googling you can find this.

At your request, here's the pseudo-code for a pixel shader that would blend two images:

// shader file start
sampler2D firstImage
sampler2D secondImage

PS_OUTPUT EvenBlendPixelShader( float4 position : POSITION0, float4 color : COLOR )
    float4 firstSample = firstImage( position )
    float4 secondSample = secondImage( position )
    float4 output = 0;
    output.x = (firstSample.x + secondSample.x) / 2;
    output.y = (firstSample.y + secondSample.y) / 2;
    output.z = (firstSample.z + secondSample.z) / 2;
    output.w = (firstSample.w + secondSample.w) / 2;
    return { position, output }

The idea is that you sample a given pixel from each image using a sampler. You then just average the values between the two and return the result.

Also check out this article on pixel shaders.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top