Use a texture to store information from fragment AND/OR vertex shader (Random write)

No, I don’t want to random write gl_FragDatas
I want to write to an arbitrary location in a 3d texture from the fragment shader OR the vertex shader. I think I can make either work.

I want to, while i’m drawing an object, map the fragment to a position in a 3D texture and write solid white to it to indicate that there was something at that XYZ location… Completely seperately from the normal gl_FragData[0] = vec4(la-dee-da);

At the same time, i’d like to read from the last frame’s 3d texture to determine if there is anything inbetween the fragment and the lights in the scene. I have figured out how to do this without branching.

In this way, the goal would be to achieve approximately correct shadows without rendering the scene twice.

With fragments I know there’d be the issue of fragments that were culled because they were on a backface or something, but with vertices I don’t think i’d have that issue and of course I could always disable backface culling

Is there some way I could achieve what I desire?


You need to use glBindImageTexture() and imageStore().