Bloom.fx Offset Question

share shaders here
Post Reply
  • Author
  • Message
Offline
Posts: 66
Joined: 08 May 2014, 00:00

Bloom.fx Offset Question

I don't know anything of code other than just changing variables and seeing the results so my question is going to be dumb to some of you.

I am trying to learn more about graphics programming but I can't learn it just by staring at it so I have a question.

In the enbbloom.fx file there is a section of code that I think is used to sample the image and downscale it to smaller size.

Code: Select all

const float2 offset[4]=
	{
		float2(0.5, 0.5),
		float2(0.5, -0.5),
		float2(-0.5, 0.5),
		float2(-0.5, -0.5)
	};
Then it does this...

Code: Select all

for (int i=0; i<4; i++)
	{
		bloomuv.xy=offset[i];
		bloomuv.xy=(bloomuv.xy*screenfact.xy)+In.txcoord0.xy;
		float4 tempbloom=tex2D(SamplerBloom1, bloomuv.xy);
		bloom.xyz+=tempbloom.xyz;
	}
Here is a diagram I made to visualize what I think this is doing.

Image

Is that code taking the original image (blue-ish color) and re sizing it to the smaller red-ish box?
Is that the size of the end texture used for bloom?

As I said, I know very little of programming and this may make no sense at all.

Offline
*blah-blah-blah maniac*
Posts: 565
Joined: 05 Apr 2014, 10:29
Location: Taiwan

Re: Bloom.fx Offset Question

At any given point(txcoord0), the loop sum over itself and 4 near by pixels with given offset.

Edit: My mistake. It doesn't sum to itself since it doesn't sample at txcoord0. Just 4 offset positions.
Last edited by kingeric1992 on 01 Sep 2014, 08:06, edited 1 time in total.
_________________
Intel Xeon L5639 6C12T @3.96GHz | Gigabyte ga-x58a-ud3r | MSI GTX680 4G | 48G RAM | Intel 760p Nvme w clover bootloader
Flickr
YouTube

Offline
Posts: 66
Joined: 08 May 2014, 00:00

Re: Bloom.fx Offset Question

So then the (0,0) in my diagram is the point and the (0.5, 0.5), (0.5, -0.5), (-0.5, 0.5), and (-0.5, -0.5) are the 4 near pixels?

Sorry if I don't understand right away.

Offline
User avatar
*blah-blah-blah maniac*
Posts: 17427
Joined: 27 Dec 2011, 08:53
Location: Rather not to say

Re: Bloom.fx Offset Question

It read nearest interpolated pixels to compute blurred. I think better for understanding is my illustration, if you not sure yet:
Image
_________________
i9-9900k, 64Gb RAM, RTX 3060 12Gb, Win7

Offline
Posts: 66
Joined: 08 May 2014, 00:00

Re: Bloom.fx Offset Question

Thanks Boris, I think I see now. The (.5, .5) etc. offsets are the white points in the middle of each little square. And those are used to average the colors for that one pixel. It does that for 4 pixels and those 4 pixels are the downscaled texture. Correct?

Offline
*sensei*
Posts: 372
Joined: 28 Jul 2013, 23:26

Re: Bloom.fx Offset Question

Deriest
When you take middle of 4 pixels you get average of the 4 pixels returned. When you take middle between 2 pixels you get average of 2 pixels. You can use this to write up more efficient methods with very minimal (actually almost impossible to see) loss in quality with significant better performance.

Ie if you have 4 pixels in a block:

--------
| 1 | 2 |
--------
| 3 | 4 |
--------

If I would sample 1 + 2 + 3 + 4 separately and divide by 4 would be the same as if I would sample the exact point at which the pixels meet. Then you could write this away as a downscaled image (which is what those lines of code do that you posted)

Offline
Posts: 66
Joined: 08 May 2014, 00:00

Re: Bloom.fx Offset Question

I saw that link you posted originally prod80 and I bookmarked it but I have to read it a few more times to understand better before I post another question. I feel like my questions have been relatively dumb.

This topic may be too advanced for me at the moment.
Post Reply