Realtime histogram?

Sage
Posts: 1,199
Joined: 2004.10
Post: #1
So, like I imagine a lot of people, I've futzed a lot with fine tuning post-processing effects like bloom. There's probably smart ways to do it. But I've decided that it's a fool's errand, and want to be more smarter.

It occurred to me that if I could generate a real time histogram of my image, I could use that data to tune my bloom filter's strength in real time. So, when looking out of a dark cave and most of the scene is dark, the bloom effect could be ramped up. When in an open area, well lit, the bloom could be turned down. Etc.

Obviously, readPixels and CPU-based histogram is not the way to go. So I'm wondering what kind of options I have. My thoughts are to write a histogram shader that would write into a 256x1 1D texture, and have the post-processing sample from that texture and run some logic to decide how hard to apply the filter. But I haven't really thought too hard about this yet.

Any thoughts? Has anybody done this?
Quote this message in a reply
Member
Posts: 45
Joined: 2008.04
Post: #2
In generating bloom, one way is to build a pyramid of scaled bloom textures which are then composited back to the screen... the trick I once used was to grab the top-most smallest texture (if think it was about 32x32 in our case) back into main memory and find the average overall intensity from that, smooth the result over time, and then use it to modulate the bloom in the next frame.

So yes, I guess we were doing a CPU-based histogram of sorts, but because we are dealing with such a small texture it was cheap.
Quote this message in a reply
Sage
Posts: 1,199
Joined: 2004.10
Post: #3
aBabyRabbit Wrote:So yes, I guess we were doing a CPU-based histogram of sorts, but because we are dealing with such a small texture it was cheap.

That was one of my ideas -- downsample the image to something really small in historgram that on the CPU. But I'd still prefer to stay on-gpu if possible.
Quote this message in a reply
Sage
Posts: 1,232
Joined: 2002.10
Post: #4
The fundamental problem with doing this on the GPU is scatter write to the histogram buckets.

One way to do it is using occlusion query. This will take (buckets * channels) render passes so it's not very fast, but it works on a lot of hardware.

On current hardware, you can do it with CUDA or OpenCL, but this is significantly more involved.

I think you could also do this using only a vertex shader, if you transform image values (fed as a texture, or attribute) to bucket locations. The problem there is you need to be able to accumulate into buckets, which is fine if you can blend to a >= 16 bit precision surface, but a lot of hardware can't do that.
Quote this message in a reply
Member
Posts: 268
Joined: 2005.04
Post: #5
Combining the usual fullscreen glow / bloom effect with HDR / floating point render target makes for a nice effect. Something like this:

http://harkal.sylphis3d.com/2006/05/20/h...rendering/
Quote this message in a reply
Sage
Posts: 1,199
Joined: 2004.10
Post: #6
I've been googling, and reading up on the available techniques... it's not looking good to me. For my platform ( x1600 ) and considering the strain I'm already putting on it, I don't think I have a lot of options outside of the CPU histogram of a severely downsampled image.

Now, a simplification to my situation would be a simple average luminance reading. If I could come up with the average luminance of a frame, I could use that to adjust the bloom levels dynamically. And I could probably compute average luminance by downsampling an image ( via several averaging passes ) to a single pixel, and use the luminance of that pixel...
Quote this message in a reply
Sage
Posts: 1,199
Joined: 2004.10
Post: #7
Bachus Wrote:Combining the usual fullscreen glow / bloom effect with HDR / floating point render target makes for a nice effect. Something like this:

http://harkal.sylphis3d.com/2006/05/20/h...rendering/

At a cursory examination, that's almost exactly what I'm doing right now! But the trouble is that the strength of the effect is critical. I've got situations where a strong bloom is required, and others where that strong bloom overpowers the image.

EDIT: After closer examination, it's similar, but I didn't catch that he's adding each downsampled/blurred pass. Looks smart...
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Histogram equalization g00se 0 1,834 Oct 3, 2011 12:52 PM
Last Post: g00se
  crazy realtime demo effects MarkJ 5 3,735 Feb 26, 2005 02:12 PM
Last Post: arekkusu
  System freezing issue under Mac OS X using realtime priority rjvbertin 5 3,782 Sep 3, 2004 09:51 AM
Last Post: rjvbertin
  Idea for "fake" realtime 3d dmalashock 17 6,367 Aug 20, 2003 08:32 AM
Last Post: Weston