From e9106ad88e4ab0cba5a4bac706b3066b2568eded Mon Sep 17 00:00:00 2001 From: Nick Date: Fri, 13 May 2022 14:12:58 -0400 Subject: [PATCH] Fix cloud fog when using basic shader --- .../Builder/Atmosphere/CloudsBuilder.cs | 35 +++++++++++-------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/NewHorizons/Builder/Atmosphere/CloudsBuilder.cs b/NewHorizons/Builder/Atmosphere/CloudsBuilder.cs index 5289156e..9156b2e3 100644 --- a/NewHorizons/Builder/Atmosphere/CloudsBuilder.cs +++ b/NewHorizons/Builder/Atmosphere/CloudsBuilder.cs @@ -11,6 +11,7 @@ namespace NewHorizons.Builder.Atmosphere public static class CloudsBuilder { private static Shader _sphereShader = null; + private static Material[] _gdCloudMaterials; public static void Make(GameObject planetGO, Sector sector, AtmosphereModule atmo, IModBehaviour mod) { Texture2D image, cap, ramp; @@ -45,26 +46,31 @@ namespace NewHorizons.Builder.Atmosphere topMF.mesh = GameObject.Find("CloudsTopLayer_GD").GetComponent().mesh; MeshRenderer topMR = cloudsTopGO.AddComponent(); - if (!atmo.UseBasicCloudShader) + + if (_sphereShader == null) _sphereShader = Main.ShaderBundle.LoadAsset("Assets/Shaders/SphereTextureWrapper.shader"); + if (_gdCloudMaterials == null) _gdCloudMaterials = GameObject.Find("CloudsTopLayer_GD").GetComponent().sharedMaterials; + var tempArray = new Material[2]; + + if (atmo.UseBasicCloudShader) { - var tempArray = new Material[2]; - for (int i = 0; i < 2; i++) - { - var mat = new Material(GameObject.Find("CloudsTopLayer_GD").GetComponent().sharedMaterials[i]); - if (!atmo.ShadowsOnClouds) mat.renderQueue = 2550; - mat.name = atmo.ShadowsOnClouds ? "AdvancedShadowCloud" : "AdvancedCloud"; - tempArray[i] = mat; - } - topMR.sharedMaterials = tempArray; + var material = new Material(_sphereShader); + if (!atmo.ShadowsOnClouds) material.renderQueue = 2550; + material.name = atmo.ShadowsOnClouds ? "BasicShadowCloud" : "BasicCloud"; + + tempArray[0] = material; } else { - if (_sphereShader == null) _sphereShader = Main.ShaderBundle.LoadAsset("Assets/Shaders/SphereTextureWrapper.shader"); - topMR.material = new Material(_sphereShader); - if (!atmo.ShadowsOnClouds) topMR.material.renderQueue = 2550; - topMR.material.name = atmo.ShadowsOnClouds ? "BasicShadowCloud" : "BasicCloud"; + var material = new Material(_gdCloudMaterials[0]); + if (!atmo.ShadowsOnClouds) material.renderQueue = 2550; + material.name = atmo.ShadowsOnClouds ? "AdvancedShadowCloud" : "AdvancedCloud"; + tempArray[0] = material; } + // This is the stencil material for the fog under the clouds + tempArray[1] = new Material(_gdCloudMaterials[1]); + topMR.sharedMaterials = tempArray; + foreach (var material in topMR.sharedMaterials) { material.SetColor("_Color", cloudTint); @@ -80,7 +86,6 @@ namespace NewHorizons.Builder.Atmosphere cloudsTopGO.layer = LayerMask.NameToLayer("IgnoreSun"); } - RotateTransform topRT = cloudsTopGO.AddComponent(); // Idk why but the axis is weird topRT._localAxis = atmo.UseBasicCloudShader ? Vector3.forward : Vector3.up;