BVE WorldWide
Would you like to react to this message? Create an account in a few clicks or log in to continue.

Render questions

2 posters

Go down

Render questions Empty Render questions

Post by Dexter Thu Jan 21, 2016 12:26 am

Hello everyone,

I would like to discuss some render properties here. I do not see the entire technical background of how the sim works with the textures etc., so I thought I'll simply ask questions. Surprised So, the first question would be... am I right there will be no difference between these two when it comes to performance?


Option A
Code:
CreateMeshBuilder,
AddVertex,0,-0.45,0, 0,1,0
AddVertex,0,2,0, 0,1,0
AddVertex,2.5,2,0, 0,1,0
AddVertex,2.5,-0.45,0, 0,1,0
AddFace,0,1,2,3,
AddFace,3,2,1,0
GenerateNormals,
LoadTexture,Bush04.png,
SetTextureCoordinates,0,0,0.9,
SetTextureCoordinates,1,0,0,
SetTextureCoordinates,2,1,0,
SetTextureCoordinates,3,1,0.9,
SetdecalTransparentColor, 0,0,0

CreateMeshBuilder,
AddVertex,0,-0.45,2, 0,1,0
AddVertex,0,2,2, 0,1,0
AddVertex,2.5,2,2, 0,1,0
AddVertex,2.5,-0.45,2, 0,1,0
AddFace,0,1,2,3,
AddFace,3,2,1,0
GenerateNormals,
LoadTexture,Bush04.png,
SetTextureCoordinates,0,0,0.9,
SetTextureCoordinates,1,0,0,
SetTextureCoordinates,2,1,0,
SetTextureCoordinates,3,1,0.9,
SetdecalTransparentColor, 0,0,0

CreateMeshBuilder,
AddVertex,0,-0.45,-0.5, 0,1,0
AddVertex,0,2,-0.5, 0,1,0
AddVertex,2.5,2,2.5, 0,1,0
AddVertex,2.5,-0.45,2.5, 0,1,0
AddFace,0,1,2,3,
AddFace,3,2,1,0
GenerateNormals,
LoadTexture,Bush04.png,
SetTextureCoordinates,0,0,0.9,
SetTextureCoordinates,1,0,0,
SetTextureCoordinates,2,1,0,
SetTextureCoordinates,3,1,0.9,
SetdecalTransparentColor, 0,0,0

CreateMeshBuilder,
AddVertex,0,-0.45,2.5, 0,1,0
AddVertex,0,2,2.5, 0,1,0
AddVertex,2.5,2,-0.5, 0,1,0
AddVertex,2.5,-0.45,-0.5, 0,1,0
AddFace,0,1,2,3,
AddFace,3,2,1,0
GenerateNormals,
LoadTexture,Bush04.png,
SetTextureCoordinates,0,1,0.9,
SetTextureCoordinates,1,1,0,
SetTextureCoordinates,2,0,0,
SetTextureCoordinates,3,0,0.9,
SetdecalTransparentColor, 0,0,0



Option B

Code:
CreateMeshBuilder,
AddVertex,0,-0.45,0, 0,1,0
AddVertex,0,2,0, 0,1,0
AddVertex,2.5,2,0, 0,1,0
AddVertex,2.5,-0.45,0, 0,1,0
AddVertex,0,-0.45,2, 0,1,0
AddVertex,0,2,2, 0,1,0
AddVertex,2.5,2,2, 0,1,0
AddVertex,2.5,-0.45,2, 0,1,0
AddVertex,0,-0.45,-0.5, 0,1,0
AddVertex,0,2,-0.5, 0,1,0
AddVertex,2.5,2,2.5, 0,1,0
AddVertex,2.5,-0.45,2.5, 0,1,0
AddVertex,0,-0.45,2.5, 0,1,0
AddVertex,0,2,2.5, 0,1,0
AddVertex,2.5,2,-0.5, 0,1,0
AddVertex,2.5,-0.45,-0.5, 0,1,0

AddFace,0,1,2,3,
AddFace,3,2,1,0
AddFace,4,5,6,7,
AddFace,7,6,5,4,
AddFace,8,9,10,11,
AddFace,11,10,9,8,
AddFace,12,13,14,15,
AddFace,15,14,13,12,
 
LoadTexture,Bush04.png,
SetTextureCoordinates,0,0,0.9,
SetTextureCoordinates,1,0,0,
SetTextureCoordinates,2,1,0,
SetTextureCoordinates,3,1,0.9,
SetTextureCoordinates,4,0,0.9,
SetTextureCoordinates,5,0,0,
SetTextureCoordinates,6,1,0,
SetTextureCoordinates,7,1,0.9,
SetTextureCoordinates,8,0,0.9,
SetTextureCoordinates,9,0,0,
SetTextureCoordinates,10,1,0,
SetTextureCoordinates,11,1,0.9,
SetTextureCoordinates,12,1,0.9,
SetTextureCoordinates,13,1,0,
SetTextureCoordinates,14,0,0,
SetTextureCoordinates,15,0,0.9,
SetdecalTransparentColor, 0,0,0

Anyone knows the answer? Smile
Dexter
Dexter

Posts : 2153
Join date : 2011-07-08
Age : 38
Location : Brno, Czech republic

http://www.brnobve.eu

Back to top Go down

Render questions Empty Re: Render questions

Post by leezer3 Thu Jan 21, 2016 1:10 am

First, an important disclaimer-
There is no single 'right' answer, performance will always depend on many factors Smile

Short answer is that they're the same (#2 will probably load a few milliseconds faster), but the speed may actually depend on where they are placed in the route.

Having said that, let's dig into what happens a little.
As I'm sure you're aware (Having posed this question), your two samples are functionally identical, so I'll explain a little further.

When an object is loaded into memory, the final result looks nothing like what you see in your .b3d or .csv object file, but it is rather optimised and distilled into an abstract set of meshes with associated (bound) textures, which may be hidden or shown by the renderer at need.
To understand why this is fundamentally different from your .b3d file, we need to look at what actually happens when the object is loaded:

  1. The file is read from disk.
  2. The [MeshBuilder] statements in the file are sorted once into those containing transparency (Either through texture or through a Transparent statement), and those which do not.
  3. Meshes using the same texture, color and lighting are combined.
  4. An optimisation routine is run to eliminate duplicate vertices (A duplicate vertex must have *identical* world co-ordinates, normals and texture mapping to another), and to batch into the most efficient draw call.
  5. These meshes are then split into face groups.
  6. Face groups within meshes using transparency are sorted *again* from the rear to the front of the object.


We now have an object in memory, but this is by no means the end of the story Smile
When the final scene is rendered, this is what happens:

  1. All the non-transparent meshes in the scene are sorted by texture, and rendered first.
  2. The non-transparent meshes are then sorted from back to front of the scene, and the face groups are rendered in order, the texture changing as appropriate.

(**Things get rather more complicated when animated faces, and those attached to trains are in the picture, but we won't worry about those**)

As I've noted in previous threads, the OpenGL call with by far the highest system impact is GL.BindTexture.

First, let's try placing these on a bare piece of track, with no other objects using transparency within the viewing distance.
The sim is intelligent enough to only bind a new texture when it is needed, so the texture will never change when rendering these.
This requires a single call to GL.BindTexture

For the next trick, drop a tree into the middle of the bushes, using transparency, and a different texture (Say Tree01.png)
Rendering from front to back, the sim will first render two bushes using Bush04.png, and then will have to change texture to Tree01.png to render the tree. Finally, it changes back to Bush04.png to render the final two bushes.
This requires three calls to GL.BindTexture.

On the other hand, if we didn't use transparency for these, it'd render all 4 bushes first, followed by the tree Very Happy
This only requires two calls to GL.BindTexture.

Your head spinning yet?
(This is getting rather technical, sorry......)

Cheers

Chris Lees

http://www.bvecornwall.co.uk

leezer3

Posts : 1978
Join date : 2011-08-23

http://www.bvecornwall.co.uk

Back to top Go down

Render questions Empty Re: Render questions

Post by Dexter Thu Jan 21, 2016 3:42 am

leezer3 wrote:Your head spinning yet?
(This is getting rather technical, sorry......)

Not really, I am following up, no problems so far. Smile  So you are basically saying those few milliseconds saved on the second example might be there because there is only one mesh and therefore no mesh sorting and/or combining is needed. A least that's how I understand that part. Smile

The thing with tree and bushes actually brings a question to my mind, but that already involves animated objects... well that did not take long, did it.Laughing I will think of how to formulate the next question now. In the meantime, I have got a couple of objects to work on. Smile
Dexter
Dexter

Posts : 2153
Join date : 2011-07-08
Age : 38
Location : Brno, Czech republic

http://www.brnobve.eu

Back to top Go down

Render questions Empty Re: Render questions

Post by Sponsored content


Sponsored content


Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum