making my stars blur

Blitz3D Forums/Blitz3D Beginners Area/making my stars blur

Hi! I wrote this code to try and implement a blur effect. I have not added any blur effect yet, I just want some tips on how I could achieve it.

The code below is just some stupid code that makes a starfield. Basically and hints or tips only that will point me in the right direction for making each star have a blur effect. ie leaving a blurry trail behind it as it goes down the screen


Graphics3d 1024,768,16
SetBuffer BackBuffer()

Type particle
	
	Field x#
	Field y#
	Field g#
	Field s#
	
End Type

Global maxstars = 0
Global numstars = 10

While Not KeyHit(1)
	
	Cls
		
		make_stars()
		plot_stars()
		increase_stars()
		
		Text 0,750,"Number of stars =" +numstars
		Text 0,740,"Maximum Stars on screen =" +maxstars
		Text 0,10,"Press Left Control key to increase stars"
	Flip
	
Wend

End

Function make_stars()
	
	For i = maxstars To numstars 
		
		p.particle = New particle
		maxstars = maxstars + 1
		p\y = -1
		p\x = Rnd(0,1024)
		p\s = Rnd(1,10)
		
	Next
	
End Function


Function plot_stars()
	
	For p.particle = Each particle
		
		Plot p\x,p\y
		
		p\y = p\y + p\s
		
		If p\y > 768 Then
			
			 Delete p
			 maxstars = maxstars - 1
		EndIf
		
	Next
	
End Function

Function increase_stars()
	
	If KeyDown(29) = True
		
		numstars = numstars + 1
		
	EndIf
	
End Function



Should I start by looking at locking buffers?

There's an excellent fast blur in the code archives. Basically you copy the backbuffer to a quad or sprite in front of the screen, every frame.

Thx Ross. :) I'll have a look.

Or you could set CameraClsMode to clear Z buffer only and set a translucent black sprite in front of the camera. The opacity would then vary the intensity of the blur.

Sticking with 2D only, I added a z coord which varies the intensity of the star, and a slight trail. Is this what you were thinking about or did you want more blur?

Also, I changed it to re-use the particles rather than deleting and recreating them every time.

Const gWidth=1024
Const gheight = 768
Graphics3D 1024,768,0,0
SetBuffer BackBuffer()

Type particle
	
	Field x#
	Field y#
	Field z#
	Field g#
	Field s#
	
End Type

Global numstars = 0
Global maxstars = 10

make_stars()

While Not KeyHit(1)
	
	
		
		;make_stars()
		plot_stars()
		increase_stars()

		Color 255,255,255
		Text 0,750,"Number of stars =" +numstars
		Text 0,10,"Press Left Control key to increase stars"
	Flip
	Cls
	
Wend

End

Function AddStar()
		p.particle = New particle
		numstars = numstars + 1
		p\y = 6
		p\x = Rnd(1,1022)
		p\s = Rnd(1,10)
		p\z = (1.25*p\s)*20
End Function

Function make_stars()
	
	For i = 0 To maxstars 
		
		p.particle = New particle
		numstars = numstars + 1
		p\y = 6
		p\x = Rnd(0,1024)
		p\s = Rnd(1,10)
		p\z = (1.25*p\s)*20
		
	Next
	
End Function


Function plot_stars()
	LockBuffer
	For p.particle = Each particle

		argb=(p\z Or (p\z Shl 8) Or (p\z Shl 16) Or ($ff000000))
		WritePixelFast p\x,p\y,argb

		If p\z>200 Then
			argb=(p\z Or (p\z Shl 8) Or (p\z Shl 16) Or ($ff000000))
			WritePixelFast p\x-1,p\y,argb
			WritePixelFast p\x+1,p\y,argb
		EndIf

		argb=(p\z / 1.5 Or (p\z / 1.5  Shl 8) Or (p\z / 1.5  Shl 16) Or ($ff000000))
		WritePixelFast p\x,p\y-1,argb
		
		argb=(p\z / 1.5 Or (p\z / 1.5  Shl 8) Or (p\z / 1.5  Shl 16) Or ($ff000000))
		WritePixelFast p\x,p\y-2,argb
		
		argb=(p\z / 2 Or (p\z / 2  Shl 8) Or (p\z / 2  Shl 16) Or ($ff000000))
		WritePixelFast p\x,p\y-3,argb
		
		argb=(p\z / 2 Or (p\z / 2  Shl 8) Or (p\z / 2  Shl 16) Or ($ff000000))
		WritePixelFast p\x,p\y-4,argb
		
		argb=(p\z / 4 Or (p\z / 4  Shl 8) Or (p\z / 4  Shl 16) Or ($ff000000))
		WritePixelFast p\x,p\y-5,argb
		
		argb=(p\z / 4 Or (p\z / 4  Shl 8) Or (p\z / 4  Shl 16) Or ($ff000000))
		WritePixelFast p\x,p\y-6,argb
						
		p\y = p\y + p\s
		
		If p\y > gHeight-1 Then
			
			p\y = 6
		EndIf
		
	Next
	UnlockBuffer
	
End Function


Function increase_stars()
	
	If KeyDown(29) = True

		AddStar()
		
	EndIf
	
End Function


Thats what I was looking for Pertubation. Thx :) Although a little more trailing blur would be nice. :)