mirror code test

Blitz3D Forums/Blitz3D Programming/mirror code test

Andy(Posted 2005) [#1]
I've propably gone as far as I can with this code. I would apreciate if anyone could point out how to improve the speed. Only copyrecting every second frame gives me a 20 fps increase without it being noticable, but what else can you suggest.

I'd also like to hear how many frames per second you get on different platforms.

With flip: 120FPS
With flip false: 380FPS

Specs: Celeron 1.4GHz with a Radeon 9800.

; fakemirrors 

width=800
height=600
fovsphere#=65.0
fovmirror#=70.0
texsize=512
testfl=1


Graphics3D width,height 

SetBuffer BackBuffer() 

; create textures
tex=CreateTexture( texsize,texsize,48+256)
tex2=CreateTexture( texsize,texsize,48+256)

;setup cube texture
SetBuffer TextureBuffer(tex2) 
ClsColor 255,255,255 
Cls
For q=1 To 200
Color Rnd(255),Rnd(255),Rnd(255)
Rect Rnd(640),Rnd(480),Rnd(32),Rnd(32)
Next
SetBuffer BackBuffer() 

; brushes
brush1=CreateBrush() 
BrushTexture brush1,tex 
BrushShininess brush1,1 

brush2=CreateBrush() 
BrushTexture brush2,tex2

brush3=CreateBrush(255,0,0) 



; objects

sphere_object=CreateSphere()
sphere_pivot=CreatePivot(sphere_object)
sphere_camera=CreateCamera(sphere_object) 
light=CreateLight() 

cube2=CreateCube()
ScaleMesh cube2,200,200,200
FlipMesh cube2
PaintMesh cube2,brush2


mirror_object=CreateMesh() 
surf=CreateSurface(mirror_object) 
v0=AddVertex(surf,-5, 5, 0, 1.0, 0.0)  ; upper left 
v1=AddVertex(surf, 5, 5, 0, 0.0, 0.0)   ; upper right 
v2=AddVertex(surf, 5,-5, 0, 0.0, 1.0)   ; lower right 
v3=AddVertex(surf,-5,-5, 0, 1.0, 1.0)  ; lower left 
t0=AddTriangle(surf,v0,v1,v2) ; triangle 1 
t1=AddTriangle(surf,v2,v3,v0) ; triangle 2 

mirror_pivot_left=CreatePivot(mirror_object)
mirror_pivot_right=CreatePivot(mirror_object)
PositionEntity mirror_pivot_left,-10,10,0 
PositionEntity mirror_pivot_right,10,10,0 

mirror_camera=CreateCamera(mirror_object)

; paint objects
PaintMesh mirror_object,brush1 
PaintMesh sphere_object,brush3 


; posititon and orient objects
PositionEntity mirror_object,0,0,100 
RotateEntity light,45,0,0 
RotateEntity mirror_camera,0.0,180.0,0.0 


While Not KeyDown(1) 

Gosub movesphere
Gosub rmirror

Cls
HideEntity(mirror_camera)
ShowEntity(sphere_camera)

CameraZoom sphere_camera,(1.0 / Tan(fovsphere#/2.0))
CameraClsColor sphere_camera,0,0,0
RenderWorld 

frames=frames+1
If fpstimer < (MilliSecs() - 1000)
	fps=frames
	frames=0
	fpstimer=MilliSecs()
EndIf
Text 10,10, fps
Text 10,30, fovmirror#
Text 10,50, mirror_distance#


Flip 

Wend 

End 


.movesphere
	If KeyDown( 203) Then TurnEntity sphere_object,0,0.5,0
	If KeyDown( 205 ) Then TurnEntity sphere_object,0,-0.5,0
	If KeyDown( 200 ) Then MoveEntity sphere_object,0,0,0.5
	If KeyDown( 208 ) Then MoveEntity sphere_object,0,0,-0.5
	If KeyDown( 30 ) Then MoveEntity sphere_object,0,0.5,0
	If KeyDown( 44 ) Then MoveEntity sphere_object,0,-0.5,0
	If KeyHit(17) Then wire= Not wire

	WireFrame wire
Return


.rmirror
    HideEntity(sphere_camera)
    ShowEntity(mirror_camera)

	CameraClsColor mirror_camera,0,0,255
	PointEntity(sphere_pivot, mirror_object) 

        mirror_distance#=Abs(EntityDistance ( sphere_object, mirror_object))
        PositionEntity mirror_camera,0.0,0.0,mirror_distance#
	RotateEntity mirror_camera,EntityPitch(mirror_object)+(EntityPitch(sphere_pivot,1)*1.0),EntityYaw(mirror_object)+180+(EntityYaw(sphere_pivot,1)*-1.0),EntityRoll(mirror_object) 

	PointEntity(sphere_pivot, mirror_pivot_left) 
	fov1#=EntityYaw(sphere_pivot);*1.75
	PointEntity(sphere_pivot, mirror_pivot_right) 
	fov2#=EntityYaw(sphere_pivot);*1.75

	fovmirror#=Abs(fov2#-fov1#)

	CameraZoom mirror_camera,(1.0 / Tan(fovmirror#/2.0))

	Cls
	RenderWorld 
    CopyRect (width/2)-(texsize/2),(height/2)-(texsize/2),texsize,texsize,0,0,0,TextureBuffer(tex)
Return



Andy


GfK(Posted 2005) [#2]
Er, what code's that, then? :)


Mark Judd(Posted 2005) [#3]
~200 fps (when up real close to the mirror)
~240 fps when further away

Work PC
Intel Xeon 1.4
512Mb
Geforce 4 Ti 4600

Funky Frank


Mikele(Posted 2005) [#4]
hmm... 38 fps (const) (P4/2.4HT 512MB with crappy gf5200fx)

EDIT:
...without 256 flag - 30 fps :)

...and 255/340 fps (close/away) with flip false (P4/2.4 512MB with old gf4200)


Andy(Posted 2005) [#5]
So with 2 simple changes, I've gone from 30fps to 400fps.

That's great, but it only underlines that I am not a very good coder.


Andy


Andy(Posted 2005) [#6]
I'm disapointed that only 2 people found it worth testing, particularly since many people have been discussing how to make mirrors since B3D came out, and someone even found it worth the effort to make a userlib for it.

On the other hand, With with close to 200 fps on a GF4, it seems plausible to actually use it in a game.

I was working on an include which would make it a simple plug-in to an existing game, but since there is no interest I'll leave it as it is.

It's not finished, and it's pretty crappy, so use it at your own perril.

Thanks for testing this Funky Frank and Mikele.

Andy


Red Ocktober(Posted 2005) [#7]
sorry Andy... was really busy most of today... missed this until now...

i'm getting about 60 fps (according to fraps) all around 1.7 GHz celeron with a radeon 9200... fullscreen

this is kinda neat

--Mike


Andy(Posted 2005) [#8]
>sorry Andy... was really busy most of today... missed this
>until now...

Well, considering you were the guy who got me started I forgive you! :)

>i'm getting about 60 fps (according to fraps) all around
>1.7 GHz celeron with a radeon 9200... fullscreen

Are you also getting 60 FPS using Flip false instead of Flip?

>this is kinda neat

I think so. It would be neat to have a system where you just include the code, call setupmirror(mirrorhandle) in the beginning of your code and call domirrorstuff(mirrorhandle) every frame. That would enable people to plug mirrors into their WIP's in just a few minutes.

Andy


Rroff(Posted 2005) [#9]
440fps with flip false

fx5950ultra + 3gig P4

with flip it was capping to my monitor refresh (no suprise)

changing the display to 32bit fullscreen I get 630fps, and in 16bit fullscreen I get 780, which is interesting as I never normally see any performance difference between 16bit and 32bit.


Mikele(Posted 2005) [#10]
ok... 75 fps (gf5200fx but with 16bit color depth)


John Blackledge(Posted 2005) [#11]
86 = 800 600 32 windowed - Flip
234>265 = 800 600 32 windowed - Flip False
76 = 800 600 32 fullscreen - Flip (fullscreen is slower?)
343>207 = 800 600 32 fullscreen - Flip False

86 = 800 600 16 windowed - Flip
274>221 = 800 600 16 windowed - Flip False
65 = 800 600 16 fullscreen - Flip
430>390 = 800 600 16 fullscreen - Flip False

P4 1.6 256MB GeForce Ti4200

(I'd love to see this as an 'Include'!)


Rroff(Posted 2005) [#12]
fullscreen flip is prolly slower than windowed flip because your directx fullscreen refreshrate for that resolution is different to your normal windows desktop.


BlitzSupport(Posted 2005) [#13]

It would be neat to have a system where you just include the code, call setupmirror(mirrorhandle) in the beginning of your code and call domirrorstuff(mirrorhandle) every frame


That's what I did here. Yours uses a lot less code, though! (It doesn't seem to be flipping the image, however.)

Mine partially broke at some point, so that the mirror masks stopped working (they let you create shaped mirrors). Square mirrors are fine, though.


Andy(Posted 2005) [#14]
>That's what I did here. Yours uses a lot less code,
>though! (It doesn't seem to be flipping the image,
>however.)

I just use reverse u coordinates on the mirror. It seems to do the trick very well.

Andy


RemiD(Posted 2016) [#15]
Hello,

Can somebody please share the file "realmirrors.zip" posted by BlitzSupport (post #13)
(old link : http://www.hi-toro.com/blitz/realmirrors.zip)

(this necropost is quite impressive, even if i have seen worse than that :P)

Thanks,


Rick Nasher(Posted 2016) [#16]
Here you go: realmirrors.zip


RemiD(Posted 2016) [#17]
@Rick>>Thanks ! (just curious, where have you found it ? the last post was 11 years ago !)


Rick Nasher(Posted 2016) [#18]
You're welcome. Sitting on my ext disk. Dunno where came from, but I once grabbed all that interested me just in case the site ever went down(which is like never I hope).


Guy Fawkes(Posted 2016) [#19]
@Rick Nasher: Do you still have Tree Party for Blitz3D? I had a license, but mine got lost in a hard drive crash... And now gothasoft's website is down forever :(

~GF


RemiD(Posted 2016) [#20]
@GF>>I don't have "tree party" but i have a code example with a similar thing (many trees or many grasses single surface ("blitzforest" and "blitzgrass")), if you are interested i can upload it...


Rick Nasher(Posted 2016) [#21]
Nope, no tree/grass party unfortunately. Blitzforest/grass is kinda cool indeed.


Guy Fawkes(Posted 2016) [#22]
That sounds great, RemiD! Thanks alot! :)

~GF


RemiD(Posted 2016) [#23]
Ok here it is : http://tempsend.com/3FB4ADA53A
And the official thread : http://www.blitzbasic.com/Community/post.php?topic=69532&post=778054


Guy Fawkes(Posted 2016) [#24]
Thanks alot, Remi! :) I think I've seen this one before, but this one needs a major overhaul. The graphics are terrible. Let me do that real quick.!

I'll reupload it for you guys! :)

~GF


RemiD(Posted 2016) [#25]
As i understand it, the intent of this demo is not to show beautiful meshes and textures but rather to render many impostors (textured quads) of trees and of grasses, very fast.


Guy Fawkes(Posted 2016) [#26]
Hehe... Too late! :D

Posting in a few minutes.

~GF