HowTo/Create a Fence Spline Featuring LOD and Random Meshes

From TrainzOnline
< HowTo
Revision as of 16:55, 15 May 2014 by Pcas1986 (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Contents

This How-to guide shows how lod-random-bias can be used to introduce visual variation into a spline for use as scenery in Surveyor. The asset is a barbed wire fence with end posts. To demonstrate mesh variation, each segment (track part) has a square or triangular marker. To demonstrate LOD levels the marker is red for the highest LOD detail, yellow for the medium level detail and green for the lowest level detail. The asset is an example only.


LOD-random-bias-fence-spline-3-rows.jpg

Purpose

This example shows how lod-random-bias can be used to introduce visual variation into a spline. Two variants of the repeating unit appear in the spline at random as the fence is laid out. In addition, a 3-tiered LOD scheme has been implemented on each mesh variant (and both end-caps).


Acknowledgements

The demonstration asset is provided by Trainz content creator Dinorius_Redundicus (Deane) for education purposes.


Working Version

A working equivalent of this asset - without the visual markers - will be made available on the Download Station as 'Post and batten fence 01' <kuid2:68213:37066:2>."


A Definition and Background

A spline in computer graphics is a curve between two points. For Trainz purposes the spline is the curve between a start and an end point. This curve is comprised or one or more meshes identified within a Track_Part_Container. These meshes are subject to variation as defined in the "track-lod-tree"_container. Within this tutorial the term "Segment" is used rather than "track-part".


Fence Spline

The asset is a 5-strand barbed-wire fence with post-and-batten construction. For demonstration purposes, the various meshes have been marked to indicate which variant and LOD level is visible;

Variant 1 (triangle markers). This is the high detail mesh series named "main".
Variant 2 (square markers). This is the low detail mesh series named "main2".
High-poly, LOD0 (red markers).
Medium-poly, LOD1 (yellow markers).
Low-poly, LOD2 (green markers).

LOD transitions occur at 15m and 70m. The transitions and textures have been designed to offset the blurring of fence wires caused by 'mip mapping' - the automatic use by Trainz of low-resolution textures at long view distance.

This image show four lengths of the asset. The two fences at the rear consist of one spline and differ in three of the eleven segments which is about a 27% variation. The second closest fence consists of two segments and the closest consists of four segments. There are twelve segments and in this case nine of the twelve are different for a variation of 75%.


LOD-random-bias-fence-spline-4-rows.jpg


The image below shows the two lowest LOD levels: LOD1 and LOD2.


LOD-random-bias-fence-spline-2-LODs-visible.jpg


The image below shows all three LOD levels.


LOD-random-bias-fence-spline-3-LODs-visible.jpg


Config.txt

The mesh-table, track, endcap-next and endcap-prev containers are shown below.

mesh-table
{
 main-lod0
 {
   mesh                                "main_lod0.im"
 }
 
 main-lod1
 {
   mesh                                "main_lod1.im"
 }
 
 main-lod2
 {
   mesh                                "main_lod2.im"
 }
 
 main2-lod0
 {
   mesh                                "main2_lod0.im"
 }
 
 main2-lod1
 {
   mesh                                "main2_lod1.im"
 }
 
 main2-lod2
 {
   mesh                                "main2_lod2.im"
 }
 
 end-next-lod0
 {
   mesh                                "end_next_lod0.im"
 }
 
 end-next-lod1
 {
   mesh                                "end_next_lod1.im"
 }
 
 end-next-lod2
 {
   mesh                                "end_next_lod2.im"
 }
 
 end-prev-lod0
 {
   mesh                                "end_prev_lod0.im"
 }
 
 end-prev-lod1
 {
   mesh                                "end_prev_lod1.im"
 }
 
 end-prev-lod2
 {
   mesh                                "end_prev_lod2.im"
 }
}
track
{
 mesh-length                           10
 adjust-cross-section-to-ground        0
 
 track-lod-tree
 {
   lod-random-bias                     0.5
   
   high-detail  (Comment:  This is the mesh series marked with triangles)
   {
     subdivisions                      1
     lod-distance                      70
     
     high-detail  
     {
       lod-distance                    15
       
       high-detail
       {
         mesh                          "main-lod0"
       }
       
       low-detail
       {
         mesh                          "main-lod1"
       }
     }
     
     low-detail
     {
       mesh                            "main-lod2"
     }
   }
   
   low-detail  (Comment:  This is the mesh series marked with squares)
   {
     subdivisions                      1
     lod-distance                      70
     
     high-detail
     {
       lod-distance                    15
       
       high-detail
       {
         mesh                          "main2-lod0"
       }
       
       low-detail
       {
         mesh                          "main2-lod1"
       }
     }
     
     low-detail
     {
       mesh                            "main2-lod2"
     }
   }
 }
}
endcap-prev
{
 mesh-length                           10
 adjust-cross-section-to-ground        0
 
 track-lod-tree
 {
   lod-distance                        70
   subdivisions                        1
   
   high-detail
   {
     subdivisions                      1
     lod-distance                      15
     
     high-detail
     {
       mesh                            "end-prev-lod0"
     }
     
     low-detail
     {
       mesh                            "end-prev-lod1"
     }
   }
   
   low-detail
   {
     mesh                              "end-prev-lod2"
   }
 }
}
endcap-next
{
 mesh-length                           0.1
 adjust-cross-section-to-ground        0
 
 track-lod-tree
 {
   lod-distance                        70
   subdivisions                        1
   
   high-detail
   {
     subdivisions                      1
     lod-distance                      15
     
     high-detail
     {
       mesh                            "end-next-lod0"
     }
     
     low-detail
     {
       mesh                            "end-next-lod1"
     }
   }
   
   low-detail
   {
     mesh                              "end-next-lod2"
   }
 }
}


Comments on randomness of fence segments

This is not part of the tutorial but rather notes on tests carried out in Surveyor with this particular asset and other observations.


A 30 row test

The LOD-random-bias tag for this asset is set for 0.5 and it could be expected that the allocation of the two main meshes used would be about 50% for each. A test of 30 fence rows, each of of one spline and 10 segments, for a total of 300 segments gave the following results:


Row Squares Triangles
1 5 5
2 8 2
3 6 4
4 1 9
5 9 1
6 0 10
7 5 5
8 2 8
9 5 5
10 7 3
11 4 6
12 8 2
13 9 1
14 8 2
15 10 0
16 5 5
17 8 2
18 9 1
19 4 6
20 0 10
21 9 1
22 1 9
23 9 1
24 8 2
25 10 0
26 8 2
27 7 3
28 8 2
29 3 7
30 7 3
Totals: 183 117

The results vary significantly in individual rows of the spline. Some are equal with five of each shape but several have a significant number of one shape. Overall for all the rows the percentage of triangles (low detail) was 36% and the percentage of squares (high detail) was 64%. This doesn't correlate with the allocated bias of 0.5. The bias will only be applied for each row individually but, given the sample, it would be reasonable to expect an overall result of about 50% for each variant across the sample range.

A different result may well have been achieved if a single run of 100 segments had been tried. This was attempted but the limitations of moving around in Surveyor made it almost impossible to count segment markers.

The skewed results towards the low detail mesh appear to be at odds with the 50% prediction. It is worth noting the comments for LOD-random-bias in the "track-lod-tree" container.


Subdivisions

The "track-lod-tree"_container has a tag called "subdivisions". This tag can be used to break up the track-part into smaller parts and so introduce further variation. This was not explored in this demonstration asset but is worthy of experimentation.


"Clumping"

The tests often showed variants of a similar type grouped together in "clumps". i.e. 4 or 5 of one variant together. In a single long run of one spline, which covered about two baseboards, the clumping was noticeable at the start of the run but lessened towards the middle of the run. There is no explanation for this behaviour. The clumping can be seen in the image below.


Variation during placement of spline points

During the tests the mix of meshes changed when a spline point was moved. Even slight movements provoked a re-shuffling of the meshes until the spline point was 'released', at which stage the arrangement of the spline was set.

Each movement of a spline point causes the spline to be regenerated, which results in a new sequence of mesh variants. For this asset, the first high-detail/low-detail fork in the track-lod-tree decides which mesh variant will appear (other forks only decide its level of detail). Each time the spline is generated, the sequence and proportion of high-detail and low-detail paths chosen vary, hence the order and proportion of mesh variants in the spline also vary. The statistics of this variation are governed rather broadly, by the lod-random-bias value.

The practical importance of this effect for the Trainz user is that it provides an easy way to overcome the 'clumping' that is often seen when initially placing the spline, to obtain a more even mix of the mesh variants. Content creators may consider including this effect in the description field of their asset config.txt to assist users of their asset.


Test Image

LOD-random-bias-fence-spline-30-rows.jpg


Related Information

This thread in the Trainz Forum discussed this subject extensively.


Downloads

A copy of the demonstration asset is available from the link below.

File:Kuid 68213 37900 Post and batten fence (demonstration).cdp

Personal tools