'Stencil shadow' thread 2

Blitz3D Forums/Blitz3D Programming/'Stencil shadow' thread 2

hello!

the first stencil shw thread was allready full. so please write here now!

previous shadow thread:
http://www.blitzbasic.com/Community/posts.php?topic=62378

thank you.

Hi All

New Update for "Core" to be create volume!!!!


file: ShadowVolumes.bb
Type ETE_Mesh
	Field ent
	Field cnt_tris, tri.ETE_Triangle[ETE_MaxTriang]
End Type
Type ETE_Triangle
	Field v1.Point3D, v2.Point3D, v3.Point3D, nx#, ny#, nz#
	Field tri, ta, tb, tc
End Type
Type Point3D
	Field x#, y#, z#
End Type
Const ETE_MaxTriang = 65000
Global VolumeMesh, VolumeSurf
Dim TriangleClone.ETE_Triangle(ETE_MaxTriang)

Function InitVolumes()
For i = 0 To ETE_MaxTriang
	TriangleClone.ETE_Triangle(i) = New ETE_Triangle
	TriangleClone(i)\v1 = New Point3D
	TriangleClone(i)\v2 = New Point3D
	TriangleClone(i)\v3 = New Point3D
Next
VolumeMesh = CreateMesh()
VolumeSurf = CreateSurface(VolumeMesh)
EntityColor VolumeMesh, 255, 0, 0
EntityAlpha VolumeMesh, .5
EntityFX VolumeMesh, 17
End Function

Function FreeVolumes()
Delete Each ETE_Mesh
Delete Each ETE_Triangle
Delete Each Point3D
If VolumeMesh Then FreeEntity VolumeMesh
End Function

Function InitVolumeCaster(ent, file = -1)
Local ad1[ETE_MaxTriang], ad2[ETE_MaxTriang], ad3[ETE_MaxTriang]
copy = SingleSurfaceMesh(ent)
etem.ETE_Mesh = New ETE_Mesh
etem\ent = ent
surf = GetSurface(copy, 1)
cnt_tris = CountTriangles(surf) - 1
etem\cnt_tris = cnt_tris
For v = 0 To cnt_tris
	etem\tri[v] = New ETE_Triangle
	etet.ETE_Triangle = etem\tri[v]
	etet\v1 = New Point3D
	etet\v2 = New Point3D
	etet\v3 = New Point3D
	v1.Point3D = etet\v1
	v2.Point3D = etet\v2
	v3.Point3D = etet\v3
	vert0 = TriangleVertex(surf, v, 0)
	vert1 = TriangleVertex(surf, v, 1)
	vert2 = TriangleVertex(surf, v, 2)
	v1\x# = VertexX(surf, vert0)
	v1\y# = VertexY(surf, vert0)
	v1\z# = VertexZ(surf, vert0)
	v2\x# = VertexX(surf, vert1)
	v2\y# = VertexY(surf, vert1)
	v2\z# = VertexZ(surf, vert1)
	v3\x# = VertexX(surf, vert2)
	v3\y# = VertexY(surf, vert2)
	v3\z# = VertexZ(surf, vert2)
	e0x# = v3\x# - v2\x#
	e0y# = v3\y# - v2\y#
	e0z# = v3\z# - v2\z#
	e1x# = v2\x# - v1\x#
	e1y# = v2\y# - v1\y#
	e1z# = v2\z# - v1\z#
	etet\nx# = e0y# * e1z# - e0z# * e1y#
	etet\ny# = e0z# * e1x# - e0x# * e1z#
	etet\nz# = e0x# * e1y# - e0y# * e1x#
	etet\tri = v
	etet\ta = -1
	etet\tb = -1
	etet\tc = -1
	ad1[v] = True
	ad2[v] = True
	ad3[v] = True
Next
For a = 0 To cnt_tris
	ATriang.ETE_Triangle = etem\tri[a]
	v1 = ATriang\v1
	v2 = ATriang\v2
	v3 = ATriang\v3
	For b = a + 1 To cnt_tris
		state1 = ad1[b]
		state2 = ad2[b]
		state3 = ad3[b]
		If a <> b And (state1 Or state2 Or state3) Then
			BTriang.ETE_Triangle = etem\tri[b]
			v2A.Point3D = BTriang\v1
			v2B.Point3D = BTriang\v2
			v2C.Point3D = BTriang\v3
			If state1 Then
				If CheckLine(v1, v2A, v2, v2B) Then
					ATriang\ta = b
					BTriang\ta = a
					ad1[b] = False
					Goto SIDEA
				EndIf
			EndIf
			If state2 Then
				If CheckLine(v1, v2B, v2, v2C) Then
					ATriang\ta = b
					BTriang\tb = a
					ad2[b] = False
					Goto SIDEA
				EndIf
			EndIf
			If state3 Then
				If CheckLine(v1, v2C, v2, v2A) Then
					ATriang\ta = b
					BTriang\tc = a
					ad3[b] = False
				EndIf
			EndIf
			.SIDEA
			If state1 Then
				If CheckLine(v2, v2A, v3, v2B) Then
					ATriang\tb = b
					BTriang\ta = a
					ad1[b] = False
					Goto SIDEB
				EndIf
			EndIf
			If state2 Then
				If CheckLine(v2, v2B, v3, v2C) Then
					ATriang\tb = b
					BTriang\tb = a
					ad2[b] = False
					Goto SIDEB
				EndIf
			EndIf
			If state3 Then
				If CheckLine(v2, v2C, v3, v2A) Then
					ATriang\tb = b
					BTriang\tc = a
					ad3[b] = False
				EndIf
			EndIf
			.SIDEB
			If state1 Then
				If CheckLine(v3, v2A, v1, v2B) Then
					ATriang\tc = b
					BTriang\ta = a
					ad1[b] = False
					Goto SIDEC
				EndIf
			EndIf
			If state2 Then
				If CheckLine(v3, v2B, v1, v2C) Then
					ATriang\tc = b
					BTriang\tb = a
					ad2[b] = False
					Goto SIDEC
				EndIf
			EndIf
			If state3 Then
				If CheckLine(v3, v2C, v1, v2A) Then
					ATriang\tc = b
					BTriang\tc = a
					ad3[b] = False
				EndIf
			EndIf
			.SIDEC
		EndIf
	Next
