decal lighting in blitz3d

Miscellaneous Forums/Blitz Showcase/decal lighting in blitz3d

hmmm.... I'm not sure if this is going to work... I'd put up a link, but I have nowhere to upload it!
Oh well... I'll post the code.

;"subtracting from the lightmap"
;-Kevin Laherty 2007.

;I imagine this may cause a bit of a slow down with
;High polygon maps since it renders 3 times...
;But c'mon, it's a nice effect, isn't it?

Graphics3D 800,600

Const map_c=1
Const ent_c=2
Collisions ent_c,map_c,2,2

Const fps=60  

Global light_tex = LoadTexture("lt1.bmp",16+32)

map_name$="map2.b3d"
map1=LoadMesh(map_name$)
map1p5=LoadMesh(map_name$) ;<<<lights?

map2=LoadMesh(map_name$)
EntityBlend map1,2
EntityFX map1,1
EntityFX map1p5,1
EntityFX map2,1

EntityType map1,map_c

EntityTexture map1p5,light_tex

;setting up the camera
Global camera=CreateCamera()
PositionEntity camera,0,11,-3
EntityRadius camera,1.5,2
EntityType camera,ent_c
CameraClsMode camera,0,1

;the light source for our little scene:
period=1000/FPS
time=MilliSecs()-period

color_surfaces(map1,1)
color_surfaces(map2,0)
color_surfaces(map1p5,0)
color_surfaces(map1p5,1)


;-------------------------------------------------------------------Main loop
While Not KeyHit(1)
;==========================the mainloop (fps reasons)========
	Repeat
		elapsed=MilliSecs()-time
	Until elapsed
	ticks=elapsed/period
	tween#=Float(elapsed Mod period)/Float(period)
	For k=1 To ticks
		time=time+period
		If k=ticks Then CaptureWorld
		;basic game tasks
		updatecamera()
		UpdateWorld()
	Next

CameraClsMode camera,1,1
ShowEntity map2
HideEntity map1
	RenderWorld

CameraClsMode camera,0,0
ShowEntity map1p5
HideEntity map2
	RenderWorld


CameraClsMode camera,0,0
ShowEntity map1
HideEntity map2
HideEntity map1p5

 shadow_test(camera,map1p5)

	RenderWorld

;===========================================================	
Text 50,50, EntityX(camera) +" "+ EntityY(camera) + " " + EntityZ(camera)
Flip
Wend
End
;-------------------------------------------------------------------end of main loop

Function updatecamera()
TranslateEntity camera,0,-1,0
If KeyDown(200) Then MoveEntity camera,0,0,.5
If KeyDown(203) Then TurnEntity camera,0,1,0
If KeyDown(205) Then TurnEntity camera,0,-1,0
If KeyDown(208) Then MoveEntity camera,0,0,-.5
If KeyDown(30) Then TurnEntity camera,1,0,0
If KeyDown(44) Then TurnEntity camera,-1,0,0
If EntityPitch(camera)>20 Then RotateEntity camera,20,EntityYaw(camera),0
If EntityPitch(camera)<-20 Then RotateEntity camera,-20,EntityYaw(camera),0
RotateEntity camera,EntityPitch(camera),EntityYaw(camera),0
End Function

Function color_surfaces(entity,sur)

For a = 1 To CountSurfaces(entity)
surf=GetSurface(entity,a)
brush=GetSurfaceBrush(surf)
texture=GetBrushTexture(brush,sur)
BrushTexture brush,texture,1,sur: PaintSurface surf,brush
Next

End Function


Function shadow_test(s_camera,s_receiver)

For s=1 To CountSurfaces(s_receiver) 
	surf=GetSurface(s_receiver,s) 
	For v=0 To CountVertices(surf)-1 
		TFormPoint VertexX(surf,v),VertexY(surf,v),VertexZ(surf,v),s_receiver,s_camera

		VertexTexCoords surf,v,(TFormedX()/5)+0.5,1-((TFormedY()/5)+.5) 
	Next 
Next 
TextureBlend light_tex,5
EntityBlend s_receiver,3
End Function


now here's the cunundrem... you'll need a lightmapped *.b3d map exported from maplet.... a flashlight texture (just like the one fredborg used in his spotlight demo! http://www.blitzbasic.com/codearcs/codearcs.php?code=1000 )

(erm... hope that use of linking is ok...)
and I think that's all you really need... Though I imagine the fact I put the camera at an odd position just for my map will cause a conundrum.... just relocate it :)
I hope it works...
It's basic concept works off 3 layers...
first only the lightmap is rendered...
then the decal lights (in this case a single flashlight)
then finally the wall textures are rendered on... this third layer uses entityblend 2.
I have to say thankyou to Leadwerks (Josh) because a few years ago I Emailed him about this and he pretty much told me to do this... but at the time I didn't know much about Z buffers... then when I finnished this and looked at it I finally figured out what he was talking about, so: Thankyou very much indeed.

The controls are left, right, up, down and escape.
Best of luck.

I wish B3d files could support a 3rd UV set...

Is it possible now we have DXTC, that 3 or even up to 8 UV sets could be allowed? Then again, asking for stuff like this seems rude if it's not used - as seems to be the case with the addition of DXTC...?

Just render the light in an additive pass with the texture and the decal, no lightmap. I did this a long time ago in Blitz3D, and it worked great. I stored an extra copy of each face in the scene, and calculated the texcoords every frame.

sonic - I use DXT a lot. It is of course a simple and powerfull addition to all tools that are written in blitz3D and only need to be recompiled. </offtopic>