TrisRendered()

Blitz3D Forums/Blitz3D Programming/TrisRendered()

Warren(Posted 2004) [#1]
Quicky question ... are the results from this command ever wrong? :) It seems to be reporting 2x as many triangles as I have on the screen. I'm 99.5% sure that I am NOT creating as many triangles as it claims I am. I'm creating one mesh, with one surface, 4 vertices and 2 triangles ... and it jumps my TrisRendered() results by 4 instead of the expected 2.

Is it doing multiple passes and counting each pass? Is there something else to look out for?


poopla(Posted 2004) [#2]
A: post your creation code.

B: I don't know :).


Warren(Posted 2004) [#3]
My code is sort of complicated, but the basic creation code is sort of like this...

	; Create the mesh itself
	
	Mesh = CreateMesh( InCamera )
	
	; Allocate and assign a brush
	
	Wk\BrushID = CreateBrush()
	BrushTexture( Wk\BrushID, InTexture )
	BrushFX( Wk\BrushID, 1+2+16+32 )

	; Give the mesh a surface

	Wk\SurfID = CreateSurface( Mesh )
	PaintSurface( Wk\SurfID, Mesh )


I then add 4 vertices to the surface and create 2 triangles looking something like this...

	vtx0 = AddVertex( InSurf,	 X0, Y0, 0,	U0#,V0# )
	vtx1 = AddVertex( InSurf,	 X1, Y1, 0,	U1#,V0# )
	vtx2 = AddVertex( InSurf,	 X2, Y2, 0,	U0#,V1# )
	vtx3 = AddVertex( InSurf,	 X3, Y3, 0,	U1#,V1# )

	AddTriangle( InSurf, vtx0, vtx1, vtx2 )
	AddTriangle( InSurf, vtx3, vtx2, vtx1 )


Not sure if that hacked up version helps at all... my renderer is kinda large-ish now.


DJWoodgate(Posted 2004) [#4]
How many cameras?


Warren(Posted 2004) [#5]
2 ... One for 3D stuff and one for 2D. The troublesome triangles are being created on the 2D one, which is the second one that I create.

BTW, I just double checked and it's actually reported 4x the triangles ... so a single letter drawn on the screen, 2 triangles, is being reported as 8.

I must have a bug somewhere unless someone knows of a gotcha here.


Warren(Posted 2004) [#6]
OK, I obviously have a problem on my end, sorry. I thought that parenting an entity to a camera would cause only THAT camera to render it. Apparently, not.

I'll have to do some digging and see how to work multiple cameras without losing my sanity...


TeraBit(Posted 2004) [#7]
Perhaps because you are disabling backface culling? Blitz may be counting the backfaces as separate tris.


Warren(Posted 2004) [#8]
No, I've narrowed it down now. The answer is that I'm a stupid n00b and don't understand cameras. :)

I need to move my second camera, that I use for HUD rendering, way off somewhere in space so the cameras can't see each other. That breaks up the rendering properly and gives me a proper triangle count.

Sorry!


BlitzSupport(Posted 2004) [#9]
Remember you can use CameraProjMode to swap between which camera renders too...


puki(Posted 2004) [#10]
No need to be sorry "EpicBoy" - this thread may benefit others.


Warren(Posted 2004) [#11]
OK, just so others don't fall into this bear trap, here's the dealio...

I have 2 cameras. I use one to draw the players perspective of the 3D world. I use the second to draw HUD/UI elements (text, menus, etc).

To make this work, I had to move the second camera way off into oblivion (MoveEntity( cam, 0, 0, 65535 )). This way, neither camera can see what the other is doing so they only render the stuff they are assigned.

This fixes it and TrisRendered is happy again.


Rob(Posted 2004) [#12]
The real reason you're getting 2x the polygons with TrisRendered() is simply because that is the amount of triangles processed in the pipeline. The actual amount rendered on screen will vary as this count is taken before backface culling.

The name is misleading, I know.


puki(Posted 2004) [#13]
Ooh, nice one "Wobby" - it amazes me how he knows all of this stuff.


Warren(Posted 2004) [#14]
No, the reason was that the second (UI) camera was too close to the world origin and was seeing the geometry and hence, rendering it.

I thought I explained all of this. ;)

It all reports perfectly now.


Rob(Posted 2004) [#15]
But TrisRendered() will still report in that fashion - ie all rendered triangles before backface culling.


Warren(Posted 2004) [#16]
Right, and if the second camera is far enough away it won't render the stuff because it's beyond that cameras far clipping plane, hence it won't be in TrisRendered(). :)

But we're talking about the same thing here, so ...


John Pickford(Posted 2004) [#17]
Epicboy,

I use multiple cameras in my 2D system, a camera each for different layers of tiles (3d mesh) and for each set of sprites (again a 3d mesh). I've never needed to move the camera away, all the cameras are in the same spot in fact. You just need to HIDE the cameras not in use. There should be only ONE camera unhidden when you Renderworld().

You also need to hide anything you don't want rendering by that particular camera.

I just have a pivot which all my ingame 3D stuff is parented to. And a pivot for my 2D stuff.

I do something like:

  showentity 3dcamera
  showentity maingamestuff

  renderworld()

  hideentity 3dcamera
  hideentity maingamestuff

Then for each layer of 2d stuff (specific to my system)

  showentity 2dcamera(x)
  showentity 2dlayer(x)

  renderworld()

  hideentity 2dcamera(x)
  hideentity 2dlayer(x)




Warren(Posted 2004) [#18]
Well, Blitz handles multiple cameras OK ... it uses them in the order that they were created. So if you set up the second camera to not clear the back buffer, it just draws right on top of the back buffer.

Anyway, thanks, but this method works for me so I'll probably stick with it. Probably faster than calling RenderWorld multiple times too...


big10p(Posted 2004) [#19]
Am I right in thinking that if you move your camera way off to 65535 then you'll only be left with precision to 1 decimal fraction? e.g. moving the cam forward by .15 will actually move it by .2 because of the six-digits-of-precision limitation of floats.

EpicBoy, I realize this probably wont effect you if you're only rendering HUD stuff on the far-away cam but I guess it's something to bare in mind when using that technique!?


Warren(Posted 2004) [#20]
Yeah, that camera isn't moving ... and I don't have to move that far away, it was just for example purposes. I can adjust it to be just outside the other cameras far clipping plane.


Anthony Flack(Posted 2004) [#21]
I believe that trisrendered reports the number of tris BEFORE directX fustrum culling as well (but AFTER blitz's per-object culling). I think so anyway, if I'm remembering right.


John Pickford(Posted 2004) [#22]
Moving your camera far away seems a bit of of bodge.

I've done a fair bit of speed testing and there's no noticable penalty for multiple renderworlds. Sticky Balls probably used 6 or 7.

SHOW\HIDE is pretty much instantaneous too. I find it best to keep everything hidden by default and just show what you need for each render.

This does highlight something missing from Blitz, it should be possible to have multiple 'worlds' in your project. Renderworld (world)


Hotcakes(Posted 2004) [#23]
Mark's mentioned that himself. =]