glowing objects...

Blitz3D Forums/Blitz3D Programming/glowing objects...

What is the quickest way of making an object glow?
I just want to make a sphere glow so it would probably be quite easy to do i was just trying to think of the easiest and best looking ways of doing it.

I thought of creating a plain facing the camera, and putting a fading ring. But the problem with that is if you get close to the sphere the glow doesnt follow the edges of the object.

Any advice?

can't you just use EntityBlend with Add Blend mode?

Could you put a light in it?

Well to be more spaciffic i am trying to glow a planet.

Perturbatio:
What do you mean exactly by EntityBlend with Add Blend mode?

Do you mean that i create another planet and change the blend mode?

If you do that, then it isnt a soft glow which is the sort of thing i was after.

Blitz Programmer:

Put a light in it? I am trying to create a halo around the edge, how would putting a light in it help?

Try full bright:

EntityFX Planet,1

Create a quad (or just use a sprite), texture it with a glow ring image, set it to blend, parent it to your sphere and make sure the quad/sprite always faces your camera.

Alternatively, I think there's an example in the code library that handles this problem specifically - go look.

http://www.blitzbasic.co.nz/codearcs/codearcs.php?code=453

MadJack,
I have had a look at that but the moment you get closer than a certain point you can see it is just another textured sphere.

Hmmmmm

I will have a muck around and see what i can come up with.

Let me know if you come up with any other ideas.

Cheers guys.

I'd vote for the sprite too. It will face to the camera no matter what. So you only have to make it intersect the sphere in the middle.
Additionally you can set the sprites entityblendmode to 3, so it will glow like in "glow".

not sure how well it would work, but you could create a sphere at the same coordinates as the planet, flip the mesh normals (similiar method to cell shading) and scale it so that its a little larger than the planet, then use a sphere mapped texture immitating a soft glow (i.e. a fade from the center of the texture to the outer edges) (look at the teapot demo and texture in the mak folder for an example of the sphere mapping part) then use the blend mode advice above to make the sphere semi-transparent and glowing.

When I get back later today I'll mockup something quick to demonstrate what I mean as my instructions don't seem that clear to me.


sphere mapped texture immitating a soft glow



Yup, sort of what I did while back:

http://www.blitzbasic.co.nz/Community/posts.php?topic=24135



i made a planet glow once, i set the 3d object to fullbright and then put attached a sprite to it (allways facing thecamera) of a radial gradient, so the edge was visible around the 3d model.

yeah something like that :D thats some nice work mustang.

It sort of sounds like he wants something that won't fall over at close range - i.e. low earth orbit with the curve of the earth filling the screen and the atmosphere glowing on the horizon(?)

Yeah, thats the one MadJack.

I have been trying to do this for a while now and getting fed up with finding ways that half work.

I also have the problem where i cant seem to make the textures detailed enough at close range. But thats another problem entirely.

yah

playing around flip normals are kinda redundant as you have to disable backface culling for the effect to really work.

sphere texture mapping is the way to go.

Icecap: you might consider making a larger-than-planet sphere, like before, but flipping the whole mesh, rather than just the normals. It might not be a complete solution but I think it'll be something you can work with. You might then make this extra mesh face the camera at all times, and if you created a texture that laid over the mesh properly, you might be able to have something decent.

I don't know, something like this seems very hard. I saw a glow demo in the code archives but it wasn't flexible at all, and had like no comments.

I think it's a misnomer to call it a 'glow effect' - you're more looking for a volumetric/atmospheric effect.

I guess the parented sprite fx could work for long views, but once you came close enough you'd need to fade out the glow sprite and ramp up your 'volumetric' effect somehow. Now what that effect would be, I don't know.

Perhaps a series of mesh 'curtains' to simulate a volumetric atmosphere, set them to blend with a gradient texture so that the top of the curtains fade to nothing, and the bottom of the curtains are also faded before they clip into the planet surface. Write some code so that they fade as they get close to the camera - or rotate them away from camera to a constant distance.

perhaps fade in a second sphere (larger than the planet), with a tiled cloud texture.

As you get lower again, start to add some particle emitters for puffy cloud

Then use the good old fog technique to create a 'break' between the upper atmosphere and flying above landscape.

I once made a planet effect like what you are describing (my Space Game Engine). It includes a realistic outer glow around a planet, atmosphere effects (the blue sky begins to appear as you enter the atmosphere), clouds, and gravetational pull simulation.

Additionally, it includes two levels of detail for each planet (with automatic smooth transitions), intended for terrains you can explore while on a planet (not implimented fully yet).

Here's a screenshot:



I may upload the source if you think it would help any.

John J

I'd be interested - might give Icecap some pointers too.

I'd be interested too, I have my own system for planets but the atmosphere glow I have had some issues with, I have it working but its rather a messy implementation.

