diff --git a/.gitignore b/.gitignore index 94675367..4e3a3cec 100644 --- a/.gitignore +++ b/.gitignore @@ -417,4 +417,9 @@ docs/.m_cache/** # Unity project new-horizons-unity new-horizons-unity/** +nh-unity +nh-unity/** +NewHorizons/Assets/Assets +NewHorizons/Assets/Assets.manifest + docs/.env diff --git a/NewHorizons/Assets/xen.newhorizons b/NewHorizons/Assets/xen.newhorizons index 84e681f3..1a754842 100644 Binary files a/NewHorizons/Assets/xen.newhorizons and b/NewHorizons/Assets/xen.newhorizons differ diff --git a/NewHorizons/Assets/xen.newhorizons.manifest b/NewHorizons/Assets/xen.newhorizons.manifest new file mode 100644 index 00000000..d45ddec5 --- /dev/null +++ b/NewHorizons/Assets/xen.newhorizons.manifest @@ -0,0 +1,23 @@ +ManifestFileVersion: 0 +CRC: 1014555239 +Hashes: + AssetFileHash: + serializedVersion: 2 + Hash: 45fa3430ee7bea1e8384e57927fc0f76 + TypeTreeHash: + serializedVersion: 2 + Hash: 55d48f4ad9c3b13330b9eb5ee5686477 +HashAppended: 0 +ClassTypes: +- Class: 48 + Script: {instanceID: 0} +SerializeReferenceClassIdentifiers: [] +Assets: +- Assets/Shaders/SphereTextureWrapper.shader +- Assets/Shaders/Ring.shader +- Assets/Shaders/SphereTextureWrapperNormal.shader +- Assets/Shaders/UnlitRing1Pixel.shader +- Assets/Shaders/UnlitTransparent.shader +- Assets/Shaders/StandardCullOFF.shader +- Assets/Shaders/Ring1Pixel.shader +Dependencies: [] diff --git a/NewHorizons/Builder/Atmosphere/AirBuilder.cs b/NewHorizons/Builder/Atmosphere/AirBuilder.cs index 7b5ab84d..209a2b26 100644 --- a/NewHorizons/Builder/Atmosphere/AirBuilder.cs +++ b/NewHorizons/Builder/Atmosphere/AirBuilder.cs @@ -23,28 +23,31 @@ namespace NewHorizons.Builder.Atmosphere sfv._allowShipAutoroll = true; sfv._disableOnStart = false; - // Try to parent it to the same as other rulesets to match vanilla but if its null put it on the root object - var ruleSetGO = planetGO.GetComponentInChildren()?.gameObject; - if (ruleSetGO == null) ruleSetGO = planetGO; - - var shockLayerRuleset = ruleSetGO.AddComponent(); - shockLayerRuleset._type = ShockLayerRuleset.ShockType.Atmospheric; - shockLayerRuleset._radialCenter = airGO.transform; - shockLayerRuleset._minShockSpeed = config.Atmosphere.minShockSpeed; - shockLayerRuleset._maxShockSpeed = config.Atmosphere.maxShockSpeed; - - if (config.Atmosphere.clouds != null) + if (config.Atmosphere.hasShockLayer) { - shockLayerRuleset._innerRadius = config.Atmosphere.clouds.innerCloudRadius; - shockLayerRuleset._outerRadius = config.Atmosphere.clouds.outerCloudRadius; - } - else - { - var bottom = config.Base.surfaceSize; - var top = config.Atmosphere.size; + // Try to parent it to the same as other rulesets to match vanilla but if its null put it on the root object + var ruleSetGO = planetGO.GetComponentInChildren()?.gameObject; + if (ruleSetGO == null) ruleSetGO = planetGO; - shockLayerRuleset._innerRadius = (bottom + top) / 2f; - shockLayerRuleset._outerRadius = top; + var shockLayerRuleset = ruleSetGO.AddComponent(); + shockLayerRuleset._type = ShockLayerRuleset.ShockType.Atmospheric; + shockLayerRuleset._radialCenter = airGO.transform; + shockLayerRuleset._minShockSpeed = config.Atmosphere.minShockSpeed; + shockLayerRuleset._maxShockSpeed = config.Atmosphere.maxShockSpeed; + + if (config.Atmosphere.clouds != null) + { + shockLayerRuleset._innerRadius = config.Atmosphere.clouds.innerCloudRadius; + shockLayerRuleset._outerRadius = config.Atmosphere.clouds.outerCloudRadius; + } + else + { + var bottom = config.Base.surfaceSize; + var top = config.Atmosphere.size; + + shockLayerRuleset._innerRadius = (bottom + top) / 2f; + shockLayerRuleset._outerRadius = top; + } } if (config.Atmosphere.hasOxygen) diff --git a/NewHorizons/Builder/Atmosphere/CloudsBuilder.cs b/NewHorizons/Builder/Atmosphere/CloudsBuilder.cs index 65039e3a..6732b18f 100644 --- a/NewHorizons/Builder/Atmosphere/CloudsBuilder.cs +++ b/NewHorizons/Builder/Atmosphere/CloudsBuilder.cs @@ -9,7 +9,6 @@ namespace NewHorizons.Builder.Atmosphere { public static class CloudsBuilder { - private static Shader _sphereShader = null; private static Material[] _gdCloudMaterials; private static Material[] _qmCloudMaterials; private static GameObject _lightningPrefab; @@ -91,8 +90,6 @@ namespace NewHorizons.Builder.Atmosphere // Fix the rotations once the rest is done cloudsMainGO.transform.rotation = planetGO.transform.TransformRotation(Quaternion.Euler(0, 0, 0)); - // For the base shader it has to be rotated idk - if (atmo.clouds.cloudsPrefab == CloudPrefabType.Basic) cloudsMainGO.transform.rotation = planetGO.transform.TransformRotation(Quaternion.Euler(90, 0, 0)); // Lightning if (atmo.clouds.hasLightning) @@ -170,7 +167,6 @@ namespace NewHorizons.Builder.Atmosphere MeshRenderer topMR = cloudsTopGO.AddComponent(); - if (_sphereShader == null) _sphereShader = Main.NHAssetBundle.LoadAsset("Assets/Shaders/SphereTextureWrapper.shader"); if (_gdCloudMaterials == null) _gdCloudMaterials = SearchUtilities.Find("CloudsTopLayer_GD").GetComponent().sharedMaterials; if (_qmCloudMaterials == null) _qmCloudMaterials = SearchUtilities.Find("CloudsTopLayer_QM").GetComponent().sharedMaterials; Material[] prefabMaterials = atmo.clouds.cloudsPrefab == CloudPrefabType.GiantsDeep ? _gdCloudMaterials : _qmCloudMaterials; @@ -178,10 +174,10 @@ namespace NewHorizons.Builder.Atmosphere if (atmo.clouds.cloudsPrefab == CloudPrefabType.Basic) { - var material = new Material(_sphereShader); + var material = new Material(Shader.Find("Standard")); if (atmo.clouds.unlit) material.renderQueue = 3000; material.name = atmo.clouds.unlit ? "BasicCloud" : "BasicShadowCloud"; - + material.SetFloat(279, 0f); // smoothness tempArray[0] = material; } else @@ -211,8 +207,7 @@ namespace NewHorizons.Builder.Atmosphere if (atmo.clouds.rotationSpeed != 0f) { var topRT = cloudsTopGO.AddComponent(); - // Idk why but the axis is weird - topRT._localAxis = atmo.clouds.cloudsPrefab == CloudPrefabType.Basic ? Vector3.forward : Vector3.up; + topRT._localAxis = Vector3.up; topRT._degreesPerSecond = atmo.clouds.rotationSpeed; topRT._randomizeRotationRate = false; } diff --git a/NewHorizons/Builder/Body/ProxyBuilder.cs b/NewHorizons/Builder/Body/ProxyBuilder.cs index 6c823c20..4e028acf 100644 --- a/NewHorizons/Builder/Body/ProxyBuilder.cs +++ b/NewHorizons/Builder/Body/ProxyBuilder.cs @@ -54,7 +54,7 @@ namespace NewHorizons.Builder.Body remnantGO.transform.parent = proxy.transform; remnantGO.transform.localPosition = Vector3.zero; - SharedMake(planetGO, remnantGO, proxyController, remnant); + SharedMake(planetGO, remnantGO, null, remnant); proxyController.stellarRemnantGO = remnantGO; } @@ -125,9 +125,11 @@ namespace NewHorizons.Builder.Body if (realSize < body.Config.Ring.outerRadius) realSize = body.Config.Ring.outerRadius; } + Renderer starAtmosphere = null; + Renderer starFog = null; if (body.Config.Star != null) { - StarBuilder.MakeStarProxy(planetGO, proxy, body.Config.Star, body.Mod, body.Config.isStellarRemnant); + (_, starAtmosphere, starFog) = StarBuilder.MakeStarProxy(planetGO, proxy, body.Config.Star, body.Mod, body.Config.isStellarRemnant); if (realSize < body.Config.Star.size) realSize = body.Config.Star.size; } @@ -217,9 +219,17 @@ namespace NewHorizons.Builder.Body if (proxyController != null) { - proxyController._atmosphere = atmosphere; - proxyController._fog = fog; - proxyController._fogCurveMaxVal = fogCurveMaxVal; + proxyController._atmosphere = atmosphere ?? starAtmosphere; + if (fog != null) + { + proxyController._fog = fog; + proxyController._fogCurveMaxVal = fogCurveMaxVal; + } + else if (starFog != null) + { + proxyController._fog = starFog; + proxyController._fogCurveMaxVal = 0.05f; + } proxyController.topClouds = topClouds; proxyController.lightningGenerator = lightningGenerator; proxyController.supernovaPlanetEffectController = supernovaPlanetEffect; diff --git a/NewHorizons/Builder/Body/StarBuilder.cs b/NewHorizons/Builder/Body/StarBuilder.cs index e976f800..7e32c3d3 100644 --- a/NewHorizons/Builder/Body/StarBuilder.cs +++ b/NewHorizons/Builder/Body/StarBuilder.cs @@ -46,23 +46,29 @@ namespace NewHorizons.Builder.Body sunAtmosphere.transform.position = planetGO.transform.position; sunAtmosphere.transform.localScale = Vector3.one * OuterRadiusRatio; sunAtmosphere.name = "Atmosphere_Star"; + + var atmospheres = sunAtmosphere.transform.Find("AtmoSphere"); + atmospheres.transform.localScale = Vector3.one; + var lods = atmospheres.GetComponentsInChildren(); + foreach (var lod in lods) + { + lod.material.SetFloat(InnerRadius, starModule.size); + lod.material.SetFloat(OuterRadius, starModule.size * OuterRadiusRatio); + } + var fog = sunAtmosphere.transform.Find("FogSphere").GetComponent(); + fog.transform.localScale = Vector3.one; + fog.fogRadius = starModule.size * OuterRadiusRatio; + fog.lodFadeDistance = fog.fogRadius * (StarBuilder.OuterRadiusRatio - 1f); + + fog.fogImpostor.material.SetFloat(Radius, starModule.size * OuterRadiusRatio); if (starModule.tint != null) { fog.fogTint = starModule.tint.ToColor(); fog.fogImpostor.material.SetColor(Tint, starModule.tint.ToColor()); - sunAtmosphere.transform.Find("AtmoSphere").transform.localScale = Vector3.one; - foreach (var lod in sunAtmosphere.transform.Find("AtmoSphere").GetComponentsInChildren()) - { + foreach (var lod in lods) lod.material.SetColor(SkyColor, starModule.tint.ToColor()); - lod.material.SetFloat(InnerRadius, starModule.size); - lod.material.SetFloat(OuterRadius, starModule.size * OuterRadiusRatio); - } } - fog.transform.localScale = Vector3.one; - fog.fogRadius = starModule.size * OuterRadiusRatio; - fog.lodFadeDistance = fog.fogRadius * (StarBuilder.OuterRadiusRatio - 1f); - fog.fogImpostor.material.SetFloat(Radius, starModule.size * OuterRadiusRatio); } var ambientLightGO = Object.Instantiate(SearchUtilities.Find("Sun_Body/AmbientLight_SUN"), starGO.transform); @@ -179,10 +185,37 @@ namespace NewHorizons.Builder.Body return (starGO, starController, starEvolutionController); } - public static GameObject MakeStarProxy(GameObject planet, GameObject proxyGO, StarModule starModule, IModBehaviour mod, bool isStellarRemnant) + public static (GameObject, Renderer, Renderer) MakeStarProxy(GameObject planet, GameObject proxyGO, StarModule starModule, IModBehaviour mod, bool isStellarRemnant) { var (starGO, controller, supernova) = SharedStarGeneration(proxyGO, null, mod, starModule, isStellarRemnant); + Renderer atmosphere = null; + Renderer fog = null; + if (starModule.hasAtmosphere) + { + GameObject sunAtmosphere = Object.Instantiate(SearchUtilities.Find("SunProxy/Sun_Proxy_Body/Atmosphere_SUN", false) ?? SearchUtilities.Find("SunProxy(Clone)/Sun_Proxy_Body/Atmosphere_SUN"), starGO.transform); + sunAtmosphere.transform.position = proxyGO.transform.position; + sunAtmosphere.transform.localScale = Vector3.one * OuterRadiusRatio; + sunAtmosphere.name = "Atmosphere_Star"; + + atmosphere = sunAtmosphere.transform.Find("Atmosphere_LOD2").GetComponent(); + atmosphere.transform.localScale = Vector3.one; + atmosphere.material.SetFloat(InnerRadius, starModule.size); + atmosphere.material.SetFloat(OuterRadius, starModule.size * OuterRadiusRatio); + + fog = sunAtmosphere.transform.Find("FogSphere").GetComponent(); + fog.transform.localScale = Vector3.one; + fog.material.SetFloat(Radius, starModule.size * OuterRadiusRatio); + + if (starModule.tint != null) + { + fog.material.SetColor(Tint, starModule.tint.ToColor()); + atmosphere.material.SetColor(SkyColor, starModule.tint.ToColor()); + } + + controller.atmosphere = sunAtmosphere; + } + controller.isProxy = true; // Planet can have multiple stars on them, so find the one that is also a remnant / not a remnant @@ -198,7 +231,7 @@ namespace NewHorizons.Builder.Body supernova.mainStellerDeathController = mainController.supernova; } - return starGO; + return (starGO, atmosphere, fog); } private static (GameObject, StarEvolutionController, StellarDeathController) SharedStarGeneration(GameObject planetGO, Sector sector, IModBehaviour mod, StarModule starModule, bool isStellarRemnant) diff --git a/NewHorizons/Builder/Body/StellarRemnantBuilder.cs b/NewHorizons/Builder/Body/StellarRemnantBuilder.cs index 31ea505a..6e06c5dc 100644 --- a/NewHorizons/Builder/Body/StellarRemnantBuilder.cs +++ b/NewHorizons/Builder/Body/StellarRemnantBuilder.cs @@ -88,7 +88,7 @@ namespace NewHorizons.Builder.Body lightRadius = 10000, solarLuminosity = 0.5f }; - if (proxy != null) return StarBuilder.MakeStarProxy(planetGO, proxy, whiteDwarfModule, mod, true); + if (proxy != null) return StarBuilder.MakeStarProxy(planetGO, proxy, whiteDwarfModule, mod, true).Item1; else return StarBuilder.Make(planetGO, sector, whiteDwarfModule, mod, true).Item1; } @@ -107,7 +107,7 @@ namespace NewHorizons.Builder.Body // Instead of showing the typical star surface we use a tinted singularity GameObject neutronStar; - if (proxy != null) neutronStar = StarBuilder.MakeStarProxy(planetGO, proxy, neutronStarModule, mod, true); + if (proxy != null) neutronStar = StarBuilder.MakeStarProxy(planetGO, proxy, neutronStarModule, mod, true).Item1; else (neutronStar, _, _) = StarBuilder.Make(planetGO, sector, neutronStarModule, mod, true); neutronStar.FindChild("Surface").SetActive(false); diff --git a/NewHorizons/External/Modules/AtmosphereModule.cs b/NewHorizons/External/Modules/AtmosphereModule.cs index f03f3ceb..d2b835ee 100644 --- a/NewHorizons/External/Modules/AtmosphereModule.cs +++ b/NewHorizons/External/Modules/AtmosphereModule.cs @@ -100,6 +100,11 @@ namespace NewHorizons.External.Modules /// public bool useAtmosphereShader; + /// + /// Whether this atmosphere will have flames appear when your ship goes a certain speed. + /// + [DefaultValue(true)] public bool hasShockLayer = true; + /// /// Minimum speed that your ship can go in the atmosphere where flames will appear. /// diff --git a/NewHorizons/Schemas/body_schema.json b/NewHorizons/Schemas/body_schema.json index 85fabcd8..7ea40e04 100644 --- a/NewHorizons/Schemas/body_schema.json +++ b/NewHorizons/Schemas/body_schema.json @@ -313,6 +313,11 @@ "type": "boolean", "description": "Whether we use an atmospheric shader on the planet. Doesn't affect clouds, fog, rain, snow, oxygen, etc. Purely\nvisual." }, + "hasShockLayer": { + "type": "boolean", + "description": "Whether this atmosphere will have flames appear when your ship goes a certain speed.", + "default": true + }, "minShockSpeed": { "type": "number", "description": "Minimum speed that your ship can go in the atmosphere where flames will appear.",