c++ - Write to mutiple 3Dtextures in fragment shader OpenGL -
i have 3d texture write info , utilize voxels in fragment shader in way:
#extension gl_arb_shader_image_size : enable ... layout (binding = 0, rgba8) coherent uniform image3d volumetexture; ... void main(){ vec4 fragmentcolor = ... vec3 coords = ... imagestore(volumetexture, ivec3(coords), fragmentcolor); }
and texture defined in way
glgentextures(1, &volumetexture); glbindtexture(gl_texture_3d, volumetexture); glteximage3d(gl_texture_3d, 0, gl_rgba8, volumedimensions, volumedimensions, volumedimensions, 0, gl_rgba, gl_unsigned_byte, 0);
and when have utilize it
glactivetexture(gl_texture0); glbindtexture(gl_texture_3d, volumetexture);
now issue have mipmapped version of , without using opengl function because noticed extremely slow. thinking of writing in 3d texture @ levels @ same time so, instance, max resolution 512^3 , write 1 voxel value in 3dtex write 0.125*value 256^3 voxel , 0.015625*value 126^3 etc. since using imagestore, uses atomicity values written , using these weights automatically average value (not interpolation might pleasing result anyway). question is, best way have multiple 3dtextures , writing in of them @ same time?
i believe hardware mipmapping fast you'll get. i've assumed attempting custom mipmapping slower given have bind , rasterize each layer manually in turn. atomics give huge contention , it'll amazingly slow. without atomics you'd negating nice o(log n) construction of mipmaps.
you have really careful imagestore
regard access order , cache. i'd start here , seek different indexing (eg row/column vs column/row).
you seek drawing texture older way, binding fbo , drawing total screen triangle (big triangle covers viewport) gldrawelementsinstanced
. in geometry shader, set gl_layer
instance id. rasterizer creates fragments x/y , layer gives z.
lastly, 512^3 huge texture todays standards. maybe find out theoretical max gpu bandwidth thought of how far away are. e.g. lets gpu can 200gb/s. you'll 100 in case anyway. 512^3 texture 512mb might able write in ~5ms (imo seems awfully fast, maybe made mistake). expect overhead , latency rest of pipeline, spawning , executing threads etc. if you're writing complex stuff memory bandwidth isn't bottleneck , estimation goes out window. seek writing zeroes first. seek changing coords
xyz
order.
update: instead of using fragment shader create threads, vertex shader can used instead, , in theory avoids rasterizer overhead though i've seen cases doesn't perform well. glenable(gl_rasterizer_discard)
, gldrawarrays(gl_points, 0, numthreads)
, utilize gl_vertexid
thread index.
c++ opengl voxels 3d-texture image-unit
No comments:
Post a Comment