Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions Game/Addons/IncreasedTerrainDistanceMod.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions Game/Addons/IncreasedTerrainDistanceMod/Prefabs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions Game/Addons/IncreasedTerrainDistanceMod/Resources.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions Game/Addons/IncreasedTerrainDistanceMod/Scripts.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//Increased Terrain Distance Mod for Daggerfall Tools For Unity
//http://www.reddit.com/r/dftfu
//http://www.dfworkshop.net/
//Author: Michael Rauter (a.k.a. Nystul)
//License: MIT License (http://www.opensource.org/licenses/mit-license.php)
//Version: 1.54

using UnityEngine;
//using System;
//using System.Collections;
//using System.Collections.Generic;
//using System.IO;
//using DaggerfallConnect;
//using DaggerfallConnect.Arena2;
//using DaggerfallConnect.Utility;
//using DaggerfallWorkshop;
using DaggerfallWorkshop.Game;
//using DaggerfallWorkshop.Utility;

namespace ProjectIncreasedTerrainDistance
{
public class CloneCameraPositionFromMainCamera : MonoBehaviour
{
void LateUpdate()
{
this.transform.position = Camera.main.transform.position;
}

}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//Increased Terrain Distance Mod for Daggerfall Tools For Unity
//http://www.reddit.com/r/dftfu
//http://www.dfworkshop.net/
//Author: Michael Rauter (a.k.a. Nystul)
//License: MIT License (http://www.opensource.org/licenses/mit-license.php)
//Version: 1.54

using UnityEngine;
//using System;
//using System.Collections;
//using System.Collections.Generic;
//using System.IO;
//using DaggerfallConnect;
//using DaggerfallConnect.Arena2;
//using DaggerfallConnect.Utility;
//using DaggerfallWorkshop;
using DaggerfallWorkshop.Game;
//using DaggerfallWorkshop.Utility;

namespace ProjectIncreasedTerrainDistance
{
public class CloneCameraRotationFromMainCamera : MonoBehaviour
{
void LateUpdate()
{
this.transform.rotation = Camera.main.transform.rotation;
}

}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
//Increased Terrain Distance Mod for Daggerfall Tools For Unity
//http://www.reddit.com/r/dftfu
//http://www.dfworkshop.net/
//Author: Michael Rauter (a.k.a. Nystul)
//License: MIT License (http://www.opensource.org/licenses/mit-license.php)
//Version: 1.54

using UnityEngine;
using System;
using System.Collections;
using DaggerfallConnect;
using DaggerfallConnect.Arena2;
using DaggerfallWorkshop;
using DaggerfallWorkshop.Utility;
using ProjectIncreasedTerrainDistance;

//namespace DaggerfallWorkshop
namespace ProjectIncreasedTerrainDistance
{
/// <summary>
/// Default TerrainSampler for StreamingWorld.
/// </summary>
public class ImprovedTerrainSampler : TerrainSampler
{
// Scale factors for this sampler implementation
public const float baseHeightScale = 8f;
public const float noiseMapScale = 4f;
public const float extraNoiseScale = 3f;
public const float scaledOceanElevation = 3.4f * baseHeightScale;
public const float scaledBeachElevation = 5.0f * baseHeightScale;

// Max terrain height of this sampler implementation
public const float maxTerrainHeight = 26115f;

public ImprovedTerrainSampler()
{
HeightmapDimension = defaultHeightmapDimension;
MaxTerrainHeight = maxTerrainHeight;
OceanElevation = scaledOceanElevation;
BeachElevation = scaledBeachElevation;
}

public override void GenerateSamples(ref MapPixelData mapPixel)
{
DaggerfallUnity dfUnity = DaggerfallUnity.Instance;

// Create samples arrays
mapPixel.tilemapSamples = new TilemapSample[MapsFile.WorldMapTileDim, MapsFile.WorldMapTileDim];
mapPixel.heightmapSamples = new float[HeightmapDimension, HeightmapDimension];

// Divisor ensures continuous 0-1 range of tile samples
float div = (float)(HeightmapDimension - 1) / 3f;

// Read neighbouring height samples for this map pixel
int mx = mapPixel.mapPixelX;
int my = mapPixel.mapPixelY;
byte[,] shm = dfUnity.ContentReader.WoodsFileReader.GetHeightMapValuesRange(mx - 2, my - 2, 4);
byte[,] lhm = dfUnity.ContentReader.WoodsFileReader.GetLargeHeightMapValuesRange(mx - 1, my, 3);

float[,] multiplierValue = new float[4, 4];
for (int y = 0; y < 4; y++)
{
for (int x = 0; x < 4; x++)
{
int mapPixelX = Math.Max(0, Math.Min(mx + x - 2, WoodsFile.mapWidthValue));
int mapPixelY = Math.Max(0, Math.Min(my + y - 2, WoodsFile.mapHeightValue));

multiplierValue[x, y] = ImprovedWorldTerrain.computeHeightMultiplier(mapPixelX, mapPixelY);
}
}

// Extract height samples for all chunks
float averageHeight = 0;
float maxHeight = float.MinValue;
float baseHeight, noiseHeight;
float x1, x2, x3, x4;
int dim = HeightmapDimension;
//mapPixel.heightmapSamples = new float[dim, dim];
for (int y = 0; y < dim; y++)
{
for (int x = 0; x < dim; x++)
{
float rx = (float)x / div;
float ry = (float)y / div;
int ix = Mathf.FloorToInt(rx);
int iy = Mathf.FloorToInt(ry);
float sfracx = (float)x / (float)(dim - 1);
float sfracy = (float)y / (float)(dim - 1);
float fracx = (float)(x - ix * div) / div;
float fracy = (float)(y - iy * div) / div;
float scaledHeight = 0;

// Bicubic sample small height map for base terrain elevation
x1 = TerrainHelper.CubicInterpolator(shm[0, 3] * multiplierValue[0, 3], shm[1, 3] * multiplierValue[1, 3], shm[2, 3] * multiplierValue[2, 3], shm[3, 3] * multiplierValue[3, 3], sfracx);
x2 = TerrainHelper.CubicInterpolator(shm[0, 2] * multiplierValue[0, 2], shm[1, 2] * multiplierValue[1, 2], shm[2, 2] * multiplierValue[2, 2], shm[3, 2] * multiplierValue[3, 2], sfracx);
x3 = TerrainHelper.CubicInterpolator(shm[0, 1] * multiplierValue[0, 1], shm[1, 1] * multiplierValue[1, 1], shm[2, 1] * multiplierValue[2, 1], shm[3, 1] * multiplierValue[3, 1], sfracx);
x4 = TerrainHelper.CubicInterpolator(shm[0, 0] * multiplierValue[0, 0], shm[1, 0] * multiplierValue[1, 0], shm[2, 0] * multiplierValue[2, 0], shm[3, 0] * multiplierValue[3, 0], sfracx);
baseHeight = TerrainHelper.CubicInterpolator(x1, x2, x3, x4, sfracy);
scaledHeight += baseHeight * baseHeightScale;

// Bicubic sample large height map for noise mask over terrain features
x1 = TerrainHelper.CubicInterpolator(lhm[ix, iy + 0], lhm[ix + 1, iy + 0], lhm[ix + 2, iy + 0], lhm[ix + 3, iy + 0], fracx);
x2 = TerrainHelper.CubicInterpolator(lhm[ix, iy + 1], lhm[ix + 1, iy + 1], lhm[ix + 2, iy + 1], lhm[ix + 3, iy + 1], fracx);
x3 = TerrainHelper.CubicInterpolator(lhm[ix, iy + 2], lhm[ix + 1, iy + 2], lhm[ix + 2, iy + 2], lhm[ix + 3, iy + 2], fracx);
x4 = TerrainHelper.CubicInterpolator(lhm[ix, iy + 3], lhm[ix + 1, iy + 3], lhm[ix + 2, iy + 3], lhm[ix + 3, iy + 3], fracx);
noiseHeight = TerrainHelper.CubicInterpolator(x1, x2, x3, x4, fracy);
scaledHeight += noiseHeight * noiseMapScale;

// Additional noise mask for small terrain features at ground level
int noisex = mapPixel.mapPixelX * (HeightmapDimension - 1) + x;
int noisey = (MapsFile.MaxMapPixelY - mapPixel.mapPixelY) * (HeightmapDimension - 1) + y;
float lowFreq = TerrainHelper.GetNoise(noisex, noisey, 0.3f, 0.5f, 0.5f, 1);
float highFreq = TerrainHelper.GetNoise(noisex, noisey, 0.9f, 0.5f, 0.5f, 1);
scaledHeight += (lowFreq * highFreq) * extraNoiseScale;

// Clamp lower values to ocean elevation
if (scaledHeight < scaledOceanElevation)
scaledHeight = scaledOceanElevation;

// Accumulate average height
averageHeight += scaledHeight;

// Get max height
if (scaledHeight > maxHeight)
maxHeight = scaledHeight;

// Set sample
float height = Mathf.Clamp01(scaledHeight / MaxTerrainHeight);
mapPixel.heightmapSamples[y, x] = height;
}
}

// Average and max heights are passed back for locations
mapPixel.averageHeight = (averageHeight /= (float)(dim * dim)) / MaxTerrainHeight;
mapPixel.maxHeight = maxHeight / MaxTerrainHeight;
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading