The fastest blur in the west?

BlitzMax Forums/BlitzMax Programming/The fastest blur in the west?

DirectX only at the moment, OGL is not working!

The example is just a simple image, you could use this to blur a render of the whole screen for super glow effects.

Loosly based on : http://www.gamasutra.com/features/20040526/james_01.shtml

Zero Bloom Passes (not really bloom but it looks nice)

One Bloom Pass

Strict

Import Indiepath.Render2Texture

' Inspired by sswifts accelerated blur function
' Copyright Indiepath 2006
' Written by Tim Fisher.

DebugLog "MOD_Bloom.bmx"

Function BlurImage:TImage(image:TImage,Quality:Int=1,Radius:Float=1,Passes:Int=1)

	Local Angle_Step:Float = 360.0 / Float(Quality * 4)
	Local Angle:Float
	Local xOff:Float
	Local yOff:Float
	
	SetBlend(ALPHABLEND)
	SetAlpha(1)
	
	Local temp:TImage = tRender.Create(image.width,image.height,image.flags)
	
	tRender.TextureRender_Begin(temp,False)
	
		tRender.Cls($00000000)
		DrawImage(image,0,0)

		SetAlpha(0.5)
	
		For Local loop:Int = 0 To (Quality * 4) - 1
			Angle = Angle_Step * Float(loop) + 180.0 * Float(loop Mod 2)
			xOff = Radius * Cos(Angle)
			yOff = Radius * Sin(Angle)
			DrawImage(temp,xOff,yOff)
		Next
		
		PrimaryDevice.device.SetRenderState D3DRS_ALPHATESTENABLE,False
		PrimaryDevice.device.SetRenderState( D3DRS_ALPHABLENDENABLE, True );
		PrimaryDevice.device.SetRenderState( D3DRS_SRCBLEND, D3DBLEND_ONE    );
		PrimaryDevice.device.SetRenderState( D3DRS_DESTBLEND, D3DBLEND_ONE   );
	
		For Local loop:Int = 1 To Passes
			DrawImage temp,0,0
		Next
	
	tRender.TextureRender_End()

		image = Null
	SetBlend(ALPHABLEND)
	Return temp

End Function

Strict


Import "MOD_Bloom.bmx"

Graphics 640,480,0


tRender.Initialise()


Local logo:Timage = LoadImage("bmax160_2.png",FILTEREDIMAGE|MIPMAPPEDIMAGE)

Local Quality = 10
Local Radius = 4
Local Passes = 0
logo = BlurImage(logo,Quality,Radius,Passes)

tRender.BackBufferRender_Begin()

	tRender.Cls($FF000000)
	DrawImage logo,200,130
	
tRender.BackBUfferRender_End()

Flip

WaitKey()


Nice. Maybe you could put a link to your render2texture module here.

If you run displaying the blurred image in a loop, it doesnt work and after a few seconds it will crash.

also it seems that your render module is writing to the log which (IMO) is really annoying.

The second sample complains that it can't find "MOD_Bloom.bmx" --maybe I'm missing the latest version of your module? Where can I download it?

Beaker: You have to mail indiepath to get the module. He does not want it to be linked on the net.

And ModBloom is the first code block in the first posting (at least I would think that as it outputs "MOD_Bloom.bmx" to the log ;-)

And ModBloom is the first code block in the first posting (at least I would think that as it outputs "MOD_Bloom.bmx" to the log ;-)


Duh. Of course. :-?

OK, renaming the first file to mod_bloom.bmx, the second sample will now run without error... Except, it seems like nothing is actually happening....

changing the various parameters, all results in the same image being displayed, seemingly unaltered.

Dreamora - wierd, cos I downloaded it the day he posted this demo.