Heat Distortion

Blitz3D Forums/Blitz3D Programming/Heat Distortion

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.

Hmm, there was once a thread of a guy that developed a quite simple Heat post-screen effect...

Ah! here it is, was searching on my HD. Just copy and paste this s*** and see if that's what you're looking for:


;----- Heat Distortion Effect by Roland Ludlam ------
;----- web: <a href="http://www.sover.net/~ardeo" target="_blank">http://www.sover.net/~ardeo</a>        ------
;----- e-mail ardeo@...                  ------

;----- I'm new to blitz and coding in general  ------
;----- So forgive my messy code!  any comments ------
;----- or suggestions for optimization or      ------
;----- other solutions are welcome!            ------
;-----                                         ------
;-----                thanks!  roland          ------
;----------------------------------------------------


Graphics3D 640,480,0

SeedRnd MilliSecs()

;----- create main scene camera ------
Global cam = CreateCamera()
CameraProjMode cam,1
CameraRange cam,.01,1000
PositionEntity cam,0,10,-20

;----- create effect camera ------
Global cam2 = CreateCamera()
PositionEntity cam2,0,10,-20
CameraViewport cam2,0,0,256,256
CameraProjMode cam2,0
CameraRange cam2,.01,1000

l=CreateLight()

;----- texture globals ------
Global texmove#=0
Global angle# = 0
Global angle2# = 0
Global texscale#=.978999
Global texscaley# =1.041
Global texx#=.0109977
Global texy#=-.023003

;----- globals to control the distortion effect ------
Global distamount# = 1
Global distalpha# = 1

;----- sin or random distortion? set to 1 for sin and 0 for random ------
Global sinewave = 1



;----- create blank texture to use later ------
Global imagetex = CreateTexture(256,256,256)


;----- load up or lava textures ------
Global lavatex = LoadTexture("lava.bmp")
ScaleTexture lavatex,300,300
Global explosion = LoadTexture("lava3.tga",1)
ScaleTexture explosion,500,500


;----- initialize types: vert is for displacement / distortion ------
Type vert
	Field x#
	Field y#
	Field z#
	Field num
	Field a#
	Field distance#

End Type

Type box
	Field entity
End Type


;----- load textures onto planes (just for fun) ------
Global plane = CreatePlane()
PositionEntity plane,0,-5,0
EntityTexture plane,lavatex
EntityFX plane,1

Global plane2 = CreatePlane()
EntityBlend plane2,3
EntityTexture plane2,explosion
EntityFX plane2,1


;----- load mesh to use as distortion sprite ------
Global dist = LoadMesh("plane.x",cam2)
PositionEntity dist,0,0,.1
ScaleEntity dist,.0256,.0256,.0256
RotateEntity dist,90,0,0
EntityFX dist,1
EntityTexture dist,imagetex
Global distsurf = GetSurface(dist,1)
Global vnum = CountVertices(distsurf)

;----- scale texture to match sprite... ------
ScaleTexture imagetex,texscale,texscaley
PositionTexture imagetex,texx,texy

;----- convert vertices to types for easy access ------
For a=0 To vnum-1
	v.vert = New vert
		v\num = Int(a)
		v\x = VertexX#(distsurf,a)
		v\y = VertexY#(distsurf,a)
		v\z = VertexZ#(distsurf,a)
		v\a = Rnd(0,360)	
Next


;----- place some boxes to show off effect better ------
For i=0 To 10
	b.box = New box
	b\entity = CreateCube()
	PositionEntity b\entity,Rnd(-20,20),Rnd(0,20),Rnd(-20,20)
Next


;----- main loop ------
While Not KeyHit(1)


;----- make the boxes move ------
For b.box = Each box
	TurnEntity b\entity,1,1,1
Next 


;----- call heatdist function ------
heatdist()

;----- make the textures on the planes move ------
texturemove()


;----- keys to change the effect if you want to. ------
If KeyHit(2) Then sinewave = 1
If KeyHit(3) Then sinewave = 0
If KeyHit(4) Then sinewave = 2

If KeyDown(200) Then distamount = distamount+.025
If KeyDown(208) Then distamount = distamount-.025

If KeyDown(203) Then distalpha = distalpha-.01
If KeyDown(205) Then distalpha = distalpha+.01

If distalpha <=0 Then distalpha = 0

UpdateWorld
RenderWorld

Text 0,0,"1 / 2 toggle sine / random"
Text 0,12,"up and dn +/- distortion"
Text 0,24,"lft and rt +/- effect alpha"

Flip True
Wend


;----- heat distortion function ------
Function heatdist()

;----- first we render the screen to texture. change the alpha of dist for more / less blur ------
	EntityAlpha dist,.8*distalpha
	CameraProjMode cam,0
	CameraProjMode cam2,1
	RenderWorld
	CopyRect 0,0,256,256,0,0,BackBuffer,TextureBuffer(imagetex)


;----- then switch back to regular camera and modify vertices for distortion effect. ------
	CameraProjMode cam2,0
	CameraProjMode cam,1
	ShowEntity dist
	EntityAlpha dist,.6*distalpha
	For v.vert = Each vert
		v\a=v\a+5
		If v\a>=360 Then v\a = 0

;----- displace vertices.  use sine or straight up random distortion? ------
		If sinewave = 0 Then VertexCoords(distsurf,v\num,v\x,v\y,v\z+(Rnd(-.08*distamount,.08*distamount)))	
		If sinewave = 1 Then VertexCoords(distsurf,v\num,v\x,v\y,v\z+((Sin(v\a)/(30/distamount))))
		If sinewave = 2 Then VertexCoords(distsurf,v\num,v\x+((Sin(v\a)/(30/distamount))),v\y,v\z)
	Next

End Function

;----- moves the textures on the ground planes.  just for show. ------
Function texturemove()
	angle = angle+.5
	If angle >=360 Then angle = 0
	angle2 = angle2+.1
	If angle2 >=360 Then angle2 = 0
	PositionTexture lavatex,(Sin(angle)/5),0
	RotateTexture lavatex,angle2
	texmove = texmove+.001
	PositionTexture explosion,texmove,0
End Function

End



@Ross C: Boy you are sure advertising the hell out of fastlibs throughout the forums! are you getting something for it?...