adding glow

Blitz3D Forums/Blitz3D Programming/adding glow

Phoenixx(Posted 2014) [#1]
This is just a question, nothing more, not looking for help or anything along that line.

But I wanted to know if there is a way to add a lens effect like glow within blitz3D.

Anyone with the answer, being good or bad, I thank you now.


Matty(Posted 2014) [#2]
There are a few different ways.

The simplest is to have another mesh or entity which is entity blended with add mode and a colour (colour of the glow) over the top of the original entity.


RemiD(Posted 2014) [#3]
Yes, i see 4 ways to add glow :

Not accurate but fast :
use a quad mesh and a texture which represents the shape and color of the mesh but blurred, then position it and rotate it at the mesh position.
If the shape is irregular (=not a sphere or a cube), you may need to use 8 textures, each texture being a capture of the shape at 45°, then apply the appropriate texture to the quad mesh depending on the camera position orientation related to the shape position orientation

Not accurate but fast :
add rectangle shapes (2 triangles) on all important edges of a mesh and color the vertices which are near the edge in the surface color and alpha 1.0 and color the vertices which are far in the surface color and alpha 0.0 (see "tecno the base" game to see a good example of this)

Accurate but may be slow depending on the complexity of the shape :
copy and scale the mesh of the shape up several time, each time with more transparency (=less alpha)

Accurate but slow :
-set the cameraviewport to a reduced size (for example 102*76 for a 1024x768 resolution)
-facultative : scale up the glowing surfaces so that they will be visible even with the smaller cameraviewport
-color the glowing surfaces in their color and fullbright
-hide all lights and set the ambientlight to 0,0,0 (all normal surfaces should be colored in black)
-render the scene
-copyrect the render to a fullbrightsurfacestexture
-blur the fullbrightsurfacestexture (can be slow depending on the texture pwidth pheight and the number of passes)
-copy the render to a glowtexture
-apply the glowtexture to a screen mesh (a rectangle mesh which cover exactly the whole screen)
-show all lights and set the ambientlight to its initial color (all normal surfaces should be colored in their colors + the lighting colors)
-render the 3d scene

I think that there is an example in the code archives to do a fast blur with quads by sswift somewhere... Here : http://www.blitzbasic.com/codearcs/codearcs.php?code=754

You can also use fastext to create a fast blur but from my tests it is not precise (there is an offset). See : http://www.blitzbasic.com/gallery/view_pic.php?id=2347&gallery=hr&page=1


Yue(Posted 2014) [#4]
;Glow effect
;Code by Mag. Idea from Sswift.

Graphics3D 640,480,32,2
SetBuffer BackBuffer()

; Create camera
Global camera=CreateCamera()
MoveEntity camera,3,3,0
RotateEntity camera,30,30,0

light=CreateLight()

Global cube=CreateCube()
PositionEntity cube,0,0,5
tex0=CreateTexture(300,300)
SetBuffer TextureBuffer(tex0)
ClsColor 255,255,255
Cls
SeedRnd(MilliSecs())
For k=1 To 50
	Color Rand(256),Rand(256),Rand(256)
	Rect Rand(600),Rand(600),Rand(600),Rand(600)
Next
EntityTexture cube,tex0
SetBuffer BackBuffer()

;glow setup
s=1
Global sizex=640/s
Global sizey=480/s
Global glowtexture=CreateTexture (384,384,256)
Global sp=CreateSprite(camera)
MoveEntity sp,-.25,-0.06,1.18
EntityAlpha sp,.32
ScaleTexture glowtexture,GraphicsWidth()/sizex,GraphicsHeight()/sizey
EntityTexture sp,glowtexture
TextureBlend glowtexture, 5
While Not KeyDown( 1 )
	TurnEntity cube,0.5,0.5,0.5
	CameraViewport camera,0,0,sizex,sizey
	RenderWorld
	CopyRect 0,0,sizex,sizey,0,0,BackBuffer(),TextureBuffer(glowtexture)
	CameraViewport camera,0,0,GraphicsWidth(),GraphicsHeight()
	
	RenderWorld
	Flip
Wend

End




Phoenixx(Posted 2014) [#5]
Thanks again to those who have help me out with this little setting, I had no idea that there was so may ways to add glow with blitz3D.

The example's I got from everyone will help out greatly, the project that I'm doing this with is a body shape, but I'll be able to figure that out with these samples.

So thanks again.