mirror of
https://github.com/Outer-Wilds-New-Horizons/new-horizons.git
synced 2025-12-11 20:15:44 +01:00
Clean up tiles
This commit is contained in:
parent
79dd968e33
commit
76a0dd9f42
@ -14,103 +14,40 @@ namespace NewHorizons.Builder.Body
|
|||||||
{
|
{
|
||||||
public static Shader PlanetShader;
|
public static Shader PlanetShader;
|
||||||
|
|
||||||
|
// I hate nested functions okay
|
||||||
|
private static IModBehaviour _currentMod;
|
||||||
|
private static string _currentPlanetName;
|
||||||
|
|
||||||
public static GameObject Make(GameObject planetGO, Sector sector, HeightMapModule module, IModBehaviour mod, int resolution, bool useLOD = false)
|
public static GameObject Make(GameObject planetGO, Sector sector, HeightMapModule module, IModBehaviour mod, int resolution, bool useLOD = false)
|
||||||
{
|
{
|
||||||
// Only delete heightmap if it hasn't been loaded yet
|
bool deleteHeightmapFlag;
|
||||||
var deleteHeightmapFlag = !string.IsNullOrEmpty(module.heightMap) && !ImageUtilities.IsTextureLoaded(mod, module.heightMap);
|
|
||||||
|
|
||||||
Texture2D heightMap;
|
Texture2D heightMap, textureMap, smoothnessMap, normalMap, emissionMap, tileBlendMap;
|
||||||
Texture2D textureMap;
|
|
||||||
Texture2D smoothnessMap;
|
|
||||||
Texture2D normalMap;
|
|
||||||
Texture2D emissionMap;
|
|
||||||
Texture2D tileBlendMap = null;
|
|
||||||
|
|
||||||
Texture2D baseTextureTile = null;
|
Tile baseTile, redTile, greenTile, blueTile, alphaTile;
|
||||||
Texture2D baseSmoothnessTile = null;
|
|
||||||
Texture2D baseNormalTile = null;
|
|
||||||
|
|
||||||
Texture2D redTextureTile = null;
|
_currentMod = mod;
|
||||||
Texture2D redSmoothnessTile = null;
|
_currentPlanetName = planetGO.name;
|
||||||
Texture2D redNormalTile = null;
|
|
||||||
|
|
||||||
Texture2D greenTextureTile = null;
|
|
||||||
Texture2D greenSmoothnessTile = null;
|
|
||||||
Texture2D greenNormalTile = null;
|
|
||||||
|
|
||||||
Texture2D blueTextureTile = null;
|
|
||||||
Texture2D blueSmoothnessTile = null;
|
|
||||||
Texture2D blueNormalTile = null;
|
|
||||||
|
|
||||||
Texture2D alphaTextureTile = null;
|
|
||||||
Texture2D alphaSmoothnessTile = null;
|
|
||||||
Texture2D alphaNormalTile = null;
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Texture2D Load(string path, string name, bool linear)
|
|
||||||
{
|
|
||||||
if (string.IsNullOrEmpty(path)) return null;
|
|
||||||
if (!File.Exists(Path.Combine(mod.ModHelper.Manifest.ModFolderPath, path)))
|
|
||||||
{
|
|
||||||
NHLogger.LogError($"Bad path for {planetGO.name} {name}: {path} couldn't be found.");
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (name != "heightMap" && path == module.heightMap)
|
|
||||||
{
|
|
||||||
// If another texture uses the heightMap then don't delete it
|
|
||||||
deleteHeightmapFlag = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return ImageUtilities.GetTexture(mod, path, wrap: true, linear: linear);
|
|
||||||
}
|
|
||||||
|
|
||||||
heightMap = Load(module.heightMap, "heightMap", false) ?? Texture2D.whiteTexture;
|
|
||||||
textureMap = Load(module.textureMap, "textureMap", false) ?? Texture2D.whiteTexture;
|
textureMap = Load(module.textureMap, "textureMap", false) ?? Texture2D.whiteTexture;
|
||||||
smoothnessMap = Load(module.smoothnessMap, "smoothnessMap", false);
|
smoothnessMap = Load(module.smoothnessMap, "smoothnessMap", false);
|
||||||
normalMap = Load(module.normalMap, "normalMap", true);
|
normalMap = Load(module.normalMap, "normalMap", true);
|
||||||
emissionMap = Load(module.emissionMap, "emissionMap", false);
|
emissionMap = Load(module.emissionMap, "emissionMap", false);
|
||||||
|
|
||||||
if (useLOD)
|
baseTile = new Tile(module.baseTile, "BASE_TILE", "_BaseTile");
|
||||||
{
|
redTile = new Tile(module.baseTile, "RED_TILE", "_RedTile");
|
||||||
tileBlendMap = Load(module.tileBlendMap, "tileBlendMap", false);
|
greenTile = new Tile(module.baseTile, "GREEN_TILE", "_GreenTile");
|
||||||
if (module.baseTile != null)
|
blueTile = new Tile(module.baseTile, "BLUE_TILE", "_BlueTile");
|
||||||
{
|
alphaTile = new Tile(module.baseTile, "ALPHA_TILE", "_AlphaTile");
|
||||||
baseTextureTile = Load(module.baseTile.textureTile, "baseTile textureTile", false);
|
|
||||||
baseSmoothnessTile = Load(module.baseTile.smoothnessTile, "baseTile smoothnessTile", false);
|
|
||||||
baseNormalTile = Load(module.baseTile.normalTile, "baseTile normalTile", true);
|
|
||||||
}
|
|
||||||
if (module.redTile != null)
|
|
||||||
{
|
|
||||||
redTextureTile = Load(module.redTile.textureTile, "redTile textureTile", false);
|
|
||||||
redSmoothnessTile = Load(module.redTile.smoothnessTile, "redTile smoothnessTile", false);
|
|
||||||
redNormalTile = Load(module.redTile.normalTile, "redTile normalTile", true);
|
|
||||||
}
|
|
||||||
if (module.greenTile != null)
|
|
||||||
{
|
|
||||||
greenTextureTile = Load(module.greenTile.textureTile, "greenTile textureTile", false);
|
|
||||||
greenSmoothnessTile = Load(module.greenTile.smoothnessTile, "greenTile smoothnessTile", false);
|
|
||||||
greenNormalTile = Load(module.greenTile.normalTile, "greenTile normalTile", true);
|
|
||||||
}
|
|
||||||
if (module.blueTile != null)
|
|
||||||
{
|
|
||||||
blueTextureTile = Load(module.blueTile.textureTile, "blueTile textureTile", false);
|
|
||||||
blueSmoothnessTile = Load(module.blueTile.smoothnessTile, "blueTile smoothnessTile", false);
|
|
||||||
blueNormalTile = Load(module.blueTile.normalTile, "blueTile normalTile", true);
|
|
||||||
}
|
|
||||||
if (module.alphaTile != null)
|
|
||||||
{
|
|
||||||
alphaTextureTile = Load(module.alphaTile.textureTile, "alphaTile textureTile", false);
|
|
||||||
alphaSmoothnessTile = Load(module.alphaTile.smoothnessTile, "alphaTile smoothnessTile", false);
|
|
||||||
alphaNormalTile = Load(module.alphaTile.normalTile, "alphaTile normalTile", true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// If the texturemap is the same as the heightmap don't delete it #176
|
tileBlendMap = useLOD ? Load(module.tileBlendMap, "tileBlendMap", false) : null;
|
||||||
// Do the same with emissionmap
|
|
||||||
// todo? maybe do this with the other maps, if someone were to ever use heightmap for them (altho that wouldnt make any sense if they did)
|
// Only delete heightmap if it hasn't been loaded yet
|
||||||
if (textureMap == heightMap || emissionMap == heightMap) deleteHeightmapFlag = false;
|
deleteHeightmapFlag = !string.IsNullOrEmpty(module.heightMap) && !ImageUtilities.IsTextureLoaded(mod, module.heightMap);
|
||||||
|
|
||||||
|
heightMap = Load(module.heightMap, "heightMap", false) ?? Texture2D.whiteTexture;
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
@ -190,75 +127,13 @@ namespace NewHorizons.Builder.Body
|
|||||||
material.SetColor("_EmissionColor", emissionColor);
|
material.SetColor("_EmissionColor", emissionColor);
|
||||||
material.SetTexture("_EmissionMap", emissionMap);
|
material.SetTexture("_EmissionMap", emissionMap);
|
||||||
|
|
||||||
if (useTriplanar)
|
if (useTriplanar) material.SetTexture("_BlendMap", tileBlendMap);
|
||||||
{
|
|
||||||
material.SetTexture("_BlendMap", tileBlendMap);
|
baseTile.TryApplyTile(material, useTriplanar);
|
||||||
if (module.baseTile != null)
|
redTile.TryApplyTile(material, useTriplanar);
|
||||||
{
|
greenTile.TryApplyTile(material, useTriplanar);
|
||||||
material.EnableKeyword("BASE_TILE");
|
blueTile.TryApplyTile(material, useTriplanar);
|
||||||
material.SetFloat("_BaseTileScale", 1 / module.baseTile.size);
|
alphaTile.TryApplyTile(material, useTriplanar);
|
||||||
material.SetTexture("_BaseTileAlbedo", baseTextureTile);
|
|
||||||
material.SetTexture("_BaseTileSmoothnessMap", baseSmoothnessTile);
|
|
||||||
material.SetFloat("_BaseTileBumpStrength", module.baseTile.normalStrength);
|
|
||||||
material.SetTexture("_BaseTileBumpMap", baseNormalTile);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
material.DisableKeyword("BASE_TILE");
|
|
||||||
}
|
|
||||||
if (module.redTile != null)
|
|
||||||
{
|
|
||||||
material.EnableKeyword("RED_TILE");
|
|
||||||
material.SetFloat("_RedTileScale", 1 / module.redTile.size);
|
|
||||||
material.SetTexture("_RedTileAlbedo", redTextureTile);
|
|
||||||
material.SetTexture("_RedTileSmoothnessMap", redSmoothnessTile);
|
|
||||||
material.SetFloat("_RedTileBumpStrength", module.redTile.normalStrength);
|
|
||||||
material.SetTexture("_RedTileBumpMap", redNormalTile);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
material.DisableKeyword("RED_TILE");
|
|
||||||
}
|
|
||||||
if (module.greenTile != null)
|
|
||||||
{
|
|
||||||
material.EnableKeyword("GREEN_TILE");
|
|
||||||
material.SetFloat("_GreenTileScale", 1 / module.greenTile.size);
|
|
||||||
material.SetTexture("_GreenTileAlbedo", greenTextureTile);
|
|
||||||
material.SetTexture("_GreenTileSmoothnessMap", greenSmoothnessTile);
|
|
||||||
material.SetFloat("_GreenTileBumpStrength", module.greenTile.normalStrength);
|
|
||||||
material.SetTexture("_GreenTileBumpMap", greenNormalTile);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
material.DisableKeyword("GREEN_TILE");
|
|
||||||
}
|
|
||||||
if (module.blueTile != null)
|
|
||||||
{
|
|
||||||
material.EnableKeyword("BLUE_TILE");
|
|
||||||
material.SetFloat("_BlueTileScale", 1 / module.blueTile.size);
|
|
||||||
material.SetTexture("_BlueTileAlbedo", blueTextureTile);
|
|
||||||
material.SetTexture("_BlueTileSmoothnessMap", blueSmoothnessTile);
|
|
||||||
material.SetFloat("_BlueTileBumpStrength", module.blueTile.normalStrength);
|
|
||||||
material.SetTexture("_BlueTileBumpMap", blueNormalTile);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
material.DisableKeyword("BLUE_TILE");
|
|
||||||
}
|
|
||||||
if (module.alphaTile != null)
|
|
||||||
{
|
|
||||||
material.EnableKeyword("ALPHA_TILE");
|
|
||||||
material.SetFloat("_AlphaTileScale", 1 / module.alphaTile.size);
|
|
||||||
material.SetTexture("_AlphaTileAlbedo", alphaTextureTile);
|
|
||||||
material.SetTexture("_AlphaTileSmoothnessMap", alphaSmoothnessTile);
|
|
||||||
material.SetFloat("_AlphaTileBumpStrength", module.alphaTile.normalStrength);
|
|
||||||
material.SetTexture("_AlphaTileBumpMap", alphaNormalTile);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
material.DisableKeyword("ALPHA_TILE");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
LODCubeSphere.transform.parent = cubeSphere.transform;
|
LODCubeSphere.transform.parent = cubeSphere.transform;
|
||||||
LODCubeSphere.transform.localPosition = Vector3.zero;
|
LODCubeSphere.transform.localPosition = Vector3.zero;
|
||||||
@ -266,5 +141,58 @@ namespace NewHorizons.Builder.Body
|
|||||||
return cubeSphereMR;
|
return cubeSphereMR;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static Texture2D Load(string path, string name, bool linear)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(path)) return null;
|
||||||
|
|
||||||
|
if (!File.Exists(Path.Combine(_currentMod.ModHelper.Manifest.ModFolderPath, path)))
|
||||||
|
{
|
||||||
|
NHLogger.LogError($"Bad path for {_currentPlanetName} {name}: {path} couldn't be found.");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ImageUtilities.GetTexture(_currentMod, path, wrap: true, linear: linear);
|
||||||
|
}
|
||||||
|
|
||||||
|
internal class Tile
|
||||||
|
{
|
||||||
|
private HeightMapModule.HeightMapTileInfo _info;
|
||||||
|
private string _keyword, _prefix;
|
||||||
|
private Texture2D _texture, _smoothness, _normal;
|
||||||
|
|
||||||
|
public Tile(HeightMapModule.HeightMapTileInfo info, string keyword, string prefix)
|
||||||
|
{
|
||||||
|
_info = info;
|
||||||
|
|
||||||
|
_keyword = keyword;
|
||||||
|
_prefix = prefix;
|
||||||
|
|
||||||
|
if (_info != null)
|
||||||
|
{
|
||||||
|
_texture = Load(info.textureTile, $"{_prefix}TextureTile", false);
|
||||||
|
_smoothness = Load(info.smoothnessTile, $"{_prefix}SmoothnessTile", false);
|
||||||
|
_normal = Load(info.normalTile, $"{_prefix}NormalTile", false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void TryApplyTile(Material material, bool applyTriplanar)
|
||||||
|
{
|
||||||
|
if (applyTriplanar && _info != null)
|
||||||
|
{
|
||||||
|
material.EnableKeyword(_keyword);
|
||||||
|
material.SetFloat($"{_prefix}Scale", 1 / _info.size);
|
||||||
|
material.SetTexture($"{_prefix}Albedo", _texture);
|
||||||
|
material.SetTexture($"{_prefix}SmoothnessMap", _smoothness);
|
||||||
|
material.SetFloat($"{_prefix}BumpStrength", _info.normalStrength);
|
||||||
|
material.SetTexture($"{_prefix}BumpMap", _normal);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// This might just be disabled by default which would simplify a few things here but nobody wants to check (me included)
|
||||||
|
material.DisableKeyword(_keyword);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user