Code archives/Graphics/Bloom

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

Download source code

Bloom by tonyg2007
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

chwaga2007
"consts must be initialized"


_332007
"consts must be initialized"

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


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


Trader35642008
awesome! Now i would wonder how you can GRAB a buffer area todo this.


Trader35642008
I wonder, would this have been the result? looks like it:



Ked2008
Doesn't work.


tonyg2008
Doesn't work.

In what way Ked?


Ked2008
It doesn't produce the "bloom" effect.


tonyg2008
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?


Twitchfactor2008
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.


Raz2008
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


tonyg2008
@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.


Ked2008
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.


plash2008
did you hit your left mouse key?

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



Ked2008
Oh goodness! I must have happened to totally somehow definitely miss that!

Yes, I hit the left mouse button, genius.


tonyg2008
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?


SillyPutty2008
Nice snippet tonyg, really cool and works like a charm here.


Trader35642008
lol @Plash, Ked & tonyg.
just to be sure, how are you holding that mouse?


Ked2008
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.


tonyg2008
Oh well! Never mind eh!


markcw2008
It doesn't work until I click the left mouse button.


Code Archives Forum