Dynamic Shadow Problems

Blitz3D Forums/Blitz3D Programming/Dynamic Shadow Problems

NTense(Posted 2003) [#1]
I'm trying to use a variation of the Dynamic Shadow code from jfk. I have created a mesh grid to map the shadow to using the following code :

Function CreateShadowGrid(Player.T_Player)
	
	Player\ShadowHandle = CreateMesh()
	Player\ShadowSurf = CreateSurface(Player\ShadowHandle)

	Player\TotalVerts = Player\ShadowGridSize ^ 2
	
	; Builds Vertex Grid and sets UV coordinates
	For z# = 0 To Player\ShadowGridSize-1
		For x# = 0 To Player\ShadowGridSize-1
			AddVertex(Player\ShadowSurf, x#, 0, z#, x#/(Player\ShadowGridSize-1), z#/(Player\ShadowGridSize-1))			
		Next
	Next	

	For z# = 0 To Player\ShadowGridSize - 2
		For x# = 0 To Player\ShadowGridSize - 2
			v1# = (Player\ShadowGridSize * z#) + x#
			v2# = v1# + 1
			v3# = v1# + Player\ShadowGridSize
			v4# = v3# + 1
			
			AddTriangle(Player\ShadowSurf, v1#, v2#, v3#)
			AddTriangle(Player\ShadowSurf, v2#, v4#, v3#)
		Next
	Next
	
	UpdateNormals Player\ShadowHandle
	
	RotateMesh Player\ShadowHandle, 0,0,180
	
End Function


I have a pickable terrain (currently the only pickable object other than bullets) held in the type 'Terrain\ObjectHandle'. I set the pickmode to 2 (polygon). Then, in the game loop I'm calling the InTouch function for each "Shadow" in view/range to update the vertices height using the following code:

Function Intouch(Player.T_Player)

	For count = 0 To Player\totalVerts-1
		vx# = VertexX(Player\Shadowsurf,count)
		vz# = VertexZ(Player\Shadowsurf,count)
		
		picker = LinePick(vx#, 500, vz#, 0, -1000, 0, .01)
		
		If picker<>0 Then 
			vy# = PickedY#()+0.1
		Else 
			Stop
		EndIf
		
		VertexCoords Player\Shadowsurf, count, vx#, vy#, vz#
	Next
	
	UpdateNormals Player\ShadowHandle
	
End Function


The thing is that the towel mesh doesn't change. It remains flat as you can see in the screenshots.. The white plane below the player is the towel mesh:

Screenshot 1
Screenshot 2
Screenshot 3

Can anyone help me with this? I can't figure out why the verts aren't changeing height. BTW: The grid in this example is 10x10.


jfk EO-11110(Posted 2003) [#2]
real tricky thing. maybe try:

picker = LinePick(vx#, 500, vz#, 0, 1000, 0, .01)


NTense(Posted 2003) [#3]
Well, I tried that, and it didn't work. It didn't hit anything via the stop I placed in the 'Intouch' function. So that tells me that with -1000, it's atleast hitting the ground. I'm just not getting the translation of the ground coordinates to the vertices somehow.


Jeremy Alessi(Posted 2003) [#4]
Perhaps there is an issue of local or global space between the verts?

Other than that what you're doing may not be possible as Sswift's shadow system doesn't work on a Blitz terrain for some reason. It uses shadow meshes which are created by aligning their verts to the receiving surface similar to your shadowmesh.

He can probably tell you why it won't work, although your system maybe different.


jfk EO-11110(Posted 2003) [#5]
oh yeah, wouldn't you have to use tformpoint or something?


NTense(Posted 2003) [#6]
Hmm.. I've tried 3 different implementations of Tformpoint & Tformvertex.. (I used Rob's Flex shadow prog as a reference.) Still no good.. This is really confusing.


jfk EO-11110(Posted 2003) [#7]
I suggest to position some red little cubes at the Positions you get with VertexX aso., the you will see, what's wrong. Well, I hope so.


NTense(Posted 2003) [#8]
Well, I'm almost there. The ShadowMesh is at least deforming now. Problem is now it's lifting exponentially higher as TerrainY value increases. The Shadowmesh ends up lifting over my player's head as I go over hills.

Here's the revised code for adjusting the verts:

	count = 0
	For z# = 0 To Player\ShadowGridSize - 1 ;Step 0.5
	
		For x# = 0 To Player\ShadowGridSize - 1 ;Step 0.5
		
			vx# = EntityX(Player\Ostrich\ObjectHandle,1) - MeshWidth(Player\ShadowHandle)/2 + x#
			vz# = EntityZ(Player\Ostrich\ObjectHandle,1) - MeshDepth(Player\ShadowHandle)/2 + z#				
			vy# = TerrainY(Terrain\ObjectHandle, vx#,1,vz#)
			
			VertexCoords Player\Shadowsurf,count, VertexX(Player\Shadowsurf, count), vy#, VertexZ(Player\Shadowsurf, count)
			
			count = count + 1
		Next
	
	Next
	
	UpdateNormals Player\ShadowHandle	


and here's the code for where I place my ShadowMesh under the player:

; Handle Shadow
			If Player\Loc = 1 Then Intouch(Player)

; Centers the ShadowMesh under the player
			
			PositionEntity Player\ShadowHandle, Player\Ostrich\xPosition# - MeshWidth(Player\ShadowHandle)/2, TerrainY(Terrain\ObjectHandle, Player\Ostrich\xPosition#, 1, Player\Ostrich\zPosition#)+ 0.1, Player\Ostrich\zPosition#-MeshDepth(Player\ShadowHandle)/2
			


Any Ideas?


NTense(Posted 2003) [#9]
AH HAH !!! Figured it out!!! When I position the ShadowMesh in the main loop, I have to Position it at a constant Y Value. Then the mesh deformation acts accordingly!


jfk EO-11110(Posted 2003) [#10]
Concrats! Post a screenie, must look nice.


NTense(Posted 2003) [#11]
I've just got the flex working. Still got to get the texture generated..


jfk EO-11110(Posted 2003) [#12]
Ah, ok. Maybe most important: keep a list of all Objects in Memory, it will make it easy to hide them while rendering the Shadow.