Code archives/Graphics/Bloom

This code has been declared by its author to be Public Domain code.

Download source code

Bloom by tonyg
(Posted 20 years ago)
A bit quicker than this but poorer quality. An image is scaled down, grabbed and then drawn scaled up which blurs the image plus a bit extra with lightblend to produce a 'bloom' effect which is a bit jaggedy but pretty quick.
SuperStrict
Graphics 640,480
SeedRnd MilliSecs()
Const scaledown:Float = 8.0
AutoMidHandle True
Local IMAGE:TIMAGE = LoadImage("MAX_alpha.PNG")
Local blur:Int = 1
Local image1:timage=Null
While Not KeyHit(KEY_ESCAPE)
	Local t1:Int=MilliSecs()
	Cls
	If MouseHit(1) image1=createbloom(image)
	SetScale 1.0 , 1.0
	SetAlpha 1.0
	SetBlend maskblend
	DrawImage image , MouseX() , MouseY()
	If image1
		SetScale scaledown + (scaledown / 10.0) , scaledown + (scaledown / 10.0)
		SetBlend lightblend
		SetAlpha 0.8  ' try changing alpha value for bigger/smaller blooms.
		DrawImage image1 , MouseX() , MouseY()
	EndIf
	Flip 0
	Local t2:Int=MilliSecs()
'	Print t2 - t1
Wend
Function createbloom:timage(image:timage)
		Local st:Int=MilliSecs()
   		SetAlpha 1.0
		SetScale 1.0/scaledown,1.0/scaledown
		DrawImage image , (ImageWidth(image)/scaledown)/2 , (ImageHeight(image)/scaledown)/2
		Local mypixmap:tpixmap = GrabPixmap(0,0,ImageWidth(image)/scaledown,ImageHeight(image)/scaledown)
		Local et:Int = MilliSecs()
		Print (et-st)
		Return LoadImage(mypixmap)
End Function

Comments

chwaga
(Posted 19 years ago)
"consts must be initialized"

_33
(Posted 19 years ago)
"consts must be initialized"

This is BlitzMax code, not Blitz3D. It simply won't compile in Blitz3D.

Raz
(Posted 19 years ago)
This is great! A really simple (read: genius) way of adding a bit extra graphics wise to my game, thanks :)

P.Weijtenburg
(Posted 19 years ago)
awesome! Now i would wonder how you can GRAB a buffer area todo this.

P.Weijtenburg
(Posted 19 years ago)
I wonder, would this have been the result? looks like it:


Ked
(Posted 19 years ago)
Doesn't work.

tonyg
(Posted 19 years ago)
Doesn't work.

In what way Ked?

Ked
(Posted 19 years ago)
It doesn't produce the "bloom" effect.

tonyg
(Posted 19 years ago)
Is anybody else having trouble with this when creating the bloom effect by pressing the left mouse button?
As some people have got it working what is your machine spec?

Twitchfactor
(Posted 19 years ago)
The theory is exactly how "bloom" is created on PS2, PSX, XBox, GameCube. We take the backbuffer, shrink it down (often to a 256x256), blow it back up (to 640x480) and run a simple blur filter on it or in some cases, the hardware takes care of it.

The best blooms have thresholds, so you only bloom the brightest stuff, otherwise you end up with that vasoline look, like Prince of Persia and Oblivion.

When I get home, I'll have to check out this code and see if it works.

Raz
(Posted 19 years ago)
Goldstar: yup that's the result of it!

I cheat a little bit, but for the level bloom I use tony's code :D

edit: and I just realised I didn't add tony to the credits, so sorry about that

tonyg
(Posted 19 years ago)
@Raz, no need for credits but glad it was useful.
@Ked, please can you provide more information on what you are doing and the machine spec.

Ked
(Posted 19 years ago)
WinXP | AMD Athalon XP-M 1700+ 1.47GHz | 512 MB RAM | ATI Radeon 9250

I am copying and pasting the above code into my BlitzMax IDE. I get the BlitzMax logo (a PNG with alpha) and rename it to whatever it should be and run the code. All I see is the BlitzMax logo at the MouseX() and MouseY() location.

BTW: I have had problems with GrabPixmap in the past.

Plash
(Posted 19 years ago)
did you hit your left mouse key?

...
If MouseHit(1) image1=createbloom(image)
...


Ked
(Posted 19 years ago)
Oh goodness! I must have happened to totally somehow definitely miss that!

Yes, I hit the left mouse button, genius.

tonyg
(Posted 19 years ago)
Hmmmm... difficult to detect sarcasm in writing so can you clarify whether pressing the LMB does anything? If it doesn't then what is your machine spec?

SillyPutty
(Posted 19 years ago)
Nice snippet tonyg, really cool and works like a charm here.

P.Weijtenburg
(Posted 19 years ago)
lol @Plash, Ked & tonyg.
just to be sure, how are you holding that mouse?

Ked
(Posted 19 years ago)
Well, since there is no bloom effect, I'm going to have to say no the LMB doesn't do a single thing. I already gave you my machine spec.

tonyg
(Posted 19 years ago)
Oh well! Never mind eh!

markcw
(Posted 19 years ago)
It doesn't work until I click the left mouse button.

Code Archives Forum