Is it possible to use RWTexture2D/RWTexture3D in pixel shader?

As the title already suggests, is it possible (or will it ever be possible) to use these kind buffers in pixel-shader?

The official microsoft page indicates its allowed, but for some reason monogame returns “Wrong parameter” when trying to load this effect (the compiler compiles file without error).

Currently the only way to use RWTextures is with the compute shader fork. This only works for compute shaders right now. Using RWTextures in pixel shaders is not (yet?) supported. You can write to the texture in a compute shader, and then read from it in the pixel shader though.

1 Like

Makes sense, thanks (:

Hello again after nearly 2 year: When will it possible to write to rwtextures in pixelshaders? How hard would it be to implement it?

Having asked that: What exactly is RenderTarget3D - how can I write to it inside a pixel-shader? I mean, the pixel-shader is called for every pixel to be drawn, how does a RenderTarget3D makes sense?

Best regards

I added this functionality for DirectX in the last update. So if you’re using DX you can write to textures and buffers from a pixel shader. I didn’t do for OpenGL. Doing it for OpenGL too is a bit more difficult, but certainly not impossible.

You can write to a RenderTarget3D slice by slice.
GraphicsDevice.SetRenderTarget(RenderTarget3D renderTarget, int arraySlice)
I’m pretty sure this is DX only too at the moment.

2 Likes

You can also generally use either compute shader to write to any pixel of RT3D, as well as geometry shader to route to different slices within single drawcall (that allows for some nice tricks like rendering shadow view of multiple lights in single drawcall, there is also trick how to do it without GS, however requires DX12 or at least DX12 compatible SM like 5.1)

1 Like

Hello, which version - 3.8.2?

Very nice!

Yep, I know but I need to write to a texture3d inside a pixel shader :smiley:

Yes 3.8.2