Possible to Write to a Texture in a Pixel Shader?
Asked Answered
F

2

0

I'm working on a full-screen post processing effect. I need to be able to save or write to an intermediate texture to process in an additional pass. However, there does not seem to be a way to write to a texture in a pixel/fragment shader. I would also consider a uniform buffer object or an array, but those do not seem to be supported. I also need random access, the pixel I am writing to is not the same as the pixel that is being currently processed. So is there any way to save data for the size of the screen (either a texture or some array object) that can be read from in a second pass?

Fairground answered 30/11, 2021 at 15:29 Comment(0)
C
0

I don't think this is possible without multi-pass shaders (or perhaps compute shaders), unless you wait for a frame every time and use a second viewport that contains the first viewport.

Cimabue answered 30/11, 2021 at 18:2 Comment(0)
F
0

Thanks for responding. I've been looking into it more and it seems it's just a limitation of how GPUs are designed for parallel processing, not anything specific to Godot. Yes compute shaders would probably work, but I think that is overkill for this effect. In any case, I found some code in the GPU Pro 3 book that does what I need. It's an approximation, and I don't even fully understand how it works, but it does seem to work okay.

Fairground answered 30/11, 2021 at 19:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.