Realtime Stencil Shadow Effect

Blitz3D Forums/Blitz3D Programming/Realtime Stencil Shadow Effect

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.

Totally faked shadow effect. I was working on a routine for a demo to test some routines and it didn't work out - but still looks coolish. ;) LEFT and RIGHT arrows move the "light".

	Graphics3D 800,600
	camera=CreateCamera()
	PositionEntity camera,0,2,0
	
	sphere=CreateSphere(64)		;add the shapes in here
	PositionEntity sphere,0,2,10
	cone=CreateCone(32)
	PositionEntity cone,0,3,10
	ScaleEntity cone,1,2,1

	light=CreateLight(2)
	LightConeAngles light,1,90
	PositionEntity light,0,6,10
	plane=CreatePlane()
	EntityFX plane,1
	PositionEntity plane,0,-5,0
	shadowcube=CreateCube()
	ScaleEntity shadowcube,10,.01,10
	PositionEntity shadowcube,0,-2,10
	shadowtex=CreateTexture(128,128)
	EntityTexture shadowcube,shadowtex
	lightsphere=CreateSphere(8,light)
	ScaleEntity lightsphere,.1,.1,.1
	EntityFX lightsphere,1
	camera2=CreateCamera(light)
	CameraViewport camera2,0,0,128,128
	CameraRange camera2,.1,100
	PointEntity camera2,sphere
	HideEntity camera
	shadowimage=CreateImage(128,128)
	SetBuffer BackBuffer()
	While Not KeyHit(1)
		HideEntity lightsphere
		HideEntity shadowcube
		HideEntity camera
		HideEntity plane
		ShowEntity camera2
		If EntityX(light) > 0 Then TurnEntity camera2,0,0,-90 Else TurnEntity camera2,0,0,90
			;main camera doesn't move, so i cheat and just use 0 as the reference
			;rather than figuring out position relative to camera
		CameraClsColor camera2,255,255,255
		AmbientLight 50,50,50
		LightColor light,0,0,0
		UpdateWorld
		RenderWorld
		GrabImage shadowimage,0,0
		MaskImage shadowimage,255,0,255
		ShowEntity shadowcube
		ShowEntity lightsphere
		HideEntity camera2
		ShowEntity camera
		ShowEntity plane
		CameraClsColor camera,0,0,0
		LightColor light,255,255,255
		SetBuffer TextureBuffer(shadowtex)
			Cls
			DrawImage shadowimage,0,0
			SetBuffer BackBuffer()
		PositionEntity shadowcube,-EntityX(light),-2,10
		PointEntity camera2,sphere
		UpdateWorld
		RenderWorld
		Flip
		If KeyDown(203) And EntityX(light)>-9 Then TranslateEntity light,-.1,0,0
		If KeyDown(205) And EntityX(light)<9 Then TranslateEntity light,.1,0,0
		Wend
	End


+BlackD

ps. Yes, I know your projectors are better halo.. but I suck at 3D. :P