OpenGL GLSL: Output from shader to memory -
i need have variable/object in graphics memory can accessed within fragment shader , within normal c# code. preferably 16byte vec4
what want do:
- [in c#] read variable graphic memory cpu memory
- [in c#] set variable 0
- [in c#] execute normal drawing of scene
- [in shader] one of fragment passes writes variable (update)
- restart loop
(update) pass current mouse coordinates fragment shader uniform variables. fragment shader checks if corresponding pixel. if yes writes color colorpicking variable. reason dont write fs output didn't find solution on internet on how output normal memory. additionaly have output each pixel instead of 1
what want uniform variable shader can write to.
is there kind of variable/object fits needs , if how performant be?
a "uniform" shader can write wrong term. uniform means uniform (as in same value everywhere). if specific shader invocation changing value, not uniform anymore.
you can use atomic counters sort of thing; increment counter every test passes , later check non-zero state. vastly simpler setting general-purpose shader storage buffer object , worrying making memory access coherent.
occlusion queries available older hardware. work surprisingly atomic counters, can (very roughly) count number of fragments pass depth test. not count on accuracy, use discard in fragment shader pixel not pass test condition , test non-zero fragment count in query readback.
as performance, long can deal couple frames worth of latency between issuing command , later using result, should fine.
if try use either, atomic counter or occlusion query , read-back result during same frame, stall pipeline , eliminate cpu/gpu parallelism.
i suggest inserting fence sync object in command stream , checking status of fence once per-frame before attempting read results back. prevent stalling.
Comments
Post a Comment