Fix ring opacity (#553)

## Bug fixes
- Fix constant NRE from rings with both a scale curve and opacity curve
This commit is contained in:
Nick 2023-03-25 12:22:13 -04:00 committed by GitHub
commit 2b64edd23d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 16 deletions

View File

@ -1,14 +1,14 @@
using NewHorizons.Components; using NewHorizons.Components;
using NewHorizons.Components.SizeControllers; using NewHorizons.Components.SizeControllers;
using NewHorizons.Components.Volumes;
using NewHorizons.External.Modules;
using NewHorizons.Utility; using NewHorizons.Utility;
using NewHorizons.Utility.OWUtilities;
using OWML.Common; using OWML.Common;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using NewHorizons.External.Modules;
using UnityEngine; using UnityEngine;
using Logger = NewHorizons.Utility.Logger; using Logger = NewHorizons.Utility.Logger;
using NewHorizons.Components.Volumes;
using NewHorizons.Utility.OWUtilities;
namespace NewHorizons.Builder.Body namespace NewHorizons.Builder.Body
{ {
@ -64,14 +64,11 @@ namespace NewHorizons.Builder.Body
// Properly lit shader doesnt work yet // Properly lit shader doesnt work yet
ring.unlit = true; ring.unlit = true;
Texture2D ringTexture; var ringTexture = ImageUtilities.GetTexture(mod, ring.texture);
try
if (ringTexture == null)
{ {
ringTexture = ImageUtilities.GetTexture(mod, ring.texture); Logger.LogError($"Couldn't load Ring texture [{ring.texture}]");
}
catch (Exception e)
{
Logger.LogError($"Couldn't load Ring texture:\n{e}");
return null; return null;
} }
@ -85,7 +82,6 @@ namespace NewHorizons.Builder.Body
var ringMF = ringGO.AddComponent<MeshFilter>(); var ringMF = ringGO.AddComponent<MeshFilter>();
var ringMesh = ringMF.mesh; var ringMesh = ringMF.mesh;
var ringMR = ringGO.AddComponent<MeshRenderer>(); var ringMR = ringGO.AddComponent<MeshRenderer>();
var texture = ringTexture;
if (RingShader == null) RingShader = Main.NHAssetBundle.LoadAsset<Shader>("Assets/Shaders/Ring.shader"); if (RingShader == null) RingShader = Main.NHAssetBundle.LoadAsset<Shader>("Assets/Shaders/Ring.shader");
if (UnlitRingShader == null) UnlitRingShader = Main.NHAssetBundle.LoadAsset<Shader>("Assets/Shaders/UnlitTransparent.shader"); if (UnlitRingShader == null) UnlitRingShader = Main.NHAssetBundle.LoadAsset<Shader>("Assets/Shaders/UnlitTransparent.shader");
@ -93,14 +89,14 @@ namespace NewHorizons.Builder.Body
if (UnlitRingShader1Pixel == null) UnlitRingShader1Pixel = Main.NHAssetBundle.LoadAsset<Shader>("Assets/Shaders/UnlitRing1Pixel.shader"); if (UnlitRingShader1Pixel == null) UnlitRingShader1Pixel = Main.NHAssetBundle.LoadAsset<Shader>("Assets/Shaders/UnlitRing1Pixel.shader");
var mat = new Material(ring.unlit ? UnlitRingShader : RingShader); var mat = new Material(ring.unlit ? UnlitRingShader : RingShader);
if (texture.width == 1) if (ringTexture.width == 1)
{ {
mat = new Material(ring.unlit ? UnlitRingShader1Pixel : RingShader1Pixel); mat = new Material(ring.unlit ? UnlitRingShader1Pixel : RingShader1Pixel);
mat.SetFloat(InnerRadius, 0); mat.SetFloat(InnerRadius, 0);
} }
ringMR.receiveShadows = !ring.unlit; ringMR.receiveShadows = !ring.unlit;
mat.mainTexture = texture; mat.mainTexture = ringTexture;
// Black holes vanish behind rings // Black holes vanish behind rings
// However if we lower this to where black holes don't vanish, water becomes invisible when seen through rings // However if we lower this to where black holes don't vanish, water becomes invisible when seen through rings

View File

@ -25,10 +25,22 @@ namespace NewHorizons.Components
CurrentOpacity = 1; CurrentOpacity = 1;
} }
if (_ringFluidVolume != null) if (_ringFluidVolume != null && _ringFluidVolume.gameObject.activeInHierarchy)
{ {
if (Mathf.Approximately(CurrentOpacity, 0) && _ringFluidVolume.IsVolumeActive()) _ringFluidVolume.SetVolumeActivation(false); if (Mathf.Approximately(CurrentOpacity, 0))
else if (!_ringFluidVolume.IsVolumeActive()) _ringFluidVolume.SetVolumeActivation(true); {
if (_ringFluidVolume.IsVolumeActive())
{
_ringFluidVolume.SetVolumeActivation(false);
}
}
else
{
if (!_ringFluidVolume.IsVolumeActive())
{
_ringFluidVolume.SetVolumeActivation(true);
}
}
} }
if (_meshRenderer == null) return; if (_meshRenderer == null) return;