diff --git a/NewHorizons/Assets/xen.newhorizons b/NewHorizons/Assets/xen.newhorizons index 8424b800..ec531739 100644 Binary files a/NewHorizons/Assets/xen.newhorizons and b/NewHorizons/Assets/xen.newhorizons differ diff --git a/NewHorizons/Builder/Body/HeightMapBuilder.cs b/NewHorizons/Builder/Body/HeightMapBuilder.cs index 3e8a06f5..3255b839 100644 --- a/NewHorizons/Builder/Body/HeightMapBuilder.cs +++ b/NewHorizons/Builder/Body/HeightMapBuilder.cs @@ -13,12 +13,14 @@ namespace NewHorizons.Builder.Body public static class HeightMapBuilder { public static Shader PlanetShader; + private static readonly int EmissionMap = Shader.PropertyToID("_EmissionMap"); + private static readonly int EmissionColor = Shader.PropertyToID("_EmissionColor"); public static GameObject Make(GameObject planetGO, Sector sector, HeightMapModule module, IModBehaviour mod, int resolution, bool useLOD = false) { var deleteHeightmapFlag = false; - Texture2D heightMap, textureMap; + Texture2D heightMap, textureMap, emissionMap; try { if (module.heightMap != null && !File.Exists(Path.Combine(mod.ModHelper.Manifest.ModFolderPath, module.heightMap))) @@ -26,11 +28,16 @@ namespace NewHorizons.Builder.Body Logger.LogError($"Bad path for {planetGO.name} heightMap: {module.heightMap} couldn't be found."); module.heightMap = null; } - if (module.textureMap != null && !File.Exists(Path.Combine(mod.ModHelper.Manifest.ModFolderPath, module.textureMap ?? ""))) + if (module.textureMap != null && !File.Exists(Path.Combine(mod.ModHelper.Manifest.ModFolderPath, module.textureMap))) { Logger.LogError($"Bad path for {planetGO.name} textureMap: {module.textureMap} couldn't be found."); module.textureMap = null; } + if (module.emissionMap != null && !File.Exists(Path.Combine(mod.ModHelper.Manifest.ModFolderPath, module.emissionMap))) + { + Logger.LogError($"Bad path for {planetGO.name} emissionMap: {module.emissionMap} couldn't be found."); + module.emissionMap = null; + } if (module.heightMap == null) { @@ -54,8 +61,18 @@ namespace NewHorizons.Builder.Body textureMap = ImageUtilities.GetTexture(mod, module.textureMap); } + if (module.emissionMap == null) + { + emissionMap = Texture2D.blackTexture; + } + else + { + emissionMap = ImageUtilities.GetTexture(mod, module.emissionMap); + } + // If the texturemap is the same as the heightmap don't delete it #176 - if (textureMap == heightMap) deleteHeightmapFlag = false; + // Do the same with emissionmap + if (textureMap == heightMap || emissionMap == heightMap) deleteHeightmapFlag = false; } catch (Exception e) { @@ -63,15 +80,18 @@ namespace NewHorizons.Builder.Body return null; } - GameObject cubeSphere = new GameObject("CubeSphere"); + var cubeSphere = new GameObject("CubeSphere"); cubeSphere.SetActive(false); cubeSphere.transform.parent = sector?.transform ?? planetGO.transform; if (PlanetShader == null) PlanetShader = Main.NHAssetBundle.LoadAsset("Assets/Shaders/SphereTextureWrapper.shader"); - Vector3 stretch = module.stretch != null ? (Vector3)module.stretch : Vector3.one; + var stretch = module.stretch != null ? (Vector3)module.stretch : Vector3.one; - var level1 = MakeLODTerrain(cubeSphere, heightMap, textureMap, module.minHeight, module.maxHeight, resolution, stretch); + var emissionColor = module.emissionColor != null ? module.emissionColor.ToColor() : Color.white; + + var level1 = MakeLODTerrain(cubeSphere, heightMap, textureMap, module.minHeight, module.maxHeight, resolution, stretch, + emissionMap, emissionColor); var cubeSphereMC = cubeSphere.AddComponent(); cubeSphereMC.sharedMesh = level1.gameObject.GetComponent().mesh; @@ -79,7 +99,8 @@ namespace NewHorizons.Builder.Body if (useLOD) { var level2Res = (int)Mathf.Clamp(resolution / 2f, 1 /*cube moment*/, 100); - var level2 = MakeLODTerrain(cubeSphere, heightMap, textureMap, module.minHeight, module.maxHeight, level2Res, stretch); + var level2 = MakeLODTerrain(cubeSphere, heightMap, textureMap, module.minHeight, module.maxHeight, level2Res, stretch, + emissionMap, emissionColor); var LODGroup = cubeSphere.AddComponent(); LODGroup.size = module.maxHeight; @@ -115,7 +136,7 @@ namespace NewHorizons.Builder.Body return cubeSphere; } - public static MeshRenderer MakeLODTerrain(GameObject root, Texture2D heightMap, Texture2D textureMap, float minHeight, float maxHeight, int resolution, Vector3 stretch) + private static MeshRenderer MakeLODTerrain(GameObject root, Texture2D heightMap, Texture2D textureMap, float minHeight, float maxHeight, int resolution, Vector3 stretch, Texture2D emissionMap, Color emissionColor) { var LODCubeSphere = new GameObject("LODCubeSphere"); @@ -126,6 +147,8 @@ namespace NewHorizons.Builder.Body cubeSphereMR.material = material; material.name = textureMap.name; material.mainTexture = textureMap; + material.SetTexture(EmissionMap, emissionMap); + material.SetColor(EmissionColor, emissionColor); LODCubeSphere.transform.parent = root.transform; LODCubeSphere.transform.localPosition = Vector3.zero; diff --git a/NewHorizons/External/Modules/HeightMapModule.cs b/NewHorizons/External/Modules/HeightMapModule.cs index 945f65ed..18c9d250 100644 --- a/NewHorizons/External/Modules/HeightMapModule.cs +++ b/NewHorizons/External/Modules/HeightMapModule.cs @@ -41,5 +41,15 @@ namespace NewHorizons.External.Modules [Range(1 * 4, 500 * 4)] [DefaultValue(51 * 4)] public int resolution = 51 * 4; + + /// + /// Relative filepath to the texture used for emission. Optional. + /// + public string emissionMap; + + /// + /// Color multiplier of the emission texture. Defaults to white. + /// + public MColor emissionColor; } } \ No newline at end of file diff --git a/NewHorizons/Schemas/body_schema.json b/NewHorizons/Schemas/body_schema.json index 8c9e6ac1..a6d54eaa 100644 --- a/NewHorizons/Schemas/body_schema.json +++ b/NewHorizons/Schemas/body_schema.json @@ -748,6 +748,14 @@ "default": 204, "maximum": 2000.0, "minimum": 4.0 + }, + "emissionMap": { + "type": "string", + "description": "Relative filepath to the texture used for emission. Optional." + }, + "emissionColor": { + "description": "Color multiplier of the emission texture. Defaults to white.", + "$ref": "#/definitions/MColor" } } },