microsoft / WPFDXInterop

Repo for WPF DX Interop support
MIT License
307 stars 98 forks source link

can't get this to work with DepthStencilBuffer #17

Open malixg opened 8 years ago

malixg commented 8 years ago

I got D3D11Image working with SharpDX, following some of the advice in the other thread and digging through the source code, but it only works with a single RenderTarget (the RenderTargetView that's wrapping the shard handle from D3D11Image). When I try to create a DepthStencilView and call OutputMerger.SetTargets(DepthStencilView, RenderTargetView) my image just winds up being blank. As I am working with 3d, I need depth, or else the layering in the image resorts to whatever was last drawn. Please advise. Thanks and have a great day.

weltkante commented 8 years ago

Did you make sure that your rendering code works when rendering against a different SharpDX render target? If you turn on depth and suddenly the image gets blank it more likely sounds like the device is configured wrong and just discards all pixels.

If you have Win10 and VS2015 you may want to try the graphic tools debugger to see what exactly is sent to the GPU and may be able to discover at which stage the pixels are discarded.

You also could setup a different render target with SharpDX and first get your rendering code working there, before trying to render against D3D11Image. Just to eliminate possibilities for errors.

(Sorry if you already did any of this, just trying to give some general advice. I have depth working with D3DImage, though not with this library. As far as I understand it, only the render target is shared with D3DImage and not the depth buffer, so it shouldn't care if you set one through SharpDX or not.)

malixg commented 8 years ago

Thanks for the quick response! If I don't use D3D11Image and set up my SwapChain using the WindowInteropHelper.Handle, then just call SwapChain.Present after Drawing my Scene, it works perfectly; but then I have the airspace issues and can't put anything on top of my directx output, which is why I'd like to use D3D11Image.

weltkante commented 8 years ago

Ok I tried it myself with D3D11Image from the nuget package and depth buffer works. You must be doing something wrong setting up the device. Can't really tell what it could be without seeing any code, there are many things to get wrong with DirectX rendering.

ZyJChen commented 8 years ago

Hello, weltkante. Could you please provide a simple example that show D3D11Image from the nuget package and depth buffer works? I had the same problem to get DepthStencilBuffer work, but I am using C++

weltkante commented 8 years ago

https://gist.github.com/weltkante/13b41a0289339ebf80e7

Here's my (reduced) test code I wrote a few days ago to check if the depth buffer works. It draws two intersecting rectangles, which is only possible to render correctly with a depth buffer (otherwise either the red or the blue would be in foreground, which you can verify by turning off the depth buffer).

Maybe you can find out what you did wrong by compring the calls I make vs. the calls you make. I think I reduced it to the minimum amount of calls necessary to render an image.

screenshot

ZyJChen commented 8 years ago

Thank you, weltkante.

jameson75 commented 4 years ago

I had the exact same issue before finding this post - weltkante's code made me realize that I simply forgot to clear the depth/stencil buffer via DeviceContext.ClearDepthStencilView