EasyRoads3D v3 - the upcoming new road system (Part 2)

Hi frankadimcosta,

Good to hear that this is working now!

Just for optimization, currently in the code you posted the road object is refreshed after each marker is added. Since in this specific case all markers are added one by one you may want to use:

Road.AddMarker(Points[t].position, false);

The road object will not update after adding each road marker. Roads.Refresh() in your code will take care of that after adding all the road markers.

Thanks,
Raoul

1 Like

Thanks !

Building the scene i got this error.

"Shader error in ā€˜EasyRoads3D/Legacy/Terrain/ER Terrain Mesh Tesselationā€™: maximum ps_5_0 sampler register index (16) exceeded at Tesselation.shader(149) (on d3d11)

Compiling Subshader: 0, Pass: FORWARD, Fragment program with SHADOWS_DEPTH SHADOWS_SOFT SPOT
Platform defines: SHADER_API_DESKTOP UNITY_ENABLE_DETAIL_NORMALMAP UNITY_ENABLE_REFLECTION_BUFFERS UNITY_LIGHTMAP_FULL_HDR UNITY_LIGHT_PROBE_PROXY_VOLUME UNITY_PASS_FORWARDADD UNITY_PBS_USE_BRDF1 UNITY_PLATFORM_SUPPORTS_DEPTH_FETCH UNITY_SPECCUBE_BLENDING UNITY_SPECCUBE_BOX_PROJECTION UNITY_USE_DITHER_MASK_FOR_ALPHABLENDED_SHADOWS
Disabled keywords: DIRECTIONAL DIRECTIONAL_COOKIE FOG_EXP FOG_EXP2 FOG_LINEAR LIGHTMAP_SHADOW_MIXING POINT POINT_COOKIE SHADER_API_GLES30 SHADOWS_CUBE SHADOWS_SCREEN SHADOWS_SHADOWMASK UNITY_ASTC_NORMALMAP_ENCODING UNITY_COLORSPACE_GAMMA UNITY_FRAMEBUFFER_FETCH_AVAILABLE UNITY_HARDWARE_TIER1 UNITY_HARDWARE_TIER2 UNITY_HARDWARE_TIER3 UNITY_LIGHTMAP_DLDR_ENCODING UNITY_LIGHTMAP_RGBM_ENCODING UNITY_METAL_SHADOWS_USE_POINT_FILTERING UNITY_NO_DXT5nm UNITY_NO_SCREENSPACE_SHADOWS UNITY_PBS_USE_BRDF2 UNITY_PBS_USE_BRDF3 UNITY_PRETRANSFORM_TO_DISPLAY_ORIENTATION UNITY_UNIFIED_SHADER_PRECISION_MODEL UNITY_VIRTUAL_TEXTURING"

Now i can create all roads in the editor. Code uses the children of the selected object in the inspector.
I have to improve the code, but it works ! THANKS Raul !

