Lighting Effect

Blitz3D Forums/Blitz3D Programming/Lighting Effect

I found this project in the gallery and was wondering how you would create the lighting effect seen on the back of the two ships.

How would you do the lighting seen around the planet??

http://www.blitzbasic.com/gallery/view_pic.php?id=1568&gallery=hr&page=3

Thanks

The lighting effect for the engines is 2 seperate fx.

First I have 3 quads which make the actual jets. two point out of the back of the ship and turn 90 degrees to each other so when viewed from a side angle you can always see the jet. Then I have another which is flat against the back of the ship so when you are looking directly at the back of the ship you can also see the ject. These are all glued into place using a pivot, however I rotate them to give a dynamic flicking effect.

The second effect is the bloom / lense flare. This again is another quad, which I point towards the camera. I also have a couple of pivots which when they come into the view of the camera activate the size and alpha of flare (depending on how close it is to the camera).

The glow on the planet is a real easy cheat. Basically the planet is a big sprite, and the glow is a part of the original sprite texture which I added using photoshop.

Here is the code for the flare rountine


;///// ENGINE GLOW EXAMPLE BY ANDREW NIXON - OCTOBER 2007 //////
;///// FREE FOR USE ON NON COMMERCIAL PROJECTS
;///// IF YOU DO USE IT, PLEASE GIVE ME A LITTLE MENTION IN THE CREDITS

Graphics3D 1024,768

Type EnemyShipOne
	Field MeshPivot
	Field Mesh
	Field glow
	Field glow2
	Field glow3
	Field glow4
	Field glow5
	Field glow6
	Field glowpivot
	Field glowpivot2
	Field glowsprite
	Field glowsprite2
	Field flarealpha#
	Field flarealpha2#
	Field flarestatus
	Field flarestatus2
End Type

Global cam=CreateCamera()
CameraZoom cam,0.8
CameraRange cam, 1,25000

Const on=1
Const off=2

Global bloomtexture=LoadTexture("texture.png",2)
TextureBlend bloomtexture,5
Global engineglowtexture=LoadTexture("glow.png",2)
TextureBlend engineglowtexture,5
Global reflectiontexture=LoadTexture("ref.png",64)
TextureBlend reflectiontexture,2

Function CreateEnemyShipOne()
	EnemyShipsOne.EnemyShipOne = New EnemyShipOne
	EnemyShipsOne\Meshpivot=CreatePivot()
	EnemyShipsOne\Mesh=LoadMesh("sf-08.b3d",EnemyShipsOne\MeshPivot)
	ScaleEntity EnemyShipsOne\Mesh,0.12,0.12,0.12
	EntityPickMode EnemyShipsOne\Mesh,2,True
	EntityTexture EnemyShipsOne\Mesh,reflectiontexture,0,2
	
	; First Glow...
	EnemyShipsOne\Glow=CreateQuad()
	EntityParent EnemyShipsOne\Glow,EnemyShipsOne\Mesh
	PositionEntity EnemyShipsOne\Glow,20,-8,-163
	RotateEntity EnemyShipsOne\Glow,0,90,0
	EntityTexture EnemyShipsOne\Glow,engineglowtexture
	EntityFX EnemyShipsOne\Glow,1+16
	EntityBlend EnemyShipsOne\Glow,3
	ScaleEntity EnemyShipsOne\Glow,45,45,45
	
	;Second Glow
	EnemyShipsOne\Glow2=CreateQuad()
	EntityParent EnemyShipsOne\Glow2,EnemyShipsOne\Mesh
	PositionEntity EnemyShipsOne\Glow2,70,-8,-163
	RotateEntity EnemyShipsOne\Glow2,0,90,0
	EntityTexture EnemyShipsOne\Glow2,engineglowtexture
	EntityFX EnemyShipsOne\Glow2,1+16
	EntityBlend EnemyShipsOne\Glow2,3
	ScaleEntity EnemyShipsOne\Glow2,45,45,45
	
	;Third Glow
	EnemyShipsOne\Glow3=CreateQuad()
	EntityParent EnemyShipsOne\Glow3,EnemyShipsOne\Mesh
	PositionEntity EnemyShipsOne\Glow3,-25,-5,-115.4
	RotateEntity EnemyShipsOne\Glow3,180,0,0
	EntityTexture EnemyShipsOne\Glow3,engineglowtexture
	EntityFX EnemyShipsOne\Glow3,1
	EntityBlend EnemyShipsOne\Glow3,3
	ScaleEntity EnemyShipsOne\Glow3,40,40,40
	
	;Fourth Glow
	EnemyShipsOne\Glow4=CreateQuad()
	EntityParent EnemyShipsOne\Glow4,EnemyShipsOne\Mesh
	PositionEntity EnemyShipsOne\Glow4,25,-5,-115.4
	RotateEntity EnemyShipsOne\Glow4,180,0,0
	EntityTexture EnemyShipsOne\Glow4,engineglowtexture
	EntityFX EnemyShipsOne\Glow4,1
	EntityBlend EnemyShipsOne\Glow4,3
	ScaleEntity EnemyShipsOne\Glow4,40,40,40
	
	;Fifth Glow
	EnemyShipsOne\Glow5=CreateQuad()
	EntityParent EnemyShipsOne\Glow5,EnemyShipsOne\Mesh
	PositionEntity EnemyShipsOne\Glow5,20,38,-163
	RotateEntity EnemyShipsOne\Glow5,90,0,0
	EntityTexture EnemyShipsOne\Glow5,engineglowtexture
	EntityFX EnemyShipsOne\Glow5,1+16
	EntityBlend EnemyShipsOne\Glow5,3
	ScaleEntity EnemyShipsOne\Glow5,45,45,45
	
	;Sixth Glow
	EnemyShipsOne\Glow6=CreateQuad()
	EntityParent EnemyShipsOne\Glow6,EnemyShipsOne\Mesh
	PositionEntity EnemyShipsOne\Glow6,-20,38,-163
	RotateEntity EnemyShipsOne\Glow6,90,0,0
	EntityTexture EnemyShipsOne\Glow6,engineglowtexture
	EntityFX EnemyShipsOne\Glow6,1+16
	EntityBlend EnemyShipsOne\Glow6,3
	ScaleEntity EnemyShipsOne\Glow6,45,45,45
	
	;Glow Pivots - These are used to check to see if the lens effect should be shown.  If visible to the camera then bloom.
	EnemyShipsOne\glowpivot=CreatePivot(EnemyShipsOne\Mesh)
	PositionEntity EnemyShipsOne\glowpivot,-25,-7,-150
	EnemyShipsOne\glowpivot2=CreatePivot(EnemyShipsOne\Mesh)
	PositionEntity EnemyShipsOne\glowpivot2,25,-7,-150
	
	;Glow Sprite1 (Lens Flare Bloom Effect)
	EnemyShipsOne\glowsprite=LoadMesh("glow.b3d")
	ScaleEntity EnemyShipsOne\glowsprite,10,5,5
	ScaleMesh EnemyShipsOne\glowsprite,10,10,10
	EntityTexture EnemyShipsOne\glowsprite,bloomtexture,0,1
	EntityBlend EnemyShipsOne\glowsprite,3
	EntityFX EnemyShipsOne\glowsprite,1+16
	
	;Glow Sprite2 (Lens Flare Bloom Effect)
	EnemyShipsOne\glowsprite2=LoadMesh("glow.b3d")
	ScaleEntity EnemyShipsOne\glowsprite2,10,5,5
	ScaleMesh EnemyShipsOne\glowsprite2,10,10,10
	EntityTexture EnemyShipsOne\glowsprite2,bloomtexture,0,1
	EntityBlend EnemyShipsOne\glowsprite2,3
	EntityFX EnemyShipsOne\glowsprite2,1+16
	
	;Init the initial alpha values for the flares
	EnemyShipsOne\FlareAlpha#=0
	EnemyShipsOne\FlareAlpha2#=0
	
	;Init the initial flare status (On or Off) for the flares
	EnemyShipsOne\Flarestatus=off
	EnemyShipsOne\Flarestatus2=off
	
	PositionEntity EnemyShipsOne\Meshpivot,0,0,55
	;RotateEntity EnemyShipsOne\Meshpivot,Rand(-50,50),Rand(-60,60),Rand(40,200)
	
End Function

