Volumetric fog?

Blitz3D Forums/Blitz3D Programming/Volumetric fog?

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

So here I am working on this Underwater Demo, when I hit my first road block in blitz, traveling near the speed of light. I want to make the sea have that all so cool looking hazy feel using fog. However, Blitz does not seem to support this directly ( witch I always took for granted in OpenGL with Gui and Glut I guess.

Anyway, Ive created a simple Fake fog system useing 10 spheres at 10% opacity. Its fast on my system and looks good enough, not as smooth on the transitions between layes as Id like but does do well for water type affects, I imagine it would work for ground fog too. The desire to not directly manipulate each entities color based on distance was my main reason for making this.

	pfog1 = CreateSphere(8,p\pivot)
	pfog2 = CreateSphere(8,p\pivot)
	pfog3 = CreateSphere(8,p\pivot)
	pfog4 = CreateSphere(8,p\pivot)
	pfog5 = CreateSphere(8,p\pivot)
	pfog6 = CreateSphere(8,p\pivot)
	pfog7 = CreateSphere(8,p\pivot)
	pfog8 = CreateSphere(8,p\pivot)
	pfog9 = CreateSphere(8,p\pivot)
	pfog10 = CreateSphere(8,p\pivot)


	FlipMesh pfog1
	FlipMesh pfog2
	FlipMesh pfog3
	FlipMesh pfog4
	FlipMesh pfog5
	FlipMesh pfog6
	FlipMesh pfog7
	FlipMesh pfog8
	FlipMesh pfog9
	FlipMesh pfog10
	pfogtex = LoadTexture ("textures\fog.bmp")
	EntityTexture pfog1, pfogtex
	EntityTexture pfog2, pfogtex
	EntityTexture pfog3, pfogtex
	EntityTexture pfog4, pfogtex
	EntityTexture pfog5, pfogtex
	EntityTexture pfog6, pfogtex
	EntityTexture pfog7, pfogtex
	EntityTexture pfog8, pfogtex
	EntityTexture pfog9, pfogtex
	EntityTexture pfog10, pfogtex

	; since the alphas tend to add up we try to keep them change at each dispance the same
	; finally reaching opaque at the tenth box
	EntityAlpha pfog1,.10
	EntityAlpha pfog2,.10
	EntityAlpha pfog3,.10
	EntityAlpha pfog4,.10
	EntityAlpha pfog5,.10
	EntityAlpha pfog6,.10
	EntityAlpha pfog7,.10
	EntityAlpha pfog8,.10
	EntityAlpha pfog9,.10
	EntityAlpha pfog10,.10
; scale the spheres to cover the range we need
	ScaleEntity pfog1,15,1,1
	ScaleEntity pfog2,15,5,5
	ScaleEntity pfog3,15,10,10
	ScaleEntity pfog4,15,15,15
	ScaleEntity pfog5,20,20,20
	ScaleEntity pfog6,25,25,25
	ScaleEntity pfog7,30,30,30
	ScaleEntity pfog8,35,35,35
	ScaleEntity pfog9,45,45,45
	ScaleEntity pfog10,55,55,55
	



The fog texture is just a 256x256 BMP file of solid dark blue.

Yea I know I could have used a type or array, but this is so simple I don't see anyone having trouble with it.

I started with boxes to try and keep poly count down, but it looked bad, so I switched to spheres. If you dont want eveything shaded by the first sphere either rescale it or just do away with it.

Also, to get varios effects of fogging its all about the scaling, I susgest in most cases that you keep the Y scale much tighter between layers than I do here.

A full demo will be uploaded soon.