Here's the engine:
;3D Space Engine
;Copyright (C) 2005 John Judnich

;Globals
Type Engine
	Field Camera
	Field PlanetLOD#,PlanetLODTransition#
End Type
Global Engine.Engine=New Engine

Type Planet
	Field X#,Y#,Z#
	Field XR#,YR#,ZR#
	Field Xv#,Yv#,Zv#
	Field XRv#,YRv#,ZRv#
	Field AtmosphereRadius#
	Field AtmosphereDensity#
	Field AtmosphereR,AtmosphereG,AtmosphereB
	Field GravityPull#,Radius#
	Field GlowOffset#,GlowScale#,CloudRadius#
	
	Field Pivot
	Field LowMesh,HighMesh ;Two levels of detail for the planet
	Field GlowMesh,AtmosphereMesh ;Two meshes used for atmosphere effects
	Field CloudMesh
	Field GlowTexture,CloudTexture
	
	Field CXRv#,CYRv#,CZRv# ;Cloud angular velocities
	
	Field LightSource
	Field TextureMap,DetailMap
End Type

;This initializes the engine
Function EngineInit()
End Function

;This sets the camera used for LOD effects, and other effects requiring camera orientation data
Function EngineCamera(camera)
	Engine\Camera=camera
End Function

;This sets the distance to switch between planet LOD levels
Function EnginePlanetLOD(lodrange#,lodtransition#)
	Engine\PlanetLOD=lodrange
	Engine\PlanetLODTransition=lodtransition
End Function

;This creates a planet with the radius of Radius# and a mass of Mass#. GlowTexture will be used for atmosphere glows
Function PlanetCreate(Radius#,GravityPull#,GlowTexture$="Media\PlanetGlow.bmp",CloudTexture$="Media\Clouds.bmp")
	this.Planet=New Planet
	this\Radius=Radius
	this\GravityPull=GravityPull
	this\AtmosphereDensity=1
	
	;Create planet
	this\Pivot=CreatePivot()
	this\LowMesh=CreateSphere(24,this\Pivot)
	this\HighMesh=CreateSphere(96,this\Pivot)
	;this\HighMesh=CreateCube(this\Pivot)
	HideEntity this\HighMesh
	EntityBlend this\HighMesh,1
	ScaleEntity this\Pivot,this\Radius,this\Radius,this\Radius
	
	;Create glow
	this\GlowTexture=LoadTexture(GlowTexture,1+2)
	this\GlowMesh=CreateMesh(this\Pivot)
	surf=CreateSurface(this\GlowMesh)
	v1=AddVertex(surf,-1,-1,0,0,0)
	v2=AddVertex(surf,1,-1,0,1,0)
	v3=AddVertex(surf,1,1,0,1,1)
	v4=AddVertex(surf,-1,1,0,0,1)
	AddTriangle(surf,v1,v2,v3)
	AddTriangle(surf,v1,v3,v4)
	EntityTexture this\GlowMesh,this\GlowTexture
	EntityBlend this\GlowMesh,3 ;1=Alpha 2=Multiply 3=Add
	EntityFX this\GlowMesh,1
	
	;Create atmosphere
	this\AtmosphereMesh=CreateSphere(16,this\Pivot)
	;ScaleMesh this\AtmosphereMesh,-1,-1,-1
	ScaleEntity this\AtmosphereMesh,this\AtmosphereRadius,this\AtmosphereRadius,this\AtmosphereRadius
	EntityFX this\AtmosphereMesh,16
	EntityBlend this\AtmosphereMesh,3 ;1=Alpha 2=Multiply 3=Add
	
	;Create cloud layer
	this\CloudMesh=CreateSphere(24,this\Pivot)
	this\CloudTexture=LoadTexture(CloudTexture,1+2)
	ScaleTexture this\CloudTexture,.5,.5
	EntityTexture this\CloudMesh,this\CloudTexture
	ScaleEntity this\CloudMesh,this\CloudRadius,this\CloudRadius,this\CloudRadius
	EntityFX this\CloudMesh,16
	EntityBlend this\AtmosphereMesh,3
	;HideEntity this\CloudMesh
	
	Return Handle(this)
End Function

Function PlanetTexture(planet,TextureMap,DetailMap)
	this.Planet=Object.Planet(planet)
	this\TextureMap=TextureMap
	this\DetailMap=DetailMap
	EntityTexture this\LowMesh,TextureMap
	EntityTexture this\HighMesh,TextureMap
	EntityTexture this\HighMesh,DetailMap,0,1
End Function

;Set this to the primary light (Sun) that is illuminating the planet for correct lighting effects
Function PlanetLightsource(planet,lightsource)
	this.Planet=Object.Planet(planet)
	this\LightSource=lightsource
End Function

;This positions a planet
Function PlanetPosition(planet,x#,y#,z#)
	this.Planet=Object.Planet(planet)
	this\X=x:this\Y=y:this\Z=z
End Function

;This rotates a planet
Function PlanetRotate(planet,xr#,yr#,zr#)
	this.Planet=Object.Planet(planet)
	this\XR=xr:this\YR=yr:this\ZR=zr
End Function

;This sets the planet's linear velocity
Function PlanetLinearVelocity(planet,x#,y#,z#)
	this.Planet=Object.Planet(planet)
	this\Xv=x:this\Yv=y:this\Zv=z
End Function

;This sets the planet's angular velocity
Function PlanetAngularVelocity(planet,xr#,yr#,zr#)
	this.Planet=Object.Planet(planet)
	this\XRv=xr:this\YRv=yr:this\ZRv=zr
End Function

Function PlanetCloudSwirl(planet,xr#,yr#,zr#)
	this.Planet=Object.Planet(planet)
	this\CXRv=xr:this\CYRv=yr:this\CZRv=zr
End Function

;This adjusts various atmosphere properties. Radius is the atmosphere radius (the distance from the surface where the air will start being tinted)
;The glowscale adjusts the amount of atmospheric glow around the surface of the planet. The density sets the atmosphere density (from 0.0 to 1.0),
;with 0 being no atmosphere at all and 1 being completely dense atmosphere. glowoffset is the amount the glow will be highlighted towards the
;planet's light source.
Function PlanetAtmosphere(planet,radius#=-1,glowscale#=-1,density#=-1,glowoffset#=-1)
	this.Planet=Object.Planet(planet)
	If radius<>-1 Then
		this\AtmosphereRadius=radius*this\Radius
		ScaleEntity this\AtmosphereMesh,radius*1.2,radius*1.2,radius*1.2 ;Atmosphere mesh is scaled slightly larger so the camera is completely inside it when it starts fading in
	End If
	If glowscale<>-1 Then
		this\GlowScale=glowscale*1.1
		ScaleEntity this\GlowMesh,this\GlowScale,this\GlowScale,this\GlowScale
	End If
	If density<>-1 Then this\AtmosphereDensity=density
	If glowoffset<>-1 Then this\GlowOffset=glowoffset
	EntityAlpha this\GlowMesh,density
End Function

;This sets the color of the planet's atmosphere
Function PlanetAtmosphereColor(planet,R,G,B)
	this.Planet=Object.Planet(planet)
	this\AtmosphereR=R
	this\AtmosphereG=G
	this\AtmosphereB=B
	EntityColor this\AtmosphereMesh,R,G,B
	EntityColor this\GlowMesh,R,G,B
End Function

;This sets radius of the planet's cloud layer
Function PlanetCloudRadius(planet,radius#)
	this.Planet=Object.Planet(planet)
	this\CloudRadius=radius
	ScaleEntity this\CloudMesh,this\CloudRadius,this\CloudRadius,this\CloudRadius
End Function

Function PlanetGravity(planet,gravity#)
	this.Planet=Object.Planet(planet)
	this\GravityPull=gravity
End Function

Function PlanetGravityGet#(planet)
	this.Planet=Object.Planet(planet)
	Return this\GravityPull
End Function

Function PlanetDelete(planet)
	this.Planet=Object.Planet(planet)
	FreeEntity this\GlowMesh
	FreeEntity this\AtmosphereMesh
	FreeEntity this\Pivot
	FreeEntity this\HighMesh
	FreeEntity this\LowMesh
	FreeTexture this\CloudTexture
	FreeTexture this\GlowTexture
	Delete this
End Function

Function EnginePlanetsUpdate(Speed#)
	cx#=EntityX(Engine\Camera,True):cy#=EntityY(Engine\Camera,True):cz#=EntityZ(Engine\Camera,True)
	For this.Planet=Each Planet
		;Visual effects
		dist#=Sqr((this\x-cx)^2+(this\y-cy)^2+(this\z-cz)^2)
		
		;Fade atmosphere according to depth of camera inside the atmosphere
		ShowEntity this\AtmosphereMesh
		alt#=(dist-this\Radius)/(this\AtmosphereRadius-this\Radius)
		a#=this\AtmosphereDensity*(1-alt)
		If a<0 Then a=0
		EntityAlpha this\AtmosphereMesh,a
		
		;Make the atmospheric glow face the camera, and move it towards the sun to make it look like the sun is illuminating the atmosphere
		PositionEntity this\GlowMesh,0,0,0
		If this\LightSource<>0 Then
			PointEntity this\GlowMesh,this\LightSource
			MoveEntity this\GlowMesh,0,0,this\GlowOffset
		End If
		PointEntity this\GlowMesh,Engine\Camera
		MoveEntity this\GlowMesh,0,0,this\Radius*.3/((dist/this\Radius)-.6) ;Try to equalize the size of the halo around the earth
		
		;Smoothly fade between high res planet and low res planet
		altitude#=dist-this\Radius
		If altitude<=Engine\PlanetLOD+(Engine\PlanetLODTransition*.5) And altitude>=Engine\PlanetLOD-(Engine\PlanetLODTransition*.5) Then
			alpha#=altitude-(Engine\PlanetLOD-(Engine\PlanetLODTransition*.5))
			alpha=1-(alpha/Engine\PlanetLODTransition)
			EntityAlpha this\HighMesh,alpha
		End If
		If altitude<=Engine\PlanetLOD+(Engine\PlanetLODTransition*.5) Then
			ShowEntity this\HighMesh
		Else
			HideEntity this\HighMesh
		End If
		If altitude>=Engine\PlanetLOD-(Engine\PlanetLODTransition*.5) Then
			ShowEntity this\LowMesh
		Else
			EntityAlpha this\HighMesh,1
			ShowEntity this\HighMesh
		End If
		If altitude<Engine\PlanetLOD-(Engine\PlanetLODTransition*.6) Then
			HideEntity this\LowMesh
		End If
		
		;Gravity
		;acceleration = gravitational_pull / distance^2   {approximation}
		xv#=this\Xv:yv#=this\Yv:zv#=this\Zv
		For that.Planet=Each Planet
			pull#=that\GravityPull
			xd#=(that\X-this\X)
			yd#=(that\Y-this\Y)
			zd#=(that\Z-this\Z)
			dist2#=xd^2+yd^2+zd^2
			If dist2<>0 Then
				xv=xv+(pull*xd/dist2)*Speed
				yv=yv+(pull*yd/dist2)*Speed
				zv=zv+(pull*zd/dist2)*Speed
			End If
		Next
		this\Xv=xv:this\Yv=yv:this\Zv=zv
		
		;Cloud swirl
		RotateEntity this\CloudMesh,EntityPitch(this\CloudMesh)+this\CXRv*Speed,EntityYaw(this\CloudMesh)+this\CYRv*Speed,EntityRoll(this\CloudMesh)+this\CZRv*Speed
		
		;Movement
		this\X=this\X+this\Xv*Speed:this\Y=this\Y+this\Yv*Speed:this\Z=this\Z+this\Zv*Speed
		this\XR=this\XR+this\XRv*Speed:this\YR=this\YR+this\YRv*Speed:this\ZR=this\ZR+this\ZRv*Speed
	
		;Update planet orientation
		PositionEntity this\Pivot,this\X,this\Y,this\Z
		RotateEntity this\Pivot,this\XR,this\YR,this\ZR
	Next
End Function


You may need to put this image file where the engine can find it:



Here's some sample code so you can get the idea how the engine works.
EngineInit()
EngineCamera(cam)
EnginePlanetLOD(.3*sc,.1*sc)

planet=PlanetCreate(sc#,.001)
PlanetCloudRadius(planet,1.02)
PlanetAngularVelocity(planet,.02,.04,.01)
PlanetLightsource(planet,light)
PlanetAtmosphere(planet,1.1,1.1,.9,.06)
PlanetAtmosphereColor(planet,60,80,255)
PlanetCloudSwirl(planet,.002,.006,.004)

;tmp.Planet=Object.Planet(planet)	
;EntityParent cam,tmp\Pivot

planet2=PlanetCreate(.2,0)
PlanetAtmosphere(planet2,0,0,0)
PlanetPosition(planet2,0,0,3)
PlanetLinearVelocity(planet2,.04,0,0)

tex1=LoadTexture("Media\tex0.bmp")
tex2=LoadTexture("planet\earth.tga")
tex3=LoadTexture("Media\detail.bmp")
ScaleTexture tex3,.01,.01
TextureBlend tex3,2
ScaleTexture tex1,.3,.3
;ScaleTexture tex2,.5,.5
PlanetTexture(planet,tex2,tex3)
PlanetTexture(planet2,tex1,tex3)


If you can't figure out how to get it working, I can upload a working example (2.5MB).

Hope this helps :)

Could you upload your 2.5 mb demo.
I couldnt seem to get it working.

No more webspace :(

I'll see if I can delete some old unused stuff.

I gave up trying to free up webspace, so I e-mailed it to you. Good luck :)

I posted this in another thread that was asking a similar question so I'll also post it here:

There are some really good code examples in the code archives so it's a good idea to check it out if you are looking for something specific. Maybe these links will help you out:

quick planet glow without entityorder
www.blitzbasic.com/codearcs/codearcs.php?code=452

Glow Effect
www.blitzbasic.com/codearcs/codearcs.php?code=1351

Cheers.