CameraPick faster than linepick by around 47 times

Miscellaneous Forums/General Discussion/CameraPick faster than linepick by around 47 times

From tests i have performed and from Makepool's observation, linepick is around 47 times slower than camerapick. Surely this could be utilized in lightmapping, as, as i recall, lightmapping is done with linepicks.

Graphics3D 800,600
SetBuffer BackBuffer()


Global camera = CreateCamera()
PositionEntity camera,0,0,-20


Global cube = CreateCube()
EntityPickMode cube,2
PositionEntity cube,5,0,0

Global cube1 = CreateCube()
EntityPickMode cube1,2
PositionEntity cube1,0,0,0



While Not KeyHit(1)

	Cls


	If MouseHit(1) Then
		CameraPick(camera,MouseX(),MouseY())
		If PickedEntity() <> 0 Then
			flag$="picked with camera pick!, time of = "+PickedTime()+" entity = "+PickedEntity()
			EntityColor PickedEntity(),Rnd(0,255),Rnd(0,255),Rnd(0,255)
		Else
			flag$="nothing picked..."
		End If
	ElseIf MouseHit(2) Then
		LinePick(0,0,-20,0,0,20,1)
		If PickedEntity() <> 0 Then
			flag$="picked with line pick!, time of = "+PickedTime()+" entity = "+PickedEntity()
			EntityColor PickedEntity(),Rnd(0,255),Rnd(0,255),Rnd(0,255)
		Else
			flag$="nothing picked..."
		End If
	End If
	
	UpdateWorld
	RenderWorld
	Text 0,0,flag
	Flip
Wend
End


Further to those tests, it seems most of the time is spent doing something other than picking, as, the further away you make the pick, the increase in time, is hardly noticable...

PickedTime ?! I didn't even know the command :o)

Maybe you should test it with millisecs and a loop that is picking something a few thousand times. Also note Cache optimations can give false results too, especially when you repeat some commands on some meshes etc. that did not move.

And - try to use Camerarange camera,0.1,40 and compare again. Maybe it's the camera range. Maybe CameraPick even scans from far to near and takes the last object, although that wouldn't make much sense.

However, very interesting stuff since I am using cameraPick a lot and maybe my game's going to run faster when I replace them by LinePicks.

I've never used 'LinePick' ever - it just always seemed it would be slower by the very design of it (albeit a useful command - yet one you could get away with never actually using).

Linepick isn't actually that slow. BIG apologies here. PickedTime returns a distance value, so to speak, between 0 and 1 of when the pick actually hit something. Poor documentation is at fault here. Sorry for posting inaccurate information.

whew... that's good to hear confirmed... LinePick() is at the heart of the shadow routine i just put in...

anyways, it was an interesting read Ross... no apologies necessary...

--Mike

CameraPick probably renders the scene and does a depth test, which would use the GPU instead of the CPU.

When you consider that its speed is about the same as rendering the scene with a width and height of one pixel then this makes sense.

But I rather think they (both, camerapick and Linepick) are so slow only because they got to scan trough all tris of all entities. a simple line-intersect-triangle code that can get very slow when the scene is complex.

The current implementation of Camerapick seems to scan space in steps (Correct me if I'm wrong). The individual times of short and long range picking suggests this.

Probably it would be faster if Blitz would calculate the intersection point of every triangle (if it intersects at all), add it to a list and then pick the one with the smallest distance to the Linepick startpoint. This would mean the speed is always the same, no matter how near the picked object is. (where Camerapick definitively takes more time the longer the pickrange is)

Graphics3D 800,600, 0, 2
SetBuffer BackBuffer()

Const ITER = 10000

Global camera = CreateCamera()
PositionEntity camera,0,0,-20


Global cube = CreateCube()
EntityPickMode cube,2
PositionEntity cube,5,0,0

Global cube1 = CreateCube()
EntityPickMode cube1,2
PositionEntity cube1,0,0,0

; FastLinePick
Global camPick = CreateCamera()
CameraClsMode camPick, False, False
CameraProjMode camPick, 0
Function FastLinePick(x1#, y1#, z1#, x2#, y2#, z2#)
	PositionEntity camPick, x1, y1, z1
	CameraProject camPick, x2, y2, z2
	Return CameraPick(camPick, ProjectedX(), ProjectedY())
End Function

While Not KeyHit(1)

	Cls


	If MouseHit(1) Then
		ts = MilliSecs()
		For i = 0 To ITER
			CameraPick(camera,MouseX(),MouseY())
			If PickedEntity() <> 0 Then
				flag$="picked with camera pick!, time of = "+PickedTime()+" entity = "+PickedEntity()
				EntityColor PickedEntity(),Rnd(0,255),Rnd(0,255),Rnd(0,255)
			Else
				flag$="nothing picked..."
			End If
		Next
		flag = flag + " (total time = " + (MilliSecs()-ts) + "ms)"
	ElseIf MouseHit(2) Then
		ts = MilliSecs()
		For i = 0 To ITER
			LinePick(0,0,-20,0,0,20,1)
			If PickedEntity() <> 0 Then
				flag$="picked with line pick!, time of = "+PickedTime()+" entity = "+PickedEntity()
				EntityColor PickedEntity(),Rnd(0,255),Rnd(0,255),Rnd(0,255)
			Else
				flag$="nothing picked..."
			End If
		Next
		flag = flag + " (total time = " + (MilliSecs()-ts) + "ms)"
	ElseIf MouseHit(3) Then
		ts = MilliSecs()
		For i = 0 To ITER
			FastLinePick(0,0,-20,0,0,20)
			If PickedEntity() <> 0 Then
				flag$="picked with fast line pick!, time of = "+PickedTime()+" entity = "+PickedEntity()
				EntityColor PickedEntity(),Rnd(0,255),Rnd(0,255),Rnd(0,255)
			Else
				flag$="nothing picked..."
			End If
			flag = flag + " (total time = " + (MilliSecs()-ts) + "ms)"
		Next
	End If
	
	UpdateWorld
	RenderWorld
	Text 0,0,flag
	Flip
Wend
End

LinePick is definately faster.

Linepick would be faster in that instance, because of the distance. For it to be a fair test, then the camera range would need to be the same as the pick length.