In the previous tutorial, we constructed a tunnel entrance using a photorealistic texture for the portal and then constructed the walls using measurements taken from the portal image. Not 100% successful in my case as part of the tunnel wall looks distorted. This could have been overcome by adjusting the positions of the offending vertices – the principle of the method is sound even if I appear to have been a bit careless with my measurements.
Additional objects used in this tutorial session may be found here:
http://vps.bvecornwall.co.uk/dennislance/DLTUTORIAL_1_11.zip
Unzip to the DLTUTORIAL_1 in your objects folder.
In this tutorial, we will see how to alter the wall texture to obtain more realistic lighting as we enter the tunnel. The tunnel will also be lengthened and the exit constructed. Finally, we will modify the track in the tunnel so that this too is illuminated correctly and then apply the necessary cab brightness commands.
It is worth pointing out that an alternative means of varying the brightness in tunnels is through the use of black fog. This is certainly something I have used before myself and although effective if applied correctly, it is very difficult to get just right.
Time to get to work…
Firstly, we will concentrate on modifying the brick1 texture applied to the tunnel wall so that it looks as if the light fades out when looking into the tunnel. To do this, a reasonably advanced image editor is a useful tool – personally, I use Photoshop.
Before making any modifications to the brick1 texture, make a backup copy – to properly assess the changes being made to the image, it must be saved and the tunnel viewed in BVE or structure viewer. With Photoshop (and possibly other image editors), once an image is saved, there is no going back on the changes made.
The first modification I made to the brick1 texture (after changing it to an RGB image) was to graduate a black fill horizontally from the centre of the bitmap. This will represent years worth of soot accumulation on the roof and also make a start darkening the tunnel walls. The next modification made used the lighting effects available in Photoshop. A wide focus spotlight was shone from the left hand side of the image with the centre point of the beam situated the mid-way up the left hand edge of the texture. The resulting image was then converted back to an eight bit indexed colour image, and now looks like this:
This texture, which is included in the objects download, may then be used in the tunnel entrance object (tunnel entrance.CSV) in place of the original brick1 texture by changing the original
1 |
loadtexture,brick1.bmp, |
To:
1 |
loadtexture,brick1_modified for tunnel entrance.bmp, |
Compared with what we had previously, the tunnel walls are now generally darker than before and with the brightness fading along the length of the wall.
The next job is to lengthen the tunnel by 75 metres. To do this, we will need two 25metre lengths of dark wall for the central 50metres and then a 25metre length where the walls become brighter as the tunnel exit is approached.
To create the central (dark) lengths we need to create a new object. Rather than rebuild the walls, we can simply make a copy of the tunnel entrance object, remove the portal and use a suitably darkened brick1 image for our texture.
So, make a copy of tunnel entrance.CSV and rename to tunnel_mid.CSV. This object should be indexed in the route file as free object 51 in the route file. It object should then be placed on the route at 275 and 300metres.
To remove the portal from this object, remove the following code from the object file:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
;side, CreateMeshBuilder Addvertex, -5.75, 8.2, 0, Addvertex, 9.25, 8.2, 0, Addvertex, 9.25, -0.3, 0, Addvertex, -5.75, -0.3, 0, Addface, 0,1,2,3, generatenormals, LoadTexture,tunnel_entrance.bmp, SetTextureCoordinates,0,0,0 SetTextureCoordinates,1,1,0 SetTextureCoordinates,2,1,1 SetTextureCoordinates,3,0,1 Setdecaltransparentcolor,0,0,0, |
If the route is now viewed, the need for a modified wall texture becomes immediately apparent. A uniformly darkened brick1 image is required – the brightness of this must match that of the end of the tunnel entrance section to ensure a seamless transition. Such an image has been supplied with the objects download, brick2.BMP, and this can replace the current texture by changing the line:
1 |
loadtexture,brick1_modified for tunnel entrance.bmp, |
To:
1 |
loadtexture,brick2.bmp, |
If the modified object file is now saved and the route viewed, the middle 50m of the tunnel appear to be of uniform darkness and we could continue extending the tunnel further using these objects.
All we need to do now is to increase the brightness of the tunnel walls as the exit is approached. If the tunnel entrance object is rotated by 180° , the effect could be achieved with no further objects required. However, our tunnel walls are not completely symmetrical and if the object is rotated in this way, gaps in the walls will result.
What we can do is create a new object which uses a mirror image of the tunnel entrance texture but with the same wall construction as used for the other sections. So, create a copy of tunnel_mid.CSV and rename it tunnel_end.CSV. In this object file, then alter the wall texture by changing the line:
1 |
loadtexture,brick2.bmp, |
To:
1 |
loadtexture,brick1_modified for tunnel exit.bmp, |
It is worth noting that if we want the tunnel walls to be of less uniform appearance, there is no reason why other modifications cannot be made to this or the texture used in the middle section of the tunnel providing the overall brightness effects are not altered – such a modification has been included in the tunnel exit texture (where bits of the wall have been marked out for repair and instructions not to machine tamp included).
Now that the tunnel walls are constructed, we need to turn our attention to the track and fade the brightness of this in and out. One possible way of achieving this is to overlay on the track a semi-transparent black texture, as seen in bridge shadows on Birmingham Cross City and other routes. The difficulty we would have with this approach is producing a uniform graduation of the darkening effect without introducing obvious ‘banding’.
To overcome this, we can again use modified image textures, in this case incorporating them into rail objects. Our first task is therefore to create a new straight rail object by making a copy of DL_STRAIGHT.B3D and renaming it DL_STRAIGHT_TUNNEL_ENTRANCE.B3D. This file needs to be defined as a rail object in the route file by including the code:
1 |
.Rail(21) DLTUTORIAL\DL_STRAIGHT_TUNNEL_ENTRANCE.b3d, |
To position the rail at the tunnel entrance we also need to add this:
1 |
250,.freeobj 0;50,.railtype 0;21,.railtype 1;21, |
Opening up this object to take a look, we find that the track part of this rail object is made up of 5 ‘segments’ (We know this as it uses 5 face statements):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
[meshbuilder] vertex -1.350, -0.170, -0.100 vertex 1.350, -0.170, -0.100 vertex -1.350, -0.170, 5.000 vertex 1.350, -0.170, 5.000 vertex -1.350, -0.170, 10.000 vertex 1.350, -0.170, 10.000 vertex -1.350, -0.170, 15.000 vertex 1.350, -0.170, 15.000 vertex -1.350, -0.170, 20.000 vertex 1.350, -0.170, 20.000 vertex -1.350, -0.170, 25.100 vertex 1.350, -0.170, 25.100 face 2, 3, 1, 0 face 4, 5, 3, 2 face 6, 7, 5, 4 face 8, 9, 7, 6 face 10, 11, 9, 8 [texture] load dl_track3.bmp coordinates 0, 1.02, 10 coordinates 1, -0.02, 10 coordinates 2, 1.02, 8 coordinates 3, -0.02, 8 coordinates 4, 1.02, 6 coordinates 5, -0.02, 6 coordinates 6, 1.02, 4 coordinates 7, -0.02, 4 coordinates 8, 1.02, 2 coordinates 9, -0.02, 2 coordinates 10, 1.02, 0 coordinates 11, -0.02, 0 |
Although we have not previously edited any .B3D objects, the way in which these are constructed should be familiar even if the commands and syntax are not. What we will do to modify our rail object is firstly create a image composed of tiled track textures and then add lighting effects to this image before incorporating it into the rail object by modifying the coordinates commands. The ballast texture will also need modification in the same way. Suitably modified textures have been included with the objects download (dl_track_3_fade_in.BMP and dl_ballast_fade_in.BMP).
Now we need to modify the object file DL_STRAIGHT_TUNNEL_ENTRANCE.B3D;
Change the texture by modifying this line:
1 |
load dl_track3.bmp |
To:
1 |
load dl_track3_fade_in.bmp |
And then modify the texture coordinates by changing the whole section to look like this:
1 2 3 4 5 6 7 8 9 10 11 12 |
coordinates 0, 1.02, 1.0 coordinates 1, -0.02, 1.0 coordinates 2, 1.02, 0.8 coordinates 3, -0.02, 0.8 coordinates 4, 1.02, 0.6 coordinates 5, -0.02, 0.6 coordinates 6, 1.02, 0.4 coordinates 7, -0.02, 0.4 coordinates 8, 1.02, 0.2 coordinates 9, -0.02, 0.2 coordinates 10, 1.02, 0.0 coordinates 11, -0.02, 0.0 |
Now if the object is saved and the route viewed, the brightness of the track texture, but not the rails or ballast, is seen to fade as the tunnel is entered (this effect will be repeated every 25m as we have not changed the rail type in the route file after ‘fading out‘).
The next job is to modify the ballast in a similar way, using a modified DL_BALLAST.BMP image as the texture. The ballast on both the left and right of the track will need altering by changing both instances of:
1 |
load dl_ballast.bmp |
To:
1 |
load dl_ballast_fade_in.bmp |
Then modify the texture coordinates by changing each section to this (Ballast on the left and right of the track is identical!):
1 2 3 4 5 6 7 8 9 10 11 12 |
coordinates 0, 1, 1.0 coordinates 1, 0, 1.0 coordinates 2, 1, 0.8 coordinates 3, 0, 0.8 coordinates 4, 1, 0.6 coordinates 5, 0, 0.6 coordinates 6, 1, 0.4 coordinates 7, 0, 0.4 coordinates 8, 1, 0.2 coordinates 9, 0, 0.2 coordinates 10, 1, 0 coordinates 11, 0, 0 |
Darkening the rails is also required. Unfortunately, the Switch generated track does not lend itself well to lighting effects such as we have applied to the ballast and track textures as it is composed of multiple faces which are all of a single colour. We could rebuild the object so that we can apply different colours for each face of the rail, however, in practice, the rails will still appear quite light in comlour because they are inherently bright and shiny and will be illuminated by the train headlights. We will therefore only decrease the brightness of the rails by a relatively small amount, altering the command (Remember to change both rails!):
1 |
color 180,190,200 |
To:
1 |
color 130,140,150 |
If we view the route now, the shading effects for the tunnel entrance are now complete. The small amount of grass evident on the right hand side will be covered up when we create the ground which will form the hill through which the tunnel passes.
Now for the mid-section of the tunnel. Firstly, we need to create the rail object by copying DL_STRAIGHT_TUNNEL_ENTRANCE.B3D and renaming it to DL_STRAIGHT_TUNNEL_MID.B3D. This needs to be indexed in the route file as rail 22:
1 |
.Rail(22) DLTUTORIAL\DL_STRAIGHT_TUNNEL_MID.b3d, |
This rail type should then be started at 275m:
1 |
275,.freeobj 0;51,.railtype 0;22,.railtype 1;22, |
Our next job is to create a track and ballast textures which are suitably darkened for use in the middle 50metres of the tunnel. To create these, we can use any suitable image editor to darken tiled images of the track and ballast so that they match the end of the entrance section. Suitable darkened textures have been included in the objects download – DL_STRAIGHT_DARK and DL_BALLAST_DARK. These need to be included in the rail object by changing:
1 |
load dl_track3_fade_in.bmp |
To:
1 |
load DL_STRAIGHT_DARK.bmp |
You also need to change both occurrences of this:
1 |
load dl_ballast_fade_in.bmp |
To this:
1 |
load DL_BALLAST_DARK.bmp |
The final task for the middle section of the tunnel track is to reduce the brightness of the rails slightly further by changing for both rails:
1 |
color 130,140,150 |
To:
1 |
color 100,100,110 |
That’s the middle section of the tunnel completed. All we need to do now is brighten the track as we approach the tunnel exit. To do this, we firstly need to create a new rail object by copying DL_STRAIGHT_TUNNEL_ENTRANCE.B3D and renaming it to DL_STRAIGHT_TUNNEL_EXIT.B3D before indexing this as rail 23 in the route file;
1 |
.Rail(23) DLTUTORIAL\DL_STRAIGHT_TUNNEL_EXIT.b3d, |
This rail type will commence at 325metres, like this:
1 |
325,.freeobj 0;52,.railtype 0;23,.railtype 1;23, |
To change the brightness from fading into shadow, we can either use mirror images of the ballast and track textures (as we did for the wall) or display the existing ones as mirror images by altering the coordinates commands in the object file.
Choosing the latter option, change this:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
load dl_track3_fade_in.bmp coordinates 0, 1.02, 1.0 coordinates 1, -0.02, 1.0 coordinates 2, 1.02, 0.8 coordinates 3, -0.02, 0.8 coordinates 4, 1.02, 0.6 coordinates 5, -0.02, 0.6 coordinates 6, 1.02, 0.4 coordinates 7, -0.02, 0.4 coordinates 8, 1.02, 0.2 coordinates 9, -0.02, 0.2 coordinates 10, 1.02, 0 coordinates 11, -0.02, 0 |
To look like this:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
load dl_track3_fade_in.bmp coordinates 0, 1.02, 0.0 coordinates 1, -0.02, 0.0 coordinates 2, 1.02, 0.2 coordinates 3, -0.02, 0.2 coordinates 4, 1.02, 0.4 coordinates 5, -0.02, 0.4 coordinates 6, 1.02, 0.6 coordinates 7, -0.02, 0.6 coordinates 8, 1.02, 0.8 coordinates 9, -0.02, 0.8 coordinates 10, 1.02, 1.0 coordinates 11, -0.02, 1.0 |
Similarly, both occurances of the ballast co-ordinates must be changed from this:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
load dl_ballast_fade_in.bmp coordinates 0, 1, 1.0 coordinates 1, 0, 1.0 coordinates 2, 1, 0.8 coordinates 3, 0, 0.8 coordinates 4, 1, 0.6 coordinates 5, 0, 0.6 coordinates 6, 1, 0.4 coordinates 7, 0, 0.4 coordinates 8, 1, 0.2 coordinates 9, 0, 0.2 coordinates 10, 1, 0.0 coordinates 11, 0, 0.0 |
To look like this:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
load dl_ballast_fade_in.bmp coordinates 0, 1, 0.0 coordinates 1, 0, 0.0 coordinates 2, 1, 0.2 coordinates 3, 0, 0.2 coordinates 4, 1, 0.4 coordinates 5, 0, 0.4 coordinates 6, 1, 0.6 coordinates 7, 0, 0.6 coordinates 8, 1, 0.8 coordinates 9, 0, 0.8 coordinates 10, 1, 1.0 coordinates 11, 0, 1.0 |
That’s construction of the tunnel complete although there are a couple modifications still needed to the route file. The first of these is to define the run sounds associated with the rails which are used in the tunnel. This is done by adding these to the route file:
1 2 3 4 |
Train.Run(20) 3, Train.Run(21) 3, Train.Run(22) 3, Train.Run(23) 3, |
Now the train run sounds reflect the fact that we are passing through a tunnel.
The final job is to change the cab brightness using the brightness command;
.BRIGHTNESS (X)
Where X may be between 1 (very dark) and 255 (very light).
When using brightness commands, it is important to realise that the cab lighting will follow a static gradient between two brightness commands. In other words, if we set brightness 1 at position 0, and brightness 255 at position 200, then the brightness level will move gradually from dark to light between these two commands.
We therefore need to set the cab brightness at the start of the route, at the start of the tunnel, at the mid-point of the tunnel and at the tunnel exit.
To do this, we need to add the following code to the route file
1 |
0,.Ground 1,.back 0,.railtype 0;1,.sta yourname1; 09.2720;09.2805;;1;1;;;7;10;;0,.railstart 1;3.5;0;1,.brightness 240, |
This defines the brightness at the start of the route.
Secondly, add:
1 |
250,.freeobj 0;50,.railtype 0;21,.railtype 1;21,.brightness 240, |
This ensures the cab brightness remains at a constant 240 between the start of the route and the tunnel entrance.
Next add this:
1 |
275,.freeobj 0;51,.railtype 0;22,.railtype 1;22,.brightness 100, |
This fades the cab brightness concurrent with the shading of the wall and track textures.
Then this:
1 |
325,.freeobj 0;52,.railtype 0;23,.railtype 1;23,.brightness 100, |
This holds the cab brightness at a low level as the middle section of the tunnel is traversed.
This is our final bit of code:
1 |
350,.curve 2000;2,.railtype 0;15,.railtype 1;15,.brightness 240, |
This increases the cab brightness as the tunnel exit is approached.
The tunnel itself is now complete – in the next tutorial, we will make a start creating the hill over the top of the tunnel.