Function UpdateEnemyOneFlares()
	For EnemyShipsOne.EnemyShipOne = Each EnemyShipOne
		; turn the sprites to give a sense of them flickering
		TurnEntity EnemyShipsOne\Glow,0,0,Rand(360)
		TurnEntity EnemyShipsOne\Glow2,0,0,Rand(360)
		TurnEntity EnemyShipsOne\Glow3,0,0,Rand(360)
		TurnEntity EnemyShipsOne\Glow5,0,0,Rand(360)
		TurnEntity EnemyShipsOne\Glow4,0,0,Rand(360)
		TurnEntity EnemyShipsOne\Glow6,0,0,Rand(360)
		ScaleEntity EnemyShipsOne\Glowsprite,3*(200/EntityDistance(EnemyShipsOne\Mesh,cam)),2*(200/EntityDistance(EnemyShipsOne\Mesh,cam)),1
		ScaleEntity EnemyShipsOne\Glowsprite2,3*(200/EntityDistance(EnemyShipsOne\Mesh,cam)),2*(200/EntityDistance(EnemyShipsOne\Mesh,cam)),1
		; check to see if the engine one is view and close enough to display the bloom effect
		If EntityVisible(EnemyShipsOne\glowpivot,cam) And EntityDistance(EnemyShipsOne\Mesh,cam)<400 Then
			If EnemyShipsOne\flarestatus=off Then 
				EnemyShipsOne\flarestatus=on
				EnemyShipsOne\flarealpha#=0.0
			EndIf
			If EnemyShipsOne\flarealpha<1 Then EnemyShipsOne\flarealpha=EnemyShipsOne\flarealpha+0.075
			EntityAlpha(EnemyShipsOne\glowsprite,EnemyShipsOne\flarealpha)
			PositionEntity EnemyShipsOne\glowsprite,EntityX(EnemyShipsOne\glowpivot,1),EntityY(EnemyShipsOne\glowpivot,1),EntityZ(EnemyShipsOne\glowpivot,1)
			RotateEntity EnemyShipsOne\glowsprite,EntityPitch(cam,1),EntityYaw(cam,1),EntityRoll(cam,1)
			EntityOrder EnemyShipsOne\glowsprite,-10000
		Else
			EnemyShipsOne\flarestatus=off
			If EnemyShipsOne\flarealpha>0 Then EnemyShipsOne\flarealpha=EnemyShipsOne\flarealpha-0.075
			PositionEntity EnemyShipsOne\glowsprite,EntityX(EnemyShipsOne\glowpivot,1),EntityY(EnemyShipsOne\glowpivot,1),EntityZ(EnemyShipsOne\glowpivot,1)
			RotateEntity EnemyShipsOne\glowsprite,EntityPitch(cam,1),EntityYaw(cam,1),EntityRoll(cam,1)
			EntityOrder EnemyShipsOne\glowsprite,-10000
			EntityAlpha(EnemyShipsOne\glowsprite,EnemyShipsOne\flarealpha)
		EndIf
		; check to see if the engine two is view and close enough to display the bloom effect
		If EntityVisible(EnemyShipsOne\glowpivot2,cam) And EntityDistance(EnemyShipsOne\Mesh,cam)<400 Then
			If EnemyShipsOne\flarestatus2=off Then
				EnemyShipsOne\flarestatus2=on
				EnemyShipsOne\flarealpha2=0.0
			EndIf
			If EnemyShipsOne\flarealpha2<1 Then EnemyShipsOne\flarealpha2=EnemyShipsOne\flarealpha2+0.075
			EntityAlpha(EnemyShipsOne\glowsprite2,EnemyShipsOne\flarealpha2)
			PositionEntity EnemyShipsOne\glowsprite2,EntityX(EnemyShipsOne\glowpivot2,1),EntityY(EnemyShipsOne\glowpivot2,1),EntityZ(EnemyShipsOne\glowpivot2,1)
			RotateEntity EnemyShipsOne\glowsprite2,EntityPitch(cam,1),EntityYaw(cam,1),EntityRoll(cam,1)
			EntityOrder EnemyShipsOne\glowsprite2,-10000
		Else
			EnemyShipsOne\flarestatus2=off
			If EnemyShipsOne\flarealpha2>0 Then EnemyShipsOne\flarealpha2=EnemyShipsOne\flarealpha2-0.075
			PositionEntity EnemyShipsOne\glowsprite2,EntityX(EnemyShipsOne\glowpivot2,1),EntityY(EnemyShipsOne\glowpivot2,1),EntityZ(EnemyShipsOne\glowpivot2,1)
			RotateEntity EnemyShipsOne\glowsprite2,EntityPitch(cam,1),EntityYaw(cam,1),EntityRoll(cam,1)
			EntityOrder EnemyShipsOne\glowsprite2,-10000
			EntityAlpha(EnemyShipsOne\glowsprite2,EnemyShipsOne\flarealpha2)
		EndIf
	Next	
End Function

Function CreateQuad() 
	Local Surface
	Local Mesh=CreateMesh()
	Surface=CreateSurface(Mesh)
	AddVertex Surface,+1,+1,+1,0,0
    AddVertex Surface,-1,+1,+1,1,0
    AddVertex Surface,-1,-1,+1,1,1
    AddVertex Surface,+1,-1,+1,0,1
    AddTriangle Surface,0,1,2
    AddTriangle Surface,0,2,3
	Return Mesh
End Function

Function create_skybox() 
    mesh = CreateMesh()
	
    ;front face
    brush = LoadBrush("neb7front.png",49)
    surface = CreateSurface(mesh,brush)
    AddVertex surface,-1,+1,-1,0,0
    AddVertex surface,+1,+1,-1,1,0
    AddVertex surface,+1,-1,-1,1,1
    AddVertex surface,-1,-1,-1,0,1
    AddTriangle surface,0,1,2
    AddTriangle surface,0,2,3
    FreeBrush brush
	
    ;right face
    brush = LoadBrush("neb7right.png",49)
    surface = CreateSurface(mesh,brush)
    AddVertex surface,+1,+1,-1,0,0
    AddVertex surface,+1,+1,+1,1,0
    AddVertex surface,+1,-1,+1,1,1
    AddVertex surface,+1,-1,-1,0,1
    AddTriangle surface,0,1,2
    AddTriangle surface,0,2,3
    FreeBrush brush
	
    ;back face
    brush = LoadBrush("neb7back.png",49)
    surface = CreateSurface(mesh,brush)
    AddVertex surface,+1,+1,+1,0,0
    AddVertex surface,-1,+1,+1,1,0
    AddVertex surface,-1,-1,+1,1,1
    AddVertex surface,+1,-1,+1,0,1
    AddTriangle surface,0,1,2
    AddTriangle surface,0,2,3
    FreeBrush brush
	
    ;left face
    brush = LoadBrush("neb7left.png",49)
    surface = CreateSurface(mesh,brush)
    AddVertex surface,-1,+1,+1,0,0
    AddVertex surface,-1,+1,-1,1,0
    AddVertex surface,-1,-1,-1,1,1
    AddVertex surface,-1,-1,+1,0,1
    AddTriangle surface,0,1,2
    AddTriangle surface,0,2,3
    FreeBrush brush
	
    ;top face
    brush = LoadBrush("neb7up.png",49)
    surface = CreateSurface(mesh,brush)
    AddVertex surface,-1,+1,+1,0,1
    AddVertex surface,+1,+1,+1,0,0
    AddVertex surface,+1,+1,-1,1,0
    AddVertex surface,-1,+1,-1,1,1
    AddTriangle surface,0,1,2
    AddTriangle surface,0,2,3
    FreeBrush brush
	
    ;bottom face 
    brush = LoadBrush("neb7down.png",49)
    surface = CreateSurface(mesh,brush)
    AddVertex surface,-1,-1,-1,1,0
    AddVertex surface,+1,-1,-1,1,1
    AddVertex surface,+1,-1,+1,0,1
    AddVertex surface,-1,-1,+1,0,0
    AddTriangle surface,0,1,2
    AddTriangle surface,0,2,3
    FreeBrush brush
    
    ScaleMesh mesh,0.1,0.1,0.1
    FlipMesh mesh
    EntityFX mesh,1 ; make fullbright
    Return mesh
End Function



;///////////////////// MAIN CODE //////////////////////////

;/// Create skybox and scale it
sky = create_skybox() 
ScaleEntity sky, 4000,4000,4000 
EntityOrder sky, 1 ;draw it before everything else 
CreateEnemyShipOne()


While Not KeyDown(1)
	TurnEntity sky,0.05,0.1,0.1
	For EnemyShipsOne.EnemyShipOne = Each EnemyShipOne
		;TurnEntity EnemyShipsOne\meshpivot,0,0,1
		If MouseDown(1) Then 
			TurnEntity EnemyShipsOne\meshpivot,0,1.5,0
		EndIf
		If MouseDown(2) Then 
			TurnEntity EnemyShipsOne\meshpivot,0,0,1.5
		EndIf
		TranslateEntity enemyshipsone\meshpivot,0,0,MouseZSpeed()
	Next
	
	UpdateEnemyOneFlares()
	UpdateWorld()
	RenderWorld
	Text 5,5,"Use mouse buttons one and two to rotate the ship."
	Text 5,20,"Use mouse roller wheel to move ship in and out."
	Flip 
Wend



You will need to supply your own models, and skybox textures as the ones I use are not free. I have however packed up a single exe showing you the effect in action. You can download it here...

Click Here to download EXE example


Cheers,


Unc