I wrote C++ code with D3D to do some general purpose computation by GPU
in these days.I can not find efficient and accurate method when I want
to compute the average value of all texels in a Quad-texture by GPU.
So do you have good idea ? Please teach me, thanks a lot.
Please log in or register to post a reply.
thats like a min filter, or box filter, im not sure if there is a quick
way to do that, thats why mips were invented.
maybe someone else can help… if you would want to do it, you have to
sample the input texture into the shader, once per each texel in the
quad then average and output, thats the only way i can think of.
Thanks for reply. In fact, I got a method which can handle this
question, but not efficent. My method is :
split the quad texture into 4 pieces like that
And I write a shader to render a quad which equal to the 1st pieces,
with sampling 4 times for each 4 pieces. Output the average of the 4
sampling values into another quad texture which size is half of the
origin one ( area is quater 1/4). After some steps, the sizes of texture
are 1x1. So I get the result.
But this method is too slow to be not suit for my need. I wish that
someone can teach me some more efficient method. So I post this thread.
Thanks for reading
the only thing i could think of to speed it up is to make it less
accurate, if you want to do it completely accurately and quick im not
sure if you can get both.
heres one way, but its way not perfect.
just reduce the size of the texture to 8x8, then just average that
normally, it wont output perfectly, thats how i read they did average
luminence checks in scenes.
Try using automatic mipmap generation and then reading back the value
from the highest mipmap. However, your method of reading 4 pixels at a
time in a shader will work better if you read 4 pixels that are right
next to each other rather than 4 pixels widely separated in the image.
For instance you would resample the image to half its dimensions by
averaging over each 2x2 box of pixels. This is pretty much how automatic
mipmap generation works anyway, but you can do it yourself if you need
more control over the process.