Fix cloud fog when using basic shader

This commit is contained in:
Nick 2022-05-13 14:12:58 -04:00
parent ba2a9722fb
commit e9106ad88e

View File

@ -11,6 +11,7 @@ namespace NewHorizons.Builder.Atmosphere
public static class CloudsBuilder public static class CloudsBuilder
{ {
private static Shader _sphereShader = null; private static Shader _sphereShader = null;
private static Material[] _gdCloudMaterials;
public static void Make(GameObject planetGO, Sector sector, AtmosphereModule atmo, IModBehaviour mod) public static void Make(GameObject planetGO, Sector sector, AtmosphereModule atmo, IModBehaviour mod)
{ {
Texture2D image, cap, ramp; Texture2D image, cap, ramp;
@ -45,26 +46,31 @@ namespace NewHorizons.Builder.Atmosphere
topMF.mesh = GameObject.Find("CloudsTopLayer_GD").GetComponent<MeshFilter>().mesh; topMF.mesh = GameObject.Find("CloudsTopLayer_GD").GetComponent<MeshFilter>().mesh;
MeshRenderer topMR = cloudsTopGO.AddComponent<MeshRenderer>(); MeshRenderer topMR = cloudsTopGO.AddComponent<MeshRenderer>();
if (!atmo.UseBasicCloudShader)
{ if (_sphereShader == null) _sphereShader = Main.ShaderBundle.LoadAsset<Shader>("Assets/Shaders/SphereTextureWrapper.shader");
if (_gdCloudMaterials == null) _gdCloudMaterials = GameObject.Find("CloudsTopLayer_GD").GetComponent<MeshRenderer>().sharedMaterials;
var tempArray = new Material[2]; var tempArray = new Material[2];
for (int i = 0; i < 2; i++)
if (atmo.UseBasicCloudShader)
{ {
var mat = new Material(GameObject.Find("CloudsTopLayer_GD").GetComponent<MeshRenderer>().sharedMaterials[i]); var material = new Material(_sphereShader);
if (!atmo.ShadowsOnClouds) mat.renderQueue = 2550; if (!atmo.ShadowsOnClouds) material.renderQueue = 2550;
mat.name = atmo.ShadowsOnClouds ? "AdvancedShadowCloud" : "AdvancedCloud"; material.name = atmo.ShadowsOnClouds ? "BasicShadowCloud" : "BasicCloud";
tempArray[i] = mat;
} tempArray[0] = material;
topMR.sharedMaterials = tempArray;
} }
else else
{ {
if (_sphereShader == null) _sphereShader = Main.ShaderBundle.LoadAsset<Shader>("Assets/Shaders/SphereTextureWrapper.shader"); var material = new Material(_gdCloudMaterials[0]);
topMR.material = new Material(_sphereShader); if (!atmo.ShadowsOnClouds) material.renderQueue = 2550;
if (!atmo.ShadowsOnClouds) topMR.material.renderQueue = 2550; material.name = atmo.ShadowsOnClouds ? "AdvancedShadowCloud" : "AdvancedCloud";
topMR.material.name = atmo.ShadowsOnClouds ? "BasicShadowCloud" : "BasicCloud"; 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) foreach (var material in topMR.sharedMaterials)
{ {
material.SetColor("_Color", cloudTint); material.SetColor("_Color", cloudTint);
@ -80,7 +86,6 @@ namespace NewHorizons.Builder.Atmosphere
cloudsTopGO.layer = LayerMask.NameToLayer("IgnoreSun"); cloudsTopGO.layer = LayerMask.NameToLayer("IgnoreSun");
} }
RotateTransform topRT = cloudsTopGO.AddComponent<RotateTransform>(); RotateTransform topRT = cloudsTopGO.AddComponent<RotateTransform>();
// Idk why but the axis is weird // Idk why but the axis is weird
topRT._localAxis = atmo.UseBasicCloudShader ? Vector3.forward : Vector3.up; topRT._localAxis = atmo.UseBasicCloudShader ? Vector3.forward : Vector3.up;