I created an image with several samples and added the texture of which to the colour texture of a frame buffer with the same number of samples, in view to render several processes of a geometry which works fine.
I also need to process the depth so when I tried to add the depth buffer image texture to the frame buffer an error said that it needed to have the same number of samples as the frame buffer. Fine, I created a depth buffer image with the same number of samples and it was accepted.
I cant for the life of me find out how to write to each of the depth samples.
I use gl_fragData[n] to write to the colour samples. I have umpteen number of depth samples as forced upon me by the implementation yet no clear method to write to them.
My question is, can someone please explain how to do this.
Thanks for your replies. I have used gl_FragDepth on single sample buffers and it works a treat.
I have considered the idea of incorporating the depth buffers into the colour buffers and since I use Depth32 they fit nicely into the 4 byte per pixel format.
Thank you Nehon for confirming to me that that is the way to go.
I didnt find any Endien helpers in my initial search through the glsl language spec. So, although I haven’t actually tested, the following code should do the trick…
int readInt(in vec4 _pixel)
vec4 writeInt(in int _i)
If there are Endien helpers or optimisations to be made I would very much appreciate the details.
ps. As there isnt a way to write multisample depth buffers I wondered why the implementation would require multisample depth buffers if multisample colour buffers were provided. I note the “setTargetIndex(n)” function defined on the FrameBuffer class. I imagine the gl_FragDepth would write to the appropriate sample specified by the target index but there is no way to write to multiple depth buffers in a single pass. I haven’t tested to see if this is true as it is not the direction I am going but I have added this paragraph as a helper for someone who is.
I just noticed the fixed functionality computed depth can be obtained by reading gl_FragCoord.z
This is a float and I imagine it ranges from zero to one so the Endien helpers above will not be suitable.
I notice the glsl language specification only states that the texture2D(sampler,coord) returns a vec4. However, with depth buffers I have successfully used…
and the returned float was in the rangle of zero to one. I have yet to determine whether buffers created using RGBA8 can be read, as above, as buffers created using Depth32. I am hoping that as essentially these are just ByteBuffers that there shouldn’t be an issue.
I also need to determin whether gl_FragData[n] can be written to as a float in addition to vec4…
No errors were raised. I have yet to determine if the depth data returns sensible values but as reading the depth data provides sensible values I am hoping that writing the depth data also provides sensible values.
Writing depth in a shader turns off early depth testing in the GPU, hence making things slower by increasing fill rate significantly. There’s rarely a reason to write depth anyway…
Sounds like a case of the XY problem.