I did the following in BasicRoadsTexturing.ScheduleAssignTilesJob() (get tileData from Interesting Terrains, and comment out GenerateTileDataJob):
Code: Select all
// Get tileData from Interesting Terrains
byte[] tData = null;
ModManager.Instance.SendModMessage("Interesting Terrains", "getTileData", new int[] { mapData.mapPixelX, mapData.mapPixelY }, (string message, object data) =>
{
if (message == "error")
{
// Should never result in error if used in a TerrainTexturer, and two ints are supplied to the message request
Debug.LogError(data as string);
}
else
{
tData = data as byte[];
}
});
// Assign byte data directly to native array
NativeArray<byte> tileData = new NativeArray<byte>(tData, Allocator.TempJob);
// Following block disabled:
/*NativeArray<byte> tileData = new NativeArray<byte>(tileDataDim * tileDataDim, Allocator.TempJob);
GenerateTileDataJob tileDataJob = new GenerateTileDataJob
{
heightmapData = mapData.heightmapData,
tileData = tileData,
tdDim = tileDataDim,
hDim = terrainSampler.HeightmapDimension,
maxTerrainHeight = terrainSampler.MaxTerrainHeight,
oceanElevation = terrainSampler.OceanElevation,
beachElevation = terrainSampler.BeachElevation,
mapPixelX = mapData.mapPixelX,
mapPixelY = mapData.mapPixelY,
};
JobHandle tileDataHandle = tileDataJob.Schedule(tileDataDim * tileDataDim, 64, dependencies);*/
Code: Select all
NativeArray<byte> lookupData = new NativeArray<byte>(lookupTable, Allocator.TempJob);
AssignTilesWithRoadsJob assignTilesJob = new AssignTilesWithRoadsJob
{
(...)
};
// Disabled: JobHandle assignTilesHandle = assignTilesJob.Schedule(assignTilesDim * assignTilesDim, 64, tileDataHandle);
// Schedule job as normal, but with default dependencies
JobHandle assignTilesHandle = assignTilesJob.Schedule(assignTilesDim * assignTilesDim, 64, dependencies);
I'll need to do additional smoothing at a larger scale to prevent stuff like this from happening:
The objectively better approach would be if it was somehow possible to handle the smoothing during heightmap sampling.
Edit: I've studied the road networks and found out that they're assumedly much simpler than I expected; my assumption is that a map tile's road/path data byte is a set of flags for each corner and edge center of the terrain object, and for each flag that's true a path is drawn at a straight line from its corresponding edge point to the center of the terrain. If my assumption is correct, that's extremely good news! It is fully possible to use that info in the shader to find the nearest road point, AND it minimizes the amount of data that needs to be pre-processed on the CPU before dispatching it to the GPU