[MenuItem("Tools/AFC82/Build RailNetwork by Point Container")]
public static void BuildRailNetworkbyPointContainer()
{
    ERRoadNetwork MyERRoadNetwork=new ERRoadNetwork();
    int PointsToImportOffset = 0;
    GameObject PointsContainer = Selection.activeGameObject; ;
    Transform [] ts = PointsContainer.transform.GetComponentsInChildren<Transform>();
    Debug.Log(ts.Length);
    int PointsToImport = 100; // lughezza tratto
    if (PointsToImport > ts.Length)
        PointsToImport = ts.Length;
    Vector3[] markers;
    bool PreviousMyERRoadIsValid=false;
    Vector3 PreviousMyERRoadFinalMarker = Vector3.zero;
    ERRoad PreviousMyERRoad;
    ERRoad MyERRoad;


    ERRoadType roadType = new ERRoadType();
    roadType = MyERRoadNetwork.GetRoadTypeByName("Train Rail");

    while (PointsToImportOffset < ts.Length)
    {
        if (ts.Length - PointsToImportOffset < PointsToImport)
            PointsToImport = ts.Length - PointsToImportOffset;

        markers = new Vector3[PointsToImport + 1];

        if (PreviousMyERRoadIsValid)
        {
            markers[0] = PreviousMyERRoadFinalMarker;
        }
        else
            markers[0] = ts[0].transform.position;


        for (int i = 0; i < PointsToImport; i++)
        {
            if (ts[PointsToImportOffset].position != Vector3.zero)
            {
                markers[i + 1] = ts[PointsToImportOffset].position;
                PreviousMyERRoadFinalMarker = ts[PointsToImportOffset].position;
            }
            else
                markers[i + 1] = PreviousMyERRoadFinalMarker;
            PointsToImportOffset++;
        }


        MyERRoad = MyERRoadNetwork.CreateRoad("Ferrovia " + PointsToImportOffset, roadType, markers);
        PreviousMyERRoad = MyERRoad;
        PreviousMyERRoadIsValid = true;


        Debug.Log(PointsToImportOffset);

    }




    ERRoad[] AllRoads = MyERRoadNetwork.GetRoadObjects();

    bool RoadsSetTerrainDeformation = false;
    bool RoadsSetSplatmap = false;
    bool RoadsSnapToTerrain = false;
    bool RoadsFollowTerrainContours = false;
    float RoadsFollowTerrainContourThreshold = 2.0f;
    

    for (int i = 0; i < AllRoads.Length; i++)
    {
        //  AllRoads[i].SetSidewalk(MyERRoadSide, RoadsSetSidewalk);
        AllRoads[i].SetTerrainDeformation(RoadsSetTerrainDeformation);
        AllRoads[i].SetSplatmap(RoadsSetSplatmap);
        //if (RoadsSideObjectSetActive) AllRoads[i].SideObjectSetActive(SO, true);
        AllRoads[i].SnapToTerrain(RoadsSnapToTerrain);
        AllRoads[i].FollowTerrainContours(RoadsFollowTerrainContours);
        AllRoads[i].FollowTerrainContourThreshold(RoadsFollowTerrainContourThreshold);
    }

    AllRoads = MyERRoadNetwork.GetRoadObjects();
    AllRoads[AllRoads.Length - 1].ClosedTrack(false);
    for (int i = 0; i < AllRoads.Length; i++)
        AllRoads[i].Refresh();

    //MyERRoadNetwork.BuildRoadNetwork(RoadsSetSplatmap, false, false, false);
    //MyERRoadNetwork.UpdateTerrainInfo();

}

Yes, that indeed seems the way to go for your situation, generate this through the scripting API by, for example, adding a menu item to the Unity editor main menu.

Regarding the shader error message in the other post, this is an older shader used for terrain mesh overlays in the older v3.1 demo scene. It is a more complex shader used on a mesh for which the main purpose is to show how side objects can be generated as terrain detail objects which can be useful in hilly areas. The shader is more complex and can indeed cause the specific error depending on the build platform. In that case, please remove this shader from /Assets/EasyRoads3D/Shaders/Legacy/Misc/. This folder includes a similar but less complex version in case you want to use a shader like this but as mentioned it is an older shader, Unity built-in render pipeline only.

Thanks,
Raoul

1 Like

The error is:
ā€œShader error in ā€˜EasyRoads3D/Legacy/Terrain/ER Terrain Mesh Tesselationā€™: maximum ps_5_0 sampler register index (16) exceeded at Tesselation.shader(149) (on d3d11)ā€

Do you confirm I have to remove another file ?

Thanks for support !

The link in the error message points to the shader path that is visible in the Inspector of the specific material, this path is defined at the top of the shader source and visible when opening the specific shader file.

This path is unrelated to the actual physical location of the shader file in the project folder, which is:

/Assets/EasyRoads3D/Shaders/Legacy/Misc/

And the specific shader file name in this folder is ā€œER Terrain Mesh Tesselationā€. That is the file/asset that can be removed.

Thanks,
Raoul

Sorry for the misunderstanding !

Thanks a lot !

1 Like

I have a strange behaviour.
The complete train rail road (Bologna-Milano) scene is large 7.3 GB on disk .
I tried to reduce the size removing all ā€œtrainConcreteā€ gamebjects.
Finalizing command donā€™t remove them it, nor ā€œbatchā€ gameobjects.
All seem working ā€¦
After this, size is less than 3 GB on disk.

Hi frankadimcosta,

What is the distance between Bologna and Milano?

Can you check the status of ā€œCombineā€ for this specific ā€œTrain Rail Concreteā€ side object in the Side Object Manager? You will find it further below in the Inspector. When ā€œCombineā€ is active all instances will be combined in batches in a single mesh inside the scene. When ā€œCombineā€ is not active these objects will all be instances of the prefab in the project folder which should reduce the size significantly in your case.

Thanks,
Raoul

High speed train route, 257 Km.
Itā€™s a huge map.
The ā€œTrain Rail Concreteā€ are combined.
The children ā€œtrainConcreteā€ inside "batch x"gameobjects are still present.
and if I deleted, are still visible (ā€œBox01matā€ combined mesh i think).
Also ā€œRailRoadMetalPlateā€ have this behaviour.
trainConcrete and RailRoadMetalPlate are still present after finalizing road network.

