can this be done faster?

Blitz3D Forums/Blitz3D Programming/can this be done faster?

Pongo(Posted 2004) [#1]
Looking if there is a faster way to do this,... places a single pixel on my ground texture map at each wheel position. Trying to create skidmarks on my ground texture map for a racing game.

Edit: code removed,... see updated version below.


Jeremy Alessi(Posted 2004) [#2]
Not sure ... I was about to add this to Leadfoot GT. However I was thinking of using dynamic mesh creation instead of writing to a texture. But there's a decent texture painting program in the archives.


skidracer(Posted 2004) [#3]
I would use setbuffer texturebuffer(tracktex) for minimal speed up (save 3 calls to the texturebuffer() function) and use a tile map of small textures for a big speed up.


Pongo(Posted 2004) [#4]
I should also add that I'm doing things a little different from the simplified example above. I'm actually getting the position using entityX and EntityZ for each of the tires,... is there a chance this is where things are bogging down, or is it more likely that I am trying to write to too large of a texture? (1024x1024)


MadJack(Posted 2004) [#5]
I've been thinking about this for my tank game (Tank Universal). I've been wondering if a particle fx might even do it - place an emitter at the point of contact with the terrain and turn the emitter on/off with the particles set flush to the terrain.


Pongo(Posted 2004) [#6]
I really want this to work as a texture if at all possible, so that once a skid is put down, it is there forever, and does not require any further overhead.

That is my main problem with mesh creation methods to do this,... and I *thought* it would be easy to write just a few pixels to the texture without really slowing things down. In my tests, the framerate is still pretty good, but the fact that I can see it take a small hit when the skids are being drawn concerns me, especially at this early stage. Maybe I'll try to make a working sample and see if anyone has a better idea for me to try.


MadJack(Posted 2004) [#7]
sounds like a mesh creation system is the way to go then - although you'll need to keep a record of entities so that you can limit their number.

Ahem, if you do get something up and running you might like to post a code snippet?


jfk EO-11110(Posted 2004) [#8]
Just a sidenote: writing to a texture may be much faster when you use Flag 256 when creating/loading the texture.


Jeremy Alessi(Posted 2004) [#9]
I'm experimenting with both ... I think I'll end up using dynamic mesh creation. I'm using particles right now ... and they look decent but dynamic mesh creation would add that perfect smoothness.


Pongo(Posted 2004) [#10]
ok,... here is some working code with all but the skid stuff stripped out,... lets see your techniques!

Good point about the flag,... I'll try it and see if it helps. Edit: Yippee! this really sped things up,... no more noticable lag when drawing the marks. Anyways, I'm still interested on seeing how some of you would handle these.

Arrow keys to drive, hold space bar to make marks. The thing I love about this method, is that I can drive for an hour making skidmarks, and they will all still be there. With a dynamic mesh, you have to start removing old ones after a while so you don't bring everything to a halt.

; skid mark test
; use arrow keys to drive, hold space bar to draw skidmarks

Graphics3D 1024,768,0,2

Global carspeed#=0
Global carspeedmax=4
Global turncar#=0

Global car=CreateCube()

Global wheel_rf=CreateCylinder(8,1,car)
PositionEntity wheel_rf,-4.9,2,-4.9
RotateEntity wheel_rf,90,90,0
ScaleEntity wheel_rf,2,1,2
EntityColor wheel_rf,64,64,64

Global wheel_lf = CopyMesh (wheel_RF,car)
PositionEntity wheel_lf,4.9,2,-4.9
RotateEntity wheel_lf,90,90,0
ScaleEntity wheel_lf,2,1,2
EntityColor wheel_lf,64,64,64

Global wheel_rr = CopyMesh (wheel_RF,car)
PositionEntity wheel_rr,-4.9,2,5.1
RotateEntity wheel_rr,90,90,0
ScaleEntity wheel_rr,2,1,2
EntityColor wheel_rr,64,64,64

Global wheel_lr = CopyMesh (wheel_RF,car)
PositionEntity wheel_lr,4.9,2,5.1
RotateEntity wheel_lr,90,90,0
ScaleEntity wheel_lr,2,1,2
EntityColor wheel_lr,64,64,64

ground=CreateCube()
ScaleEntity ground,512,.01,512


Global tracktex=CreateTexture(1024,1024,256)
SetBuffer TextureBuffer(tracktex)
Color 0,200,0
Rect 0,0,1023,1023
SetBuffer BackBuffer()

EntityTexture ground,tracktex

;Create And position camera
camera=CreateCamera()
PositionEntity camera,0,100,-300
CameraZoom camera,2
PointEntity camera,ground

light1= CreateLight(2)
PositionEntity light1,0,500,-1000


;#########################################################################################################################
;Main loop until esc key is hit

Timer=CreateTimer(60)

While Not KeyHit(1)

	WaitTimer(timer) ; maintain constant FPS on faster machines (60)
	
	playerinput()
	MoveEntity car,0,0,carspeed
	
	TurnEntity car,0,turncar,0	
		
	UpdateWorld
	RenderWorld

	Flip 
	
Wend


End ;end program


;#########################################################################################################################

Function playerinput()

	If KeyDown( 200 ) ; upkey
	carspeed=carspeed+.1
	EndIf
 	
	If KeyDown( 208 ) ;downkey
	carspeed=carspeed-.1
	If carspeed<0 Then carspeed=0	
	EndIf
	
	If KeyDown( 203 ) ;leftkey
	turncar=turncar+1
	EndIf
	
	If KeyDown( 205 ) ;rightkey
	turncar=turncar-1
	EndIf
	
		
	If KeyDown(57)
	maketracks()
	EndIf
		
	Turncar=turncar*.75
    carspeed=carspeed*.98
	If carspeed>carspeedmax Then carspeed=carspeedmax

End Function 


Function maketracks()
	SetBuffer TextureBuffer(tracktex )
	LockBuffer TextureBuffer(tracktex )
	WritePixelFast EntityX(wheel_rf,1)+512,512-EntityZ(wheel_rf,1),0
	WritePixelFast EntityX(wheel_lf,1)+512,512-EntityZ(wheel_lf,1),0
	WritePixelFast EntityX(wheel_rr,1)+512,512-EntityZ(wheel_rr,1),0
	WritePixelFast EntityX(wheel_lr,1)+512,512-EntityZ(wheel_lr,1),0
	UnlockBuffer TextureBuffer(tracktex )
	SetBuffer BackBuffer()
End Function 




MadJack(Posted 2004) [#11]
Good work. The downside (to be a wet blanket ;-), is that the skidmarks themselves won't show detail such as tyre tracks. Would need to go to continuous mesh creation for that I guess.

Wonder if there's anything about his on Gamasutra or the like...


Pongo(Posted 2004) [#12]
yea,... not a problem for my particular game as the camera is not going to be that close (RC style control of the camera rather than following the car or inside the car)

I also plan on (if speed permits) drawing lines rather than single pixels so that the mark is less spotty. Even if it doesn't improve much I think I'll be ok with this method, since subsequent laps will eventually get the corners built up with skidmarks.


Jeremy Alessi(Posted 2004) [#13]
Very cool ... however I think I'm going to need either a special UV set just for skid marks or I'll have to use the PickedUVW(0 stuff from Fredborg.


Pongo(Posted 2004) [#14]
If you are not using a lightmap, (or even if you are) you should be able to write to that to make the skidmarks,... my example kind of cheats things a bit since the track size is nice and neat 1024x1024 units, so 1 unit = 1 pixel.