diff --git a/NewHorizons/Assets/xen.newhorizons b/NewHorizons/Assets/xen.newhorizons index 1a754842..de0815e9 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 index d45ddec5..8902bd7f 100644 --- a/NewHorizons/Assets/xen.newhorizons.manifest +++ b/NewHorizons/Assets/xen.newhorizons.manifest @@ -1,14 +1,16 @@ ManifestFileVersion: 0 -CRC: 1014555239 +CRC: 2022446871 Hashes: AssetFileHash: serializedVersion: 2 - Hash: 45fa3430ee7bea1e8384e57927fc0f76 + Hash: 083882699617744b8fc49234bb8cb795 TypeTreeHash: serializedVersion: 2 - Hash: 55d48f4ad9c3b13330b9eb5ee5686477 + Hash: 10a6a558690295dadb3dd990eda0821a HashAppended: 0 ClassTypes: +- Class: 21 + Script: {instanceID: 0} - Class: 48 Script: {instanceID: 0} SerializeReferenceClassIdentifiers: [] @@ -18,6 +20,7 @@ Assets: - Assets/Shaders/SphereTextureWrapperNormal.shader - Assets/Shaders/UnlitRing1Pixel.shader - Assets/Shaders/UnlitTransparent.shader +- Assets/Resources/TransparentCloud.mat - Assets/Shaders/StandardCullOFF.shader - Assets/Shaders/Ring1Pixel.shader Dependencies: [] diff --git a/NewHorizons/Builder/Atmosphere/AtmosphereBuilder.cs b/NewHorizons/Builder/Atmosphere/AtmosphereBuilder.cs index 7646a205..9dd1e8a8 100644 --- a/NewHorizons/Builder/Atmosphere/AtmosphereBuilder.cs +++ b/NewHorizons/Builder/Atmosphere/AtmosphereBuilder.cs @@ -59,7 +59,7 @@ namespace NewHorizons.Builder.Atmosphere } } - material.SetFloat(InnerRadius, atmosphereModule.clouds != null ? atmosphereModule.size : surfaceSize); + material.SetFloat(InnerRadius, (atmosphereModule.clouds != null && atmosphereModule.clouds.cloudsPrefab != CloudPrefabType.Transparent) ? atmosphereModule.size : surfaceSize); material.SetFloat(OuterRadius, atmosphereModule.size * 1.2f); if (atmosphereModule.atmosphereTint != null) material.SetColor(SkyColor, atmosphereModule.atmosphereTint.ToColor()); diff --git a/NewHorizons/Builder/Atmosphere/CloudsBuilder.cs b/NewHorizons/Builder/Atmosphere/CloudsBuilder.cs index 6732b18f..d5b15f89 100644 --- a/NewHorizons/Builder/Atmosphere/CloudsBuilder.cs +++ b/NewHorizons/Builder/Atmosphere/CloudsBuilder.cs @@ -11,6 +11,7 @@ namespace NewHorizons.Builder.Atmosphere { private static Material[] _gdCloudMaterials; private static Material[] _qmCloudMaterials; + private static Material _transparentCloud; private static GameObject _lightningPrefab; private static Texture2D _colorRamp; private static readonly int Color = Shader.PropertyToID("_Color"); @@ -18,6 +19,7 @@ namespace NewHorizons.Builder.Atmosphere private static readonly int MainTex = Shader.PropertyToID("_MainTex"); private static readonly int RampTex = Shader.PropertyToID("_RampTex"); private static readonly int CapTex = Shader.PropertyToID("_CapTex"); + private static readonly int Smoothness = Shader.PropertyToID("_Glossiness"); public static void Make(GameObject planetGO, Sector sector, AtmosphereModule atmo, bool cloaked, IModBehaviour mod) { @@ -28,7 +30,15 @@ namespace NewHorizons.Builder.Atmosphere cloudsMainGO.SetActive(false); cloudsMainGO.transform.parent = sector?.transform ?? planetGO.transform; - MakeTopClouds(cloudsMainGO, atmo, mod); + if (atmo.clouds.cloudsPrefab != CloudPrefabType.Transparent) MakeTopClouds(cloudsMainGO, atmo, mod); + else + { + MakeTransparentClouds(cloudsMainGO, atmo, mod); + if (atmo.clouds.hasLightning) MakeLightning(cloudsMainGO, sector, atmo); + cloudsMainGO.transform.position = planetGO.transform.TransformPoint(Vector3.zero); + cloudsMainGO.SetActive(true); + return; + } GameObject cloudsBottomGO = new GameObject("BottomClouds"); cloudsBottomGO.SetActive(false); @@ -114,7 +124,7 @@ namespace NewHorizons.Builder.Atmosphere lightning.transform.localPosition = Vector3.zero; var lightningGenerator = lightning.GetComponent(); - lightningGenerator._altitude = (atmo.clouds.outerCloudRadius + atmo.clouds.innerCloudRadius) / 2f; + lightningGenerator._altitude = atmo.clouds.cloudsPrefab != CloudPrefabType.Transparent ? (atmo.clouds.outerCloudRadius + atmo.clouds.innerCloudRadius) / 2f : atmo.clouds.outerCloudRadius; if (noAudio) { lightningGenerator._audioPrefab = null; @@ -177,7 +187,7 @@ namespace NewHorizons.Builder.Atmosphere 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 + material.SetFloat(Smoothness, 0f); tempArray[0] = material; } else @@ -218,5 +228,65 @@ namespace NewHorizons.Builder.Atmosphere return cloudsTopGO; } + + public static GameObject MakeTransparentClouds(GameObject rootObject, AtmosphereModule atmo, IModBehaviour mod, bool isProxy = false) + { + Texture2D image; + + try + { + image = ImageUtilities.GetTexture(mod, atmo.clouds.texturePath); + } + catch (Exception e) + { + Logger.LogError($"Couldn't load Cloud texture for [{atmo.clouds.texturePath}]:\n{e}"); + return null; + } + + GameObject cloudsTransparentGO = new GameObject("TransparentClouds"); + cloudsTransparentGO.SetActive(false); + cloudsTransparentGO.transform.parent = rootObject.transform; + cloudsTransparentGO.transform.localScale = Vector3.one * atmo.clouds.outerCloudRadius; + + MeshFilter filter = cloudsTransparentGO.AddComponent(); + filter.mesh = SearchUtilities.Find("CloudsTopLayer_GD").GetComponent().mesh; + + MeshRenderer renderer = cloudsTransparentGO.AddComponent(); + if (_transparentCloud == null) _transparentCloud = Main.NHAssetBundle.LoadAsset("Assets/Resources/TransparentCloud.mat"); + var material = new Material(_transparentCloud); + material.name = "TransparentClouds_" + image.name; + material.SetTexture(MainTex, image); + renderer.sharedMaterial = material; + + if (!isProxy) + { + GameObject tcrqcGO = new GameObject("TransparentCloudRenderQueueController"); + tcrqcGO.transform.SetParent(cloudsTransparentGO.transform, false); + tcrqcGO.layer = LayerMask.NameToLayer("BasicEffectVolume"); + + var shape = tcrqcGO.AddComponent(); + shape.radius = 1; + + var owTriggerVolume = tcrqcGO.AddComponent(); + owTriggerVolume._shape = shape; + + TransparentCloudRenderQueueController tcrqc = tcrqcGO.AddComponent(); + tcrqc.renderer = renderer; + } + + if (atmo.clouds.rotationSpeed != 0f) + { + var rt = cloudsTransparentGO.AddComponent(); + rt._localAxis = Vector3.up; + rt._degreesPerSecond = atmo.clouds.rotationSpeed; + rt._randomizeRotationRate = false; + } + + cloudsTransparentGO.transform.localPosition = Vector3.zero; + + cloudsTransparentGO.SetActive(true); + + return cloudsTransparentGO; + } } } diff --git a/NewHorizons/Builder/Atmosphere/EffectsBuilder.cs b/NewHorizons/Builder/Atmosphere/EffectsBuilder.cs index c177a9ed..6394e02f 100644 --- a/NewHorizons/Builder/Atmosphere/EffectsBuilder.cs +++ b/NewHorizons/Builder/Atmosphere/EffectsBuilder.cs @@ -21,7 +21,6 @@ namespace NewHorizons.Builder.Atmosphere SCG._waitForStreaming = false; var minHeight = surfaceSize; - var maxHeight = config.Atmosphere.size; if (config.HeightMap?.minHeight != null) { if (config.Water?.size >= config.HeightMap.minHeight) minHeight = config.Water.size; // use sea level if its higher @@ -30,6 +29,9 @@ namespace NewHorizons.Builder.Atmosphere else if (config.Water?.size != null) minHeight = config.Water.size; else if (config.Lava?.size != null) minHeight = config.Lava.size; + var maxHeight = config.Atmosphere.size; + if (config.Atmosphere.clouds?.outerCloudRadius != null) maxHeight = config.Atmosphere.clouds.outerCloudRadius; + if (config.Atmosphere.hasRain) { var rainGO = GameObject.Instantiate(SearchUtilities.Find("GiantsDeep_Body/Sector_GD/Sector_GDInterior/Effects_GDInterior/Effects_GD_Rain"), effectsGO.transform); diff --git a/NewHorizons/Builder/Body/ProxyBuilder.cs b/NewHorizons/Builder/Body/ProxyBuilder.cs index 4e028acf..32f7d355 100644 --- a/NewHorizons/Builder/Body/ProxyBuilder.cs +++ b/NewHorizons/Builder/Body/ProxyBuilder.cs @@ -111,7 +111,8 @@ namespace NewHorizons.Builder.Body if (body.Config.Atmosphere.clouds != null) { - topClouds = CloudsBuilder.MakeTopClouds(proxy, body.Config.Atmosphere, body.Mod).GetComponent(); + if (body.Config.Atmosphere.clouds.cloudsPrefab != External.Modules.CloudPrefabType.Transparent) topClouds = CloudsBuilder.MakeTopClouds(proxy, body.Config.Atmosphere, body.Mod).GetComponent(); + else topClouds = CloudsBuilder.MakeTransparentClouds(proxy, body.Config.Atmosphere, body.Mod, true).GetAddComponent(); if (body.Config.Atmosphere.clouds.hasLightning) lightningGenerator = CloudsBuilder.MakeLightning(proxy, null, body.Config.Atmosphere, true); diff --git a/NewHorizons/Components/TransparentCloudRenderQueueController.cs b/NewHorizons/Components/TransparentCloudRenderQueueController.cs new file mode 100644 index 00000000..d78259b1 --- /dev/null +++ b/NewHorizons/Components/TransparentCloudRenderQueueController.cs @@ -0,0 +1,54 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using UnityEngine; + +namespace NewHorizons.Components +{ + [RequireComponent(typeof(OWTriggerVolume))] + public class TransparentCloudRenderQueueController : MonoBehaviour + { + public int insideQueue = 3001; + public int outsideQueue = 2999; + + private OWTriggerVolume _triggerVolume; + public Renderer renderer; + + public void Awake() + { + _triggerVolume = this.GetRequiredComponent(); + if (_triggerVolume == null) return; + _triggerVolume.OnEntry += OnTriggerVolumeEntry; + _triggerVolume.OnExit += OnTriggerVolumeExit; + } + + public void OnDestroy() + { + if (_triggerVolume == null) return; + _triggerVolume.OnEntry -= OnTriggerVolumeEntry; + _triggerVolume.OnExit -= OnTriggerVolumeExit; + } + + public void OnTriggerVolumeEntry(GameObject hitObj) + { + if (hitObj.CompareTag("PlayerDetector")) SetQueueToInside(); + } + + public void OnTriggerVolumeExit(GameObject hitObj) + { + if (hitObj.CompareTag("PlayerDetector")) SetQueueToOutside(); + } + + public void SetQueueToInside() + { + if (renderer == null) return; + renderer.sharedMaterial.renderQueue = insideQueue; + } + + public void SetQueueToOutside() + { + if (renderer == null) return; + renderer.sharedMaterial.renderQueue = outsideQueue; + } + } +} diff --git a/NewHorizons/External/Modules/AtmosphereModule.cs b/NewHorizons/External/Modules/AtmosphereModule.cs index d2b835ee..33c0ccef 100644 --- a/NewHorizons/External/Modules/AtmosphereModule.cs +++ b/NewHorizons/External/Modules/AtmosphereModule.cs @@ -30,6 +30,8 @@ namespace NewHorizons.External.Modules [EnumMember(Value = @"quantumMoon")] QuantumMoon = 1, [EnumMember(Value = @"basic")] Basic = 2, + + [EnumMember(Value = @"transparent")] Transparent = 3, } [JsonObject] diff --git a/NewHorizons/Handlers/PlanetCreationHandler.cs b/NewHorizons/Handlers/PlanetCreationHandler.cs index 67700c36..ec75a23c 100644 --- a/NewHorizons/Handlers/PlanetCreationHandler.cs +++ b/NewHorizons/Handlers/PlanetCreationHandler.cs @@ -590,7 +590,7 @@ namespace NewHorizons.Handlers if (!string.IsNullOrEmpty(body.Config.Atmosphere?.clouds?.texturePath)) { CloudsBuilder.Make(go, sector, body.Config.Atmosphere, willHaveCloak, body.Mod); - SunOverrideBuilder.Make(go, sector, body.Config.Atmosphere, body.Config.Water, surfaceSize); + if (body.Config.Atmosphere.clouds.cloudsPrefab != External.Modules.CloudPrefabType.Transparent) SunOverrideBuilder.Make(go, sector, body.Config.Atmosphere, body.Config.Water, surfaceSize); } if (body.Config.Atmosphere.hasRain || body.Config.Atmosphere.hasSnow) diff --git a/NewHorizons/Handlers/TitleSceneHandler.cs b/NewHorizons/Handlers/TitleSceneHandler.cs index b4fb22dc..ea435305 100644 --- a/NewHorizons/Handlers/TitleSceneHandler.cs +++ b/NewHorizons/Handlers/TitleSceneHandler.cs @@ -89,7 +89,7 @@ namespace NewHorizons.Handlers heightMap.minHeight = body.Config.HeightMap.minHeight * size / body.Config.HeightMap.maxHeight; heightMap.stretch = body.Config.HeightMap.stretch; } - if (body.Config.Atmosphere?.clouds?.texturePath != null) + if (body.Config.Atmosphere?.clouds?.texturePath != null && body.Config.Atmosphere?.clouds?.cloudsPrefab != CloudPrefabType.Transparent) { // Hacky but whatever I just want a sphere size = Mathf.Clamp(body.Config.Atmosphere.size / 10, minSize, maxSize); diff --git a/NewHorizons/Schemas/body_schema.json b/NewHorizons/Schemas/body_schema.json index 7ea40e04..2a4b8881 100644 --- a/NewHorizons/Schemas/body_schema.json +++ b/NewHorizons/Schemas/body_schema.json @@ -400,12 +400,14 @@ "x-enumNames": [ "GiantsDeep", "QuantumMoon", - "Basic" + "Basic", + "Transparent" ], "enum": [ "giantsDeep", "quantumMoon", - "basic" + "basic", + "transparent" ] }, "FluidType": {