Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Efficient pixel shader sum of all pixels

How can I efficiently calculate the sum of all pixels in an image, by using a HSLS pixel shader? I'm interested in Pixel Shader 2.0, that I could invoke as a WPF shader effect.

like image 240
luvieere Avatar asked May 31 '10 14:05

luvieere


1 Answers

There is a much simpler solution that doesn't use shaders: load the image as a texture, create a mipmap chain and read back the value of the last mipmap (1x1 pixel). This trick is used in games extensively to calculate, for example, the average brigthness of a scene (in order to apply HDR tonemapping). It's a great trick if you value simplicity and efficiency over accuracy.

like image 56
The Fiddler Avatar answered Oct 21 '22 06:10

The Fiddler