really simple fake shadows?

Blitz3D Forums/Blitz3D Beginners Area/really simple fake shadows?

Pete Carter(Posted 2007) [#1]
Ive been using Sswifts shadow system for years and its great. but its not suited to my current project, which is a over track view racing game with up to 6 players on split screen. I have been getting alot of slow down because of the realtime shadow being cast by all the cars. I dont need real shadows there to small to really tell.

How do i go about making a blob shadow ive made a alpha texture that fits nicely under the car and looks like a shadow but how do i make it follow the shape of the track mesh? do i use project how fast is this?


stayne(Posted 2007) [#2]
Yep, use a texture for your shadow. Good example here:

http://www.blitzbasic.com/codearcs/codearcs.php?code=384

Also plenty more simple shadow examples in the archives :).


Ross C(Posted 2007) [#3]
Copy the mesh, colour it black and flaten it :o) Parent it to the car and tada! Or use the blob method :o)


Pete Carter(Posted 2007) [#4]
Stayne: so the above code draws the shadow shape to a texture thats apply to the mesh. and the shadow res is just how bit the shadow texture is.

ok its not how i thought it would work. but it should work.

is there any other ways?


stayne(Posted 2007) [#5]
As an alternative you could create your own simple square mesh in wings3d, blender or whatever modeling app you like, UV map it and apply the texture to that.

You said your game is a top-down view... if the camera is looking straight down at the cars then I wouldn't be too concerned with conforming the shadow to the road unless you're doing jumps, crashing and flipping over, etc?


Pete Carter(Posted 2007) [#6]
jumps, crashing and flipping over, etc

yes all of those im using Jv-ode and its from a 45 degree angle so the shadows would need to conform.


stayne(Posted 2007) [#7]
Yep, then I would just make the track pickable, do a linepick down and position your textured shadow mesh at that location.


IPete2(Posted 2007) [#8]
there is a bit of code called "Flex shadows" in the code archives... look there

Alternatively if you are experienceing slow down with Swifts system, it is possibly to do with the number of polygons in the track which you are testing for and if the cars are high poly this will also cause slowdown if you have a few of them.

So one option is to break the track down into small sections and only test the road surfaces which could be affected by shadows. This means deleting the receiver on the fly and creating a new receiver for the next bit of track needed to receive shadows, but it is super fast and quite possible (I just did the same in my project). I managed it so that the last two parts of my world affected by shadows would be remembered so I could turn my character back and cross a shadow boundary without noticing too much.

Shawn implemented a really great feature which you can utilise and make life a lot easier, as the cars are not animated (or even if they are) can you make a reduced polygon version of them? If so you could be laughing, as Shawn allows you to hide a mesh which is parented to an object and cast a shadow from this lower polygon version, meaning the calculations are drastically reduced. I am not sure where this is documented, but during a recent project I asked for help and asked why the shadow system detects meshes parented to my main mesh, yet hidden, that was the reason. Low poly animated characters can be hidden and parented and used as the shadow casters for more complex animated characters. You could even create a very low polygon sphere and cast that as a simple shadow for you cars, meaning you dont have to do too much re-coding or new coding to see if it works - Sweet!

Hope this is useful.

IPete2.


Pete Carter(Posted 2007) [#9]
IPete2 : I was wondering about that so if i lower the polycount of the track and use low poly dumby car models it should improve permormance enough. ill do some tests.


IPete2(Posted 2007) [#10]
Pete

Yeah only test the actual surface the vehicles may drive on - Since you read my post I have added some more information so please re read it again
as theres something really good in there at the end .

The on the fly receiver deletion and creation is a really great way to go btw as it means you can keep the surface checking down to just where the cars are, not the entire track.


IPete2.


puki(Posted 2007) [#11]
Out of interest - what version of "sswifty's" Shadow System does everyone have?

My last version I got from him is v115 (26/10/04).


Pete Carter(Posted 2007) [#12]
puki: v120

IPete2: ive split the track mesh into 2 so that just the bit of the track i need to be tested is tested and ive made a low poly dummy of the car mesh and it runs alot better, its still not super smooth though im not running a lo end system so it making me think i should have basic shadow option so that the user can select basic shadows if there systems not up to the real time ones.

As for your surgestion of deleting receivers on the fly I havent a clue how id do it because i have 1 light and 4 cars with shadows and they can be spread out at any distance around the track, how do you go about tracking which sections to delete and which to activate?

thanks for your help :O)

Pete


IPete2(Posted 2007) [#13]
Pete I have just read your request - can I give you some info later today ? I have to go to work in Manchester today I'll be back in 9 hours - then I shall give you the process I went through it is easy so don't worry. It will mean you need to identify which part of the track your cars are on - I use Meshesintersect or collision detection for this - having broken the floor of my levels down into 5 sections in each level. Be back later today

IPete2.


Pete Carter(Posted 2007) [#14]
Thats IPete2: No problem, I too have got work today. I work as front of house for my local live music venue. I wont be back until after the last band has played and we've packed away all the mics etc so quite late.

thanks again for your help.


Dreamora(Posted 2007) [#15]
whats actually preventing you from using sswifts texture shadow casting instead of real shadow? the system already offers that feature (beside realtime and static shadow casting)


IPete2(Posted 2007) [#16]
Pete,

(1) I broke my level into small sections

- I would suggest you do the same and ensure the sections where the cars can cast shadows (the track and tracksides) are broken down into low polygon sections - the less polygons the better, certainly not thousands in each section as a rough guide. This will also depend upon the power of the users pc's minimum spec you are aiming for I guess.

I load these in, and then set up a type so that I know where my character's camera is - you too may only need to show shadows around your main cars camera - as follows:

Path000 would be your staring grid
Path001 would be the next bit of track afterwards.
Path002 would be the third section of track the cars will come to

Part 1 of my set up is something like this
Type LevelShadow
	Field entity
	Field On
End Type

b.LevelShadow = New LevelShadow
b\entity = path000
b\on = 1 ; the shadow receiver for this section of track is set to on - it will dsiplay a shadow

b.LevelShadow = New LevelShadow
b\entity = path001
b\on = 2 ; the shadow receiver for this section of track is set to on - it will display a shadow 
;the '2' part of this is so I can have a previous piece of path with a shadow still able to fall on it if I go back - retracing my steps - you won't need this I don't think.


b.LevelShadow = New LevelShadow
b\entity = path002
b\on = 0 ; the shadow receiver for this section of track is switched off - it wont display a shadow



(2) I switch the shadow receviers on if they are ready to be turned on:

Part 2 of my set up is something like this
;switch shadows to be received if they are set ON=True/1

For b.Levelshadow = Each LevelShadow
	If b\on= 1 
		Receive_Shadow(b\entity) ; If not already shadow receiver then - make this entity a receiver	
	End If
Next




(3) Then I check for the character (this will be each of your cars I guess) to see if he is stood on any particular part of the track, and if so which part.


Now in my main loop I monitor which area my character is stood on it, and turn it on so it can receive a shadow.

; Now in the main loop,  use something like this routine - entHit has the name of the section of my level the character is stood on
; defind by 

entHit = EntityCollided(playerentityname,ground_collision_type) 

If entHit <> oldenthit Then 
; don't keep setting the same receivers or it will grind to a halt
; Oldhit contains the entity of the path the character is stood on 	
	
		
		For b.Levelshadow = Each LevelShadow
			
			
			If (b\on=1) And (entHit <> oldenthit)
				delete_shadow_receiver(b\entity)	
				b\on=0
			End If
			
			
			If (b\on >0) And (entHit <> oldenthit) 
				b\on=b\on-1
			End If
			
			
			If b\on= 0 And entHit = b\entity Then 
				Receive_Shadow(entHit) ; If not already shadow receiver then - make this entity a receiver	
				oldenthit=entHit 
				b\on= 2
				
			End If
			
		Next
		
		oldenthit=entHit
		
		
	
	End If
	


You may have to do this for all your cars so it would be best to set up a function with this last bit in it and send each entHit after each car is tested for what is under it.

What should happen is only those sections which your cars touch will have shadows receivers on them, this means that you will be testing a very much smaller section of your track every loop, so you should see a huge jump in fps - er I hope! lol.

Let me know how you get on. Email me or msn me(peter@...) or skype me (petermcaddock) if you want to chat live.

Best regards,

IPete2.


Pete Carter(Posted 2007) [#17]
IPete: great stuff ill take a close look at this in the morning and let you know how i get on. thanks for your help. Ill email you, i must sort out skype at some point.

Dreamora: i forgot it even had that function. its been along time since ive used it. thanks for pointing that out. ive desided to have both a projected texture type shadow for the low spec system setup and the real shadows for the higher spec setup, but i will still try to add IPete's system because it should make it so more people can enjoy the detail shadow setup.