I tested another train route, 95Km long:

  1. using combined and DELETED trainConcrete and RailRoadMetalPlate, size is 1,2 GB
  2. using not combined trainConcrete and RailRoadMetalPlate, size is 1 GB.
    Obviously worse performance. (from -25% to -40% fps)

TNX for support !

257km will result in a huge mesh when all instances are combined

These are assets in the Demo package which are primary intended for learning purposes to show for example side objects can be used in different ways. You may want to do further tests, for example create LOD Groups for the specific prefab, and not render it at all from a certain distance.

We will look in these children still being present when ā€œCombineā€ is used. For sure that will be required when for example Box Colliders are involved but that is probably not the case here.

Thanks,
Raoul

I have separate roads 5km long.

Yes, I should have written a large amount of combined meshes because in this situation the meshes will be created in batches anyway due to the max vertex limitation in Unity (and various build platforms) per mesh object. That is not the case when using instances of the original prefab in the project folder.

Hi,

I have a strange behavior on my unique small road. My project is under Unity 6000, and EasyRoad 3.2 Pro. On a flat terrain, I created a simple road, and, when running the scene, i walk my avatar to the road, and the road progressively disappears (shrinks).

On first screenshot, road is just after the first house. My avatar is running to the road.

My avatar still walks to the road, but the road shrinksā€¦

And so on, to the end of the roadā€¦

My settings are quite simple :

Any idea ?

Sylvain

Hi sylvain,

What is the ā€œRaiseā€ value of the road network in Build Mode?

The EasyRoads3D shaders have an offset option to deal with Z-fighting with the terrain, the offset strength can be set in the road material.

This offset becomes progressively stronger further away from the cam which can be useful to deal with the terrain LOD system. It seems that is what is happening in your scene. Near the cam the terrain is rendered on top of the road, further away the road renders on top of the terrain because of the stronger offset.

A ā€œRaiseā€ value of 0.01 or 0.02 should be enough to make the road render on top of the terrain also near the cam.

Thanks,
Raoul

Hi Raoul,

Thanks to your very quick reply. But where is the ā€œRaiseā€ value, in ā€œRoad Networkā€ inspector ? I have not seen such field.

For the camera : it is attached to the avatar, in his back. I just need that my avatar can walk on the road.

Sylvain

Hi Sylvain,

It seems you are looking at this with the road network in Edit Mode, is that correct?

Press the middle mountain tab of the EasyRoads3D toolbar visible in the screenshot you posted. After that press the ā€œBuild Terrain(s)ā€ button. This will put the road network in Build Mode with the terrain adjusted to match the road network and you will see the ā€œRaiseā€ control. Probably at this moment the issue is already fixed because the default value for ā€œRaiseā€ is 0.02.

Thanks,
Raoul

Hi Raul.
Can you help me, please ?
Iā€™m traying to connect 2 ERRoad by code using ConnectRoad, but i get error:
ā€œNullReferenceException: Object reference not set to an instance of an object
EasyRoads3Dv3.ODODCOQODD.JoinRoads (System.Collections.Generic.List`1[EasyRoads3Dv3.SelectedObject]& objects, EasyRoads3Dv3.ERModularRoad& road, System.Int32& marker) (at <36f3e32e9182460a909544e4a6e0f589>:0)
EasyRoads3Dv3.ERRoadNetwork.ConnectRoads (EasyRoads3Dv3.ERRoad road1, EasyRoads3Dv3.ERRoad road2) (at <36f3e32e9182460a909544e4a6e0f589>:0)ā€

Hello frankadimcosta,

Unfortunately it is impossible to give feedback with the current info. What is the exact status of these two road objects? Given previous conversations, how were these road objects created? How can we recreate this error?

And also given previous conversation, do you actually want to use ConnectRoads() which will merge the two road objects in one, or do you want to insert an I Connector between the two road objects for a smooth curve between the two road objects?

Thanks,
Raoul

Thanks for reply. I only need to join two near erroads (train rails).
But if joining will impact on vertex limit of the resulting mesh I think iā€™s better to insert an I connector.
Iā€™m building a long rail tran route by code and i need to improve looking of the connecting roads.
Iā€™d like a code to mimic the join command in editor
(" Roads of the same road type can be connected by selecting the two markers that should connect (hold the Shift key when selecting the marker) and pressing the ā€œJoin Selected Roadsā€ button in the Inspector or Shift + J.")