Next
FreeEntity copy
End Function

Function LoadVolumeCaster(ent, path$, file = -1)
If file = -1 Then file = ReadFile(path$)
sm.ShadowMesh = New ShadowMesh
sm\ent = ent
sm\casting = True
etem.ETE_Mesh = New ETE_Mesh
etem\ent = sm\ent
etem\cnt_tris = ReadInt(file)
For v = 0 To etem\cnt_tris
	etem\tri[v] = New ETE_Triangle
	etet.ETE_Triangle = etem\tri[v]
	tri.ETE_Triangle = etem\tri[v]
	tri\v1 = New Point3D
	tri\v2 = New Point3D
	tri\v3 = New Point3D
	v1.Point3D = tri\v1
	v2.Point3D = tri\v2
	v3.Point3D = tri\v3
	v1\x# = ReadFloat(file)
	v1\y# = ReadFloat(file)
	v1\z# = ReadFloat(file)
	v2\x# = ReadFloat(file)
	v2\y# = ReadFloat(file)
	v2\z# = ReadFloat(file)
	v3\x# = ReadFloat(file)
	v3\y# = ReadFloat(file)
	v3\z# = ReadFloat(file)
	tri\nx# = ReadFloat(file)
	tri\ny# = ReadFloat(file)
	tri\nz# = ReadFloat(file)
	tri\tri = ReadInt(file)
	tri\ta = ReadInt(file)
	tri\tb = ReadInt(file)
	tri\tc = ReadInt(file)
Next
cnt_children = CountChildren(ent)
For i = 1 To cnt_children
	LoadVolumeCaster(GetChild(ent, i), "", file)
Next
End Function


Function CreateVolume_orig(light, parallel = False)
	;===>
	RangeLight# = 10 ; is a range light, all object over range is jump
	;===>
	light_x# = EntityX(light, True) * (1 + parallel * 1000000)
	light_y# = EntityY(light, True) * (1 + parallel * 1000000)
	light_z# = EntityZ(light, True) * (1 + parallel * 1000000)
	volume_lenght = RangeLight
	;===>
	For etem.ETE_Mesh = Each ETE_Mesh
		;===>
		cnt_tris = etem\cnt_tris
		For v = 0 To cnt_tris
			;===>
			etet.ETE_Triangle = TriangleClone(v)
			CloneTriangle(etet, etem\tri[v])
			;===>
			v1.Point3D = etet\v1
			TFormPoint v1\x#, v1\y#, v1\z#, etem\ent, 0
			v1\x# = TFormedX()
			v1\y# = TFormedY()
			v1\z# = TFormedZ()
			;===>
			TFormNormal etet\nx#, etet\ny#, etet\nz#, etem\ent, 0
			;===>
			Dot# = ((v1\x# - light_x#) * TFormedX()) + ((v1\y# - light_y#) * TFormedY()) + ((v1\z# - light_z#) * TFormedZ())
			;===>
			If Dot# < 0.0 Then
				;===>
				etet\tri = -1
				;===>
			Else
				;===>
				v2.Point3D = etet\v2
				TFormPoint v2\x#, v2\y#, v2\z#, etem\ent, 0
				v2\x# = TFormedX()
				v2\y# = TFormedY()
				v2\z# = TFormedZ()
				;===>
				v3.Point3D = etet\v3
				TFormPoint v3\x#, v3\y#, v3\z#, etem\ent, 0
				v3\x# = TFormedX()
				v3\y# = TFormedY()
				v3\z# = TFormedZ()
				;===>
			EndIf
			;===>
		Next
		;===>
		;Return
		;===>
		For v = 0 To cnt_tris
			etet = TriangleClone(v)
			If etet\tri => 0 Then
				ta = etet\ta
				tb = etet\tb
				tc = etet\tc
				If ta > -1 Then check1 = TriangleClone(ta)\tri Else check1 = -1
				If tb > -1 Then check2 = TriangleClone(tb)\tri Else check2 = -1
				If tc > -1 Then check3 = TriangleClone(tc)\tri Else check3 = -1
				If check1 < 0 Or check2 < 0 Or check3 < 0 Then
					v1 = etet\v1
					v2 = etet\v2
					v3 = etet\v3
					If check1 < 0 Then
						rax# = v1\x# + (v1\x# - light_x#) * volume_lenght
						ray# = v1\y# + (v1\y# - light_y#) * volume_lenght
						raz# = v1\z# + (v1\z# - light_z#) * volume_lenght
						rbx# = v2\x# + (v2\x# - light_x#) * volume_lenght
						rby# = v2\y# + (v2\y# - light_y#) * volume_lenght
						rbz# = v2\z# + (v2\z# - light_z#) * volume_lenght
						vert1 = AddVertex(VolumeSurf, v1\x#, v1\y#, v1\z#)
						vert2 = AddVertex(VolumeSurf, rax#, ray#, raz#)
						vert3 = AddVertex(VolumeSurf, rbx#, rby#, rbz#)
						vert4 = AddVertex(VolumeSurf, v2\x#, v2\y#, v2\z#)
						AddTriangle(VolumeSurf, vert1, vert2, vert3)
						AddTriangle(VolumeSurf, vert1, vert3, vert4)
					EndIf
					If check2 < 0 Then
						rbx# = v2\x# + (v2\x# - light_x#) * volume_lenght
						rby# = v2\y# + (v2\y# - light_y#) * volume_lenght
						rbz# = v2\z# + (v2\z# - light_z#) * volume_lenght
						rcx# = v3\x# + (v3\x# - light_x#) * volume_lenght
						rcy# = v3\y# + (v3\y# - light_y#) * volume_lenght
						rcz# = v3\z# + (v3\z# - light_z#) * volume_lenght
						vert1 = AddVertex(VolumeSurf, v2\x#, v2\y#, v2\z#)
						vert2 = AddVertex(VolumeSurf, rbx#, rby#, rbz#)
						vert3 = AddVertex(VolumeSurf, rcx#, rcy#, rcz#)
						vert4 = AddVertex(VolumeSurf, v3\x#, v3\y#, v3\z#)
						AddTriangle(VolumeSurf, vert1, vert2, vert3)
						AddTriangle(VolumeSurf, vert1, vert3, vert4)
					EndIf
					If check3 < 0 Then
						rax# = v1\x# + (v1\x# - light_x#) * volume_lenght
						ray# = v1\y# + (v1\y# - light_y#) * volume_lenght
						raz# = v1\z# + (v1\z# - light_z#) * volume_lenght
						rcx# = v3\x# + (v3\x# - light_x#) * volume_lenght
						rcy# = v3\y# + (v3\y# - light_y#) * volume_lenght
						rcz# = v3\z# + (v3\z# - light_z#) * volume_lenght
						vert1 = AddVertex(VolumeSurf, v1\x#, v1\y#, v1\z#)
						vert2 = AddVertex(VolumeSurf, rax#, ray#, raz#)
						vert3 = AddVertex(VolumeSurf, rcx#, rcy#, rcz#)
						vert4 = AddVertex(VolumeSurf, v3\x#, v3\y#, v3\z#)
						AddTriangle(VolumeSurf, vert1, vert3, vert2)
						AddTriangle(VolumeSurf, vert1, vert4, vert3)
					EndIf
				EndIf
			EndIf
		Next
	Next
End Function

Function CreateVolume(light, parallel = False); New Version 
	;===>
	RangeLight# = 10 ; is a range light, all object over range is jump
	;===>
	light_x# = EntityX(light, True) * (1 + parallel * 1000000)
	light_y# = EntityY(light, True) * (1 + parallel * 1000000)
	light_z# = EntityZ(light, True) * (1 + parallel * 1000000)
	volume_lenght = RangeLight
	;===>
	v1x# = 0 : v1y# = 0 : v1z# = 0
	v2x# = 0 : v2y# = 0 : v2z# = 0
	v3x# = 0 : v3y# = 0 : v3z# = 0
	;===>
	For etem.ETE_Mesh = Each ETE_Mesh
		;===>
		cnt_tris = etem\cnt_tris
		For v = 0 To cnt_tris
			etet.ETE_Triangle = TriangleClone(v)
			CloneTrianglePart1(etet, etem\tri[v])
			;===>
			v1.Point3D = etet\v1
			TFormPoint v1\x#, v1\y#, v1\z#, etem\ent, 0
			v1\x# = TFormedX()
			v1\y# = TFormedY()
			v1\z# = TFormedZ()
			;===>
			TFormNormal etet\nx#, etet\ny#, etet\nz#, etem\ent, 0
			;===>
			Dot# = ((v1\x# - light_x#) * TFormedX()) + ((v1\y# - light_y#) * TFormedY()) + ((v1\z# - light_z#) * TFormedZ())
			;===>
			If Dot# < 0.0 Then
				;===>
				etet\tri = -1
				;===>
			Else
				;===>
				CloneTrianglePart2(etet, etem\tri[v])
				;===>
				v2.Point3D = etet\v2
				TFormPoint v2\x#, v2\y#, v2\z#, etem\ent, 0
				v2\x# = TFormedX()
				v2\y# = TFormedY()
				v2\z# = TFormedZ()
				;===>
				v3.Point3D = etet\v3
				TFormPoint v3\x#, v3\y#, v3\z#, etem\ent, 0
				v3\x# = TFormedX()
				v3\y# = TFormedY()
				v3\z# = TFormedZ()
				;===>
			EndIf
			;===>
		Next
		;===>
;Goto Pippo
		;===>
		For v = 0 To cnt_tris
			;===>
			etet = TriangleClone(v)
			;===>
			If etet\tri => 0 Then
			
				;===>
				ta = etet\ta
					If ta > -1 Then check1 = TriangleClone(ta)\tri Else check1 = -1
				tb = etet\tb
					If tb > -1 Then check2 = TriangleClone(tb)\tri Else check2 = -1
				tc = etet\tc
					If tc > -1 Then check3 = TriangleClone(tc)\tri Else check3 = -1
				;===>
				If check1 < 0 Or check2 < 0 Or check3 < 0 Then
					;===>
					If check1 < 0 Then
						;===>
						v1x# = etet\v1\x# : v1y# = etet\v1\y# : v1z# = etet\v1\z#
						v2x# = etet\v2\x# : v2y# = etet\v2\y# : v2z# = etet\v2\z#
						;===>
						rax# = v1x# + (v1x# - light_x#) * volume_lenght
						ray# = v1y# + (v1y# - light_y#) * volume_lenght
						raz# = v1z# + (v1z# - light_z#) * volume_lenght
						rbx# = v2x# + (v2x# - light_x#) * volume_lenght
						rby# = v2y# + (v2y# - light_y#) * volume_lenght
						rbz# = v2z# + (v2z# - light_z#) * volume_lenght
						vert1 = AddVertex(VolumeSurf, v1x#, v1y#, v1z#)
						vert2 = AddVertex(VolumeSurf, rax#, ray#, raz#)
						vert3 = AddVertex(VolumeSurf, rbx#, rby#, rbz#)
						vert4 = AddVertex(VolumeSurf, v2x#, v2y#, v2z#)
						AddTriangle(VolumeSurf, vert1, vert2, vert3)
						AddTriangle(VolumeSurf, vert1, vert3, vert4)
						;===>
					EndIf
					If check2 < 0 Then
						;===>
						v2x# = etet\v2\x# : v2y# = etet\v2\y# : v2z# = etet\v2\z#
						v3x# = etet\v3\x# : v3y# = etet\v3\y# : v3z# = etet\v3\z#
						;===>
						rbx# = v2x# + (v2x# - light_x#) * volume_lenght
						rby# = v2y# + (v2y# - light_y#) * volume_lenght
						rbz# = v2z# + (v2z# - light_z#) * volume_lenght
						rcx# = v3x# + (v3x# - light_x#) * volume_lenght
						rcy# = v3y# + (v3y# - light_y#) * volume_lenght
						rcz# = v3z# + (v3z# - light_z#) * volume_lenght
						vert1 = AddVertex(VolumeSurf, v2x#, v2y#, v2z#)
						vert2 = AddVertex(VolumeSurf, rbx#, rby#, rbz#)
						vert3 = AddVertex(VolumeSurf, rcx#, rcy#, rcz#)
						vert4 = AddVertex(VolumeSurf, v3x#, v3y#, v3z#)
						AddTriangle(VolumeSurf, vert1, vert2, vert3)
						AddTriangle(VolumeSurf, vert1, vert3, vert4)
						;===>
					EndIf
					If check3 < 0 Then
						;===>
						v1x# = etet\v1\x# : v1y# = etet\v1\y# : v1z# = etet\v1\z#
						v3x# = etet\v3\x# : v3y# = etet\v3\y# : v3z# = etet\v3\z#
						;===>
						rax# = v1x# + (v1x# - light_x#) * volume_lenght
						ray# = v1y# + (v1y# - light_y#) * volume_lenght
						raz# = v1z# + (v1z# - light_z#) * volume_lenght
						rcx# = v3x# + (v3x# - light_x#) * volume_lenght
						rcy# = v3y# + (v3y# - light_y#) * volume_lenght
						rcz# = v3z# + (v3z# - light_z#) * volume_lenght
						vert1 = AddVertex(VolumeSurf, v1x#, v1y#, v1z#)
						vert2 = AddVertex(VolumeSurf, rax#, ray#, raz#)
						vert3 = AddVertex(VolumeSurf, rcx#, rcy#, rcz#)
						vert4 = AddVertex(VolumeSurf, v3x#, v3y#, v3z#)
						AddTriangle(VolumeSurf, vert1, vert3, vert2)
						AddTriangle(VolumeSurf, vert1, vert4, vert3)
						;===>
					EndIf
				EndIf
			EndIf
		Next
;.Pippo		
	Next
End Function


Function SingleSurfaceMesh(ent)
ret = CopyMesh(ent)
If CountSurfaces(ret) = 1 Then
	Return ret
Else
	FreeEntity ret
	ret = CreateMesh()
	new_surf = CreateSurface(ret)
	For s = 1 To CountSurfaces(ent)
		surf = GetSurface(ent, s)
		For t = 0 To CountTriangles(surf) - 1
			v0 = TriangleVertex(surf, t, 0)
			v1 = TriangleVertex(surf, t, 1)
			v2 = TriangleVertex(surf, t, 2)
			new_v1 = AddVertex(new_surf, VertexX(surf, v0), VertexY(surf, v0), VertexZ(surf, v0))
			new_v2 = AddVertex(new_surf, VertexX(surf, v1), VertexY(surf, v1), VertexZ(surf, v1))
			new_v3 = AddVertex(new_surf, VertexX(surf, v2), VertexY(surf, v2), VertexZ(surf, v2))
			AddTriangle new_surf, new_v1, new_v2, new_v3
		Next
	Next
	Return ret
EndIf
End Function

Function CloneTrianglePart1(dst.ETE_Triangle, src.ETE_Triangle); New Version 
dst\v1\x# = src\v1\x#
dst\v1\y# = src\v1\y#
dst\v1\z# = src\v1\z#
dst\nx# = src\nx#
dst\ny# = src\ny#
dst\nz# = src\nz#
dst\tri = src\tri
End Function

Function CloneTrianglePart2(dst.ETE_Triangle, src.ETE_Triangle); New Version 
dst\v2\x# = src\v2\x#
dst\v2\y# = src\v2\y#
dst\v2\z# = src\v2\z#
dst\v3\x# = src\v3\x#
dst\v3\y# = src\v3\y#
dst\v3\z# = src\v3\z#
dst\ta = src\ta
dst\tb = src\tb
dst\tc = src\tc
End Function

Function CloneTriangle(dst.ETE_Triangle, src.ETE_Triangle)
dst\v1\x# = src\v1\x#
dst\v1\y# = src\v1\y#
dst\v1\z# = src\v1\z#
dst\v2\x# = src\v2\x#
dst\v2\y# = src\v2\y#
dst\v2\z# = src\v2\z#
dst\v3\x# = src\v3\x#
dst\v3\y# = src\v3\y#
dst\v3\z# = src\v3\z#

dst\nx# = src\nx#
dst\ny# = src\ny#
dst\nz# = src\nz#
dst\tri = src\tri
dst\ta = src\ta
dst\tb = src\tb
dst\tc = src\tc
End Function

Function CheckLine(a1.Point3D, b1.Point3D, a2.Point3D, b2.Point3D)
c1 = (a1\x# = a2\x# And a1\y# = a2\y# And a1\z# = a2\z#)
c2 = (b1\x# = b2\x# And b1\y# = b2\y# And b1\z# = b2\z#)
c3 = (a1\x# = b2\x# And a1\y# = b2\y# And a1\z# = b2\z#)
c4 = (b1\x# = a2\x# And b1\y# = a2\y# And b1\z# = a2\z#)
If (c1 And c2) Or (c3 And c4) Then Return True Else Return False
End Function



1 modify statistic time for "Volume time"

file: SampleFunctions.bb
Include "Includes\DevilShadowSystem.bb"

Global font_height = FontHeight() + 3
Global timer = CreateTimer(60)
Global render_mode = 1
;===> New Version 
Const Mid_Const = 20
Dim Mid_Time#(Mid_Const)
Global Mid_Time_Cnt%
;===> New Version 
Function InitGraphics()
Graphics3D 1024, 768, 16, 2
SetBuffer BackBuffer()
SeedRnd MilliSecs()
End Function

Function StartProgram(center_mouse = False)
If center_mouse Then MoveMouse GraphicsWidth() / 2, GraphicsHeight() / 2
FlushMouse()
FlushKeys()
End Function

Function UpdateProgram(Cam, freelook_speed# = 0);===> New Version 

;Freelook
If freelook_speed# > 0 Then
	MoveEntity Cam, (KeyDown(32) - KeyDown(30)) * freelook_speed#, 0, (KeyDown(17) - KeyDown(31)) * freelook_speed#
	RotateEntity Cam, EntityPitch(Cam) + MouseYSpeed(), EntityYaw(Cam) - MouseXSpeed(), 0
	MoveMouse GraphicsWidth() / 2, GraphicsHeight() / 2
	HidePointer
Else
	ShowPointer
EndIf
;Render
ms = MilliSecs()
If KeyHit(2) Then render_mode = 0 ElseIf KeyHit(3) Then render_mode = 1 ElseIf KeyHit(4) Then render_mode = 2
Render(render_mode)
;Debug
Color 255, 255, 255
;===>
; Midle time
Mid_Time#(Mid_Time_Cnt) = Debug_TimeVolumesBuilt
If Mid_Time_Cnt<Mid_Const Then Mid_Time_Cnt=Mid_Time_Cnt+1 Else Mid_Time_Cnt = 0
Tim_Volume=0
For a=0 To Mid_Const-1
	Tim_Volume = Tim_Volume+Mid_Time#(a)
Next
Tim_Volume=Tim_Volume/Mid_Const
;===>

UpdateDebugBar(10, 10, 10, "FPS: " + FPS(), "Render time: " + Debug_TimeRender, "InitVolume time: " + Debug_TimeInitVolumes, "Volume time statistic: " + Tim_Volume, "Shadow Polys: " + Debug_ShadowPolys)

;UpdateDebugBar(10, 10, 10, "FPS: " + FPS(), "Render time: " + Debug_TimeRender, "InitVolume time: " + Debug_TimeInitVolumes, "Volume time: " + Debug_TimeVolumesBuilt, "Shadow Polys: " + Debug_ShadowPolys)

gw = GraphicsWidth()
gh = GraphicsHeight()
txt1$ = "Press keys 1-3 to toggle the render modes."
txt2$ = "Use A,S,W,D and the mouse to look arround."
If freelook_speed# > 0 Then
	UpdateDebugBar(240, 10, 5, txt1$, txt2$)
Else
	UpdateDebugBar(240, 10, 5, txt1$)
EndIf
WaitTimer(timer)
Flip
End Function

Function UpdateDebugBar(x, y, d, p1$, p2$ = "***", p3$ = "***", p4$ = "***", p5$ = "***")
max_params = 4
Local p$[4]
p[0] = p1$
p[1] = p2$
p[2] = p3$
p[3] = p4$
p[4] = p5$
width = 20
For i = 0 To max_params
	If p[i] <> "***" Then
		cnt_params = i
		sw = StringWidth(p[i])
		If sw > width Then width = sw
	EndIf
Next
fh = FontHeight() + 2
Color 0, 0, 0
w = width + d * 2
h = fh * (cnt_params + 1) + d * 2
Rect x, y, w, h
Color 255, 255, 255
Rect x, y, w, h, False
For i = 0 To cnt_params
	Text x + d, y + d + fh * i, p[i]
Next
End Function

Global FPS, FPS_temp, FPS_time
Function FPS()
ctime = MilliSecs()
FPS_temp = FPS_temp + 1
If ctime - FPS_time > 500 Then
	FPS = FPS_temp * 2
	FPS_temp = 0
	FPS_time = ctime
EndIf
Return FPS
End Function


Bye

What happens to the stencil shadows if you have more than one light in your scene? Does it cope okay or do the stencil shadows rely on a single light source?

when you add a seccond light, he deletes the first light.
of course it is possible to do multilights! but the only problem is, that the parts of the scene, where the both shadows should overlap, are not overlapping!

I don't think the lack of overlapping is too bad. For example, if you had two connecting rooms (both lit by a small bulb) you wouldn't mind that there wasn't a darker area in the connecting doorway or corridor. Clever asset layout would probably be recommended though. ^^

This condizion I have idea bsp for interaction ambient, the light interaction only object present in the specyfic zone.

ciao !! bye

daredevil:
when you have updated, please send them to me and dont make them public. i wanna make a release soon. and not every day an update. this confuses only!!!

!!! SPEED !!!

Optimizzation for core 20%

Devils Child pleace test all inport and export shadow

are can new update for speed

http://digidownload.libero.it/enzo_light/DSS_Release_0.7E.rar

Bye

daredevil: i said, I am oranizing the releases!!!
ARGH

Ok!!

grat news guys!!
ENBM is now supported as well!

see:


A Gaetano

Ho visto che tu sei italiano e quindi scrivo in italiano (prima e l'ultima volta, inglese e l'ufficiale qui) ma in italiano posso spiegare meglio che cosa penso di stencil shawow system.
E troppo buono quello che avete fatto. Forse il massimo in Blitz3D ma quasi sono sicuro che non si puo fare sistema di ombra rapida, veramente usabile in gioco.
Anchi'io sto facendo un giocio con Blitz ed anch'io vorrei bell ombra ma secondo me questo sistema sara sufficente per un demo scene con 2-3 lowpoly modelli ma non sara sufficente in gioco vero, purtroppo. Se per caso io sbaglio e tu fai qualcosa bella io saro molto allegro e contento ma ho paura di no.
L'ultima versione fa 15-20 fps con 2 lowpoli modelli sul mio PC (una media configurazione ) senza collision detect, senza AI, senza grosso map, senza scprit engine, senza (quasi) tutti.
Questo la mia opinione niente di piu, scusi ma non ti nascondo, ho scritto quello che ho pensato.
Tanti auguri

Ciao

Giorgio

what the hell are you talking man???
talk english please...


To Gaetano I have inasmuch as you six Italian and therefore I before write in Italian (and the last time, English and the official here) but in Italian I can explain better than what task than stencil shawow system. And too much good the one which you have made. Perhaps the maximum in Blitz3D but nearly is sure that puo not to make system of fast shadow, truly usable in game. Anchi' I am making a giocio with Raid and anch' I would want Bell second shadow but me this sufficente system sara for demo scenes with 2-3 lowpoly models but not sara sufficente in true game, unfortunately. If for case I mistake and you make something beautiful saro much allegro and content I but I have fear not. The last version makes 15-20 fps with 2 lowpoli models on my PC (one medium configuration) without collision detect, To i, large map, scprit engine, (nearly) all. This my opinion nothing of piu, excuses but I do not hide to you, I have written what I have thought. Many auguries Hello George



Above me a traslate machine result.

In english: Your shadow system is very good, really nice work but I think Blitz3D is not able, proper to make really good very fast stencil shadow what is usable in a big project. Maybe a professional C++ made
dll is usable.
I was buy Adrej's shadow system (with dll writed in c++) but very weak in game, with big map with more full animated models with mor light.
I would like to see and use a good directx based, hardwer supported stencil shadow system. I need it.
I hope you can make this but I don't believe.
Why does not make Mark Silby this kind of shadow for Blitz3D? Without help of Mark will be very hard to realization this.
This is my opinion, nothing else.
I whis good work.

The only thing I really understood...

"Why does not make Mark Silby this kind of shadow for Blitz3D?"

Good question, hehehehe.

As far as i know he does, it was seen in screenshots of Max3D work in progress, together with the physics engine etc., half a year ago or so. It's probably still in his Worklogs.

Yes, for BlitzMax3D but the old Blitz3D is not supported.
(little bugfix but nothing else)

i just tried out this shadow system. i get this message "Graphic card does not support stencil buffers." my card is ati radeon ve.

just thought i'd mention it. i can run the "swift shadow system" so i thought since this looks exactly the same, it would run too. wrong! :)

desable the line "Runtimeerror "Graphic card..." and test it. if it works, ok. otherwise your graphic card is to old...

the "swifty demo" looks like the swift shadow system, but it is using MY system!

btw: this shadow system works differentey of sswifts one!



stencil shadows
(+) fast, robust, self shadowing
(-) angular, problems with animations, needs graphic cards > gforce2, very complex!

texture shadow system
(+) smooth, animations are working without extra coding, no high end graphic card required
(-) slow, no self shadowing, easier to make

well yes it runs, but there are no shadows!

guess i need to upgrade.

update graphic card drivers! reboot pc and try it again...

when there are no shadows, press key "2" to activate shadow mode, if you have unfortiunaly pressed key "1" for no-sahdow-mode ;)
cya

"easier to make"

I beg to differ! Stencil shadows do not require complicated projections and polygon clipping! You just extrude a volume along a line etending from the light source! Much simpler math! :-)

great news guys!!!

the camera can now get inside the shadow volumes as well :)
but the only problem is that the rendering of the shadows is very costly since now!

see:


i will release the next version in a week :)
cya!

hi Mike0101

my name Vincenzo Caldarulo, Gaetano in may friend good friend :)

The shadow system ops!! DSS is a system for game non only demo, the optimization code are a process for all function or core.

blitz have a limitation for pointer structure this is a problem, but the beautiful one is to exceed the limits.

I'm programmer C++ ex programmer professional the gamer :)

------------------------------------------------------------

for Devils Child

Good work! send me the version ;)

I believe there am of the BUG in the tails, to level of management.
and creed of being able to resolve them but if job on this my version
lì we will increase.



Bye

Scusi per il nome, da oggi Vincenzo. Va bene?
A working stencil shadow system is my dream.
I wrote my doubt only but I hope you will clear my doubt.

thnx

====================
===== DSS 0.9 Beta =====
====================


As i promissed, i will release the 0.9beta now!

here you go guys!
http://xware.chat-blitz.de/scripts/upload/DSS_Release_0.9b.zip
http://xware.chat-blitz.de/scripts/upload/DSS_Release_0.9b_EXE_Only.zip
This is almost final. there won't be great changes.

and don't forgett to update the userlibs!

have fun :)
of course you can use this in your game for free. but don't forget the credits ;)


cya!

Orca Leppa! Wow! many thanks!!!

best work!!!

mongia2

thx guys :)
hope you find some use in it!

All the shadow demo's say my card does not support bumpmapping but I'm almost certain is does?!

Sure, a gfx440mx is old ( which I'm keeping for compatibility ) but so is bumpmapping! It supports stencils fine.

Any ideas what's going on?

first at all, update your graph. card drivers and reboot :)
if this doesnt work, just disable the "runtimeerror" command(but not the whole line)!

hope it helps... i got this problem from 3 users and i dont know why... perhabs tom knows why, he made the dll :)

cya

I try launch bb code but return thi error ... function "bb_getcamerangestart" not found

@ Devils ... I can't imagine updating my drivers will make a bit of difference as they're pretty up to date anyway. Any other bumpmapping and stencil systems I've tried work fine on my system, including previous version of yours and Tom's.

I really wanted to check the speed of the system on this rig before I started playing around with it.

Looks sweet mind you.

Stevie

@sideextreme: have you put the userlib-decls-files into your userlib dir?

@devils child: greate work! i've been playing around with it in order to enable soft self shadowing and colored lights casting not colored shadows... i thought it would work, if i didn't draw the shadow plane but instead drew the whole scene with disabled lights (of course still using the stencil). and it worked (though the selfshadowing is often not really soft.. ill have to do some more work on this ^^). but somehow i've messed up something with the zbuffer. it works and the shadows as well as the scene are drawn quite properly, but some regions aren't zsortet the way they should. any suggestions?



you can see that in the center there are some zglitches.. unfortunately im not too familiar with all these directx render modes, that you're using. any ideas?

in userlibs folder i see 3 file

-Devilshadowsystem.decls

-Devilshadowsystem.b3d

-Devilshadowsistem_DX7.dll

I need some more file?

sideExtreme: you need to update the dlls in your userlib folder. delete my dlls in your blitz userlib dir and put in the new ones.

inarie: i am trying to make soft self shadowing, but i had no success yet. but i will try harder on it :)

also, i am very happy with our current result!
cya

your code is very very! good!

thanks for shadows b3d!


there are some bug in create mesh.shw
in my model

thanks

hi Devils Child

pleace enable line 3d for debug silouette ;)


whats function contain "DevilShadowSystem_B3D.dll" if is code c++ pleace post a my email the code for optimization.

Spot:

DDS... the new style shodow

Bye ;)

devilshadowsystem_b3d.dll is a dll which has functions like GetEntityRed() or GetCamRangeStart()
also there is no need to optimaze the dlls. and i dont even have any c++ source code!

@ianrie: i don't know what you are doing there. please send me the source of that, and i will implement soft self shadowing :)

I study the system for optimize speed silhouette.

step by step go to piramid

Bye

Wait ... wait .. wait

The my optimization what is ?

a new optimizzation?

is very very low speed, ok ... ok ... I optimized all

davedevil:

some thing left to do for you is to update your signature!

Software-Renderer Shadow Volume: www.blitzbasic.com/Community/posts.php?topic=58767


just put there the link to my worklog!!

Hm. Please add multipass buffer (hardware isnt possible with dx7) and so are smooth shadows possible

no, i tried this a certain time ago and it is not possible.
also it would bu such a slowdown!!

i checked out soft self shadowing. inarie gave me the hot tip for rendering the ambient noise only instead of the whoule scene in dark! so i got soft self shadows. but somehow they are not working. see the lila pic above^^

tom: have you got any idea??

edit: here is a screenshot


but there are still some problems!

I can't use the 0.9b demos on my Intel Extreme laptop because it moans about the hard not being able to do bump mapping, even on the demos without it.

he is initialzing bump mapping on the beginning of the program in the case of you would use it at the and...

try to disable the runtimeerror command and tell me what happens.
if the dx7_... commands will cause MAV, your graphics cars is to old!
cya

I devil

i have a question for you:

what is a function for copy list vertex shadow? (ex function copy vertex)
what's name have?

you copy all vertex preview create shadow

pleace this information are muth more important for result the optimizzation.

Ciao

talk english, and then i will explain you

classic.

I have resolved the question

the new system is not optimizzation

I return old version

excused for the my English not corrected

bye ;)

This should work fine with JV-ODE wrapper, right?

Great job :D

yes, of corse :)
the executable to the screenshot below is in the new 0.9beta delivered with.


hello everybody!

if you want to work with this shadow system easier, here is my new user interface:
Function CreateShadowCube(casting = True, path$ = "***")
c = CreateCube()
SetShadowMesh(c, casting, path$)
Return c
End Function

Function CreateShadowSphere(seg = 8, casting = True, path$ = "***")
c = CreateSphere(seg)
SetShadowMesh(c, casting, path$)
Return c
End Function

Function CreateShadowCylinder(seg = 8, casting = True, path$ = "***")
c = CreateCylinder(seg)
SetShadowMesh(c, casting, path$)
Return c
End Function

Function CreateShadowCone(seg = 8, casting = True, path$ = "***")
c = CreateCone(seg)
SetShadowMesh(c, casting, path$)
Return c
End Function

Function LoadShadowMesh(mesh_path$, casting = True, path$ = "***")
c = LoadMesh(mesh_path$)
SetShadowMesh(c, casting, path$)
Return c
End Function

Function LoadAnimShadowMesh(mesh_path$, casting = True, path$ = "***")
c = LoadAnimMesh(mesh_path$)
SetShadowMesh(c, casting, path$)
Return c
End Function

Function CreateShadowLight(typ = 1, parallel = False)
c = CreateLight(typ)
SetShadowLight(c, parallel)
Return c
End Function


these are functions which makes it easier to habdle the shadow system

instad of
c = createcube()
setshadowmesh c

you can now use:
c = createshadowcube()


cya!

Does the 0.9b system include the new soft self shadow system? I have an idea for a small project that could use this shadow system but I want to be sure the self shadowing problem isn't present. Keep up the good work guys! ^_^

Great stuff! How's the water coming along?

thx :)
dock: the soft self shadowing isn't improved yet. and also i don't know if and when it will. but belive me, this is the best shadow system you can get for free!

markd: the water sys is alrealy finished, but i have some problems, when setting a camera's viewport. it looks like one of the old stencil demos by tom on ATIs...

cu

Hi Devil
I have optimized DSS version 7.b obtain 260% over limit the your new version .9x

:D


bye

send me the new version!
edit: but DON'T publish it now!

please send it to me, daredevil!

i got an idea:
the "Blitz3D C++ geometry code" threas is standing above all other threads. also the jv-ode and the tokamak thread are standing above all others. can any moderator make this shdaow thread stand above, please?

I have not understood
you can write easier for me

Bye ( Ciao )

You mean make it a sticky? Completely agree.

he said: ha detto gli trasmette la nuova versione e non la pubblica

he also said: inoltre ha detto rendere a questo filetto un filetto appiccicoso

Translation mode on
Spediscigli via email la nuova versione, e pensa che sia utile rendere questo thread 'fisso' come "Blitz3D C++ geometry code" e altri...

hey everybody!
i have just improved soft self shadowing (thx to inaries help)


and now, let's make this thread and the follwoing shadow threads sticky!!

can't wait to get the new version...

Yeah, this really is great :)

i will release the final version in approx. a month.
the version will be 1.0 but maybee there will come a 1.1 version if we optimaze it.
cu

tom, i have got a querstion to you:
you are the develpoer of the dx7 dll. and to enable soft shadows. we need to blur the stencil mask. with a 1 bit stencil buffer it is not possible. but with 8 bits it is. is it possible to do that?

This system is very-very good work but the animated b3d part has many bugs
This is (would be) the most important part of the shadowsystem because b3d is the native file of Blitz3d and this is a shadowsystem dedicated to Blitz3D.
I can't waiting the new bugfree release, I need it:)

well, i guess, there won't be any support for b3d animations at all :/
i restricted the b3d animations from the new release, because it is to buggy and i can't fix it!

i will release the final one next week :)

~CLOSED~

please go on here:
http://www.blitzbasic.com/Community/posts.php?topic=63491

@moderators: close this thread please!