Transparent clouds (#338)

Adds fourth cloud prefab that allows transparency.
This commit is contained in:
Will Corby 2022-09-04 19:22:21 -07:00 committed by GitHub
commit 9192890f4c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 147 additions and 13 deletions

Binary file not shown.

View File

@ -1,14 +1,16 @@
ManifestFileVersion: 0 ManifestFileVersion: 0
CRC: 1014555239 CRC: 2022446871
Hashes: Hashes:
AssetFileHash: AssetFileHash:
serializedVersion: 2 serializedVersion: 2
Hash: 45fa3430ee7bea1e8384e57927fc0f76 Hash: 083882699617744b8fc49234bb8cb795
TypeTreeHash: TypeTreeHash:
serializedVersion: 2 serializedVersion: 2
Hash: 55d48f4ad9c3b13330b9eb5ee5686477 Hash: 10a6a558690295dadb3dd990eda0821a
HashAppended: 0 HashAppended: 0
ClassTypes: ClassTypes:
- Class: 21
Script: {instanceID: 0}
- Class: 48 - Class: 48
Script: {instanceID: 0} Script: {instanceID: 0}
SerializeReferenceClassIdentifiers: [] SerializeReferenceClassIdentifiers: []
@ -18,6 +20,7 @@ Assets:
- Assets/Shaders/SphereTextureWrapperNormal.shader - Assets/Shaders/SphereTextureWrapperNormal.shader
- Assets/Shaders/UnlitRing1Pixel.shader - Assets/Shaders/UnlitRing1Pixel.shader
- Assets/Shaders/UnlitTransparent.shader - Assets/Shaders/UnlitTransparent.shader
- Assets/Resources/TransparentCloud.mat
- Assets/Shaders/StandardCullOFF.shader - Assets/Shaders/StandardCullOFF.shader
- Assets/Shaders/Ring1Pixel.shader - Assets/Shaders/Ring1Pixel.shader
Dependencies: [] Dependencies: []

View File

@ -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); material.SetFloat(OuterRadius, atmosphereModule.size * 1.2f);
if (atmosphereModule.atmosphereTint != null) material.SetColor(SkyColor, atmosphereModule.atmosphereTint.ToColor()); if (atmosphereModule.atmosphereTint != null) material.SetColor(SkyColor, atmosphereModule.atmosphereTint.ToColor());

View File

@ -11,6 +11,7 @@ namespace NewHorizons.Builder.Atmosphere
{ {
private static Material[] _gdCloudMaterials; private static Material[] _gdCloudMaterials;
private static Material[] _qmCloudMaterials; private static Material[] _qmCloudMaterials;
private static Material _transparentCloud;
private static GameObject _lightningPrefab; private static GameObject _lightningPrefab;
private static Texture2D _colorRamp; private static Texture2D _colorRamp;
private static readonly int Color = Shader.PropertyToID("_Color"); 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 MainTex = Shader.PropertyToID("_MainTex");
private static readonly int RampTex = Shader.PropertyToID("_RampTex"); private static readonly int RampTex = Shader.PropertyToID("_RampTex");
private static readonly int CapTex = Shader.PropertyToID("_CapTex"); 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) 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.SetActive(false);
cloudsMainGO.transform.parent = sector?.transform ?? planetGO.transform; 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"); GameObject cloudsBottomGO = new GameObject("BottomClouds");
cloudsBottomGO.SetActive(false); cloudsBottomGO.SetActive(false);
@ -114,7 +124,7 @@ namespace NewHorizons.Builder.Atmosphere
lightning.transform.localPosition = Vector3.zero; lightning.transform.localPosition = Vector3.zero;
var lightningGenerator = lightning.GetComponent<CloudLightningGenerator>(); var lightningGenerator = lightning.GetComponent<CloudLightningGenerator>();
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) if (noAudio)
{ {
lightningGenerator._audioPrefab = null; lightningGenerator._audioPrefab = null;
@ -177,7 +187,7 @@ namespace NewHorizons.Builder.Atmosphere
var material = new Material(Shader.Find("Standard")); var material = new Material(Shader.Find("Standard"));
if (atmo.clouds.unlit) material.renderQueue = 3000; if (atmo.clouds.unlit) material.renderQueue = 3000;
material.name = atmo.clouds.unlit ? "BasicCloud" : "BasicShadowCloud"; material.name = atmo.clouds.unlit ? "BasicCloud" : "BasicShadowCloud";
material.SetFloat(279, 0f); // smoothness material.SetFloat(Smoothness, 0f);
tempArray[0] = material; tempArray[0] = material;
} }
else else
@ -218,5 +228,65 @@ namespace NewHorizons.Builder.Atmosphere
return cloudsTopGO; 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<MeshFilter>();
filter.mesh = SearchUtilities.Find("CloudsTopLayer_GD").GetComponent<MeshFilter>().mesh;
MeshRenderer renderer = cloudsTransparentGO.AddComponent<MeshRenderer>();
if (_transparentCloud == null) _transparentCloud = Main.NHAssetBundle.LoadAsset<Material>("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<SphereShape>();
shape.radius = 1;
var owTriggerVolume = tcrqcGO.AddComponent<OWTriggerVolume>();
owTriggerVolume._shape = shape;
TransparentCloudRenderQueueController tcrqc = tcrqcGO.AddComponent<TransparentCloudRenderQueueController>();
tcrqc.renderer = renderer;
}
if (atmo.clouds.rotationSpeed != 0f)
{
var rt = cloudsTransparentGO.AddComponent<RotateTransform>();
rt._localAxis = Vector3.up;
rt._degreesPerSecond = atmo.clouds.rotationSpeed;
rt._randomizeRotationRate = false;
}
cloudsTransparentGO.transform.localPosition = Vector3.zero;
cloudsTransparentGO.SetActive(true);
return cloudsTransparentGO;
}
} }
} }

View File

@ -21,7 +21,6 @@ namespace NewHorizons.Builder.Atmosphere
SCG._waitForStreaming = false; SCG._waitForStreaming = false;
var minHeight = surfaceSize; var minHeight = surfaceSize;
var maxHeight = config.Atmosphere.size;
if (config.HeightMap?.minHeight != null) if (config.HeightMap?.minHeight != null)
{ {
if (config.Water?.size >= config.HeightMap.minHeight) minHeight = config.Water.size; // use sea level if its higher 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.Water?.size != null) minHeight = config.Water.size;
else if (config.Lava?.size != null) minHeight = config.Lava.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) if (config.Atmosphere.hasRain)
{ {
var rainGO = GameObject.Instantiate(SearchUtilities.Find("GiantsDeep_Body/Sector_GD/Sector_GDInterior/Effects_GDInterior/Effects_GD_Rain"), effectsGO.transform); var rainGO = GameObject.Instantiate(SearchUtilities.Find("GiantsDeep_Body/Sector_GD/Sector_GDInterior/Effects_GDInterior/Effects_GD_Rain"), effectsGO.transform);

View File

@ -111,7 +111,8 @@ namespace NewHorizons.Builder.Body
if (body.Config.Atmosphere.clouds != null) if (body.Config.Atmosphere.clouds != null)
{ {
topClouds = CloudsBuilder.MakeTopClouds(proxy, body.Config.Atmosphere, body.Mod).GetComponent<MeshRenderer>(); if (body.Config.Atmosphere.clouds.cloudsPrefab != External.Modules.CloudPrefabType.Transparent) topClouds = CloudsBuilder.MakeTopClouds(proxy, body.Config.Atmosphere, body.Mod).GetComponent<MeshRenderer>();
else topClouds = CloudsBuilder.MakeTransparentClouds(proxy, body.Config.Atmosphere, body.Mod, true).GetAddComponent<MeshRenderer>();
if (body.Config.Atmosphere.clouds.hasLightning) lightningGenerator = CloudsBuilder.MakeLightning(proxy, null, body.Config.Atmosphere, true); if (body.Config.Atmosphere.clouds.hasLightning) lightningGenerator = CloudsBuilder.MakeLightning(proxy, null, body.Config.Atmosphere, true);

View File

@ -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<OWTriggerVolume>();
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;
}
}
}

View File

@ -30,6 +30,8 @@ namespace NewHorizons.External.Modules
[EnumMember(Value = @"quantumMoon")] QuantumMoon = 1, [EnumMember(Value = @"quantumMoon")] QuantumMoon = 1,
[EnumMember(Value = @"basic")] Basic = 2, [EnumMember(Value = @"basic")] Basic = 2,
[EnumMember(Value = @"transparent")] Transparent = 3,
} }
[JsonObject] [JsonObject]

View File

@ -590,7 +590,7 @@ namespace NewHorizons.Handlers
if (!string.IsNullOrEmpty(body.Config.Atmosphere?.clouds?.texturePath)) if (!string.IsNullOrEmpty(body.Config.Atmosphere?.clouds?.texturePath))
{ {
CloudsBuilder.Make(go, sector, body.Config.Atmosphere, willHaveCloak, body.Mod); 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) if (body.Config.Atmosphere.hasRain || body.Config.Atmosphere.hasSnow)

View File

@ -89,7 +89,7 @@ namespace NewHorizons.Handlers
heightMap.minHeight = body.Config.HeightMap.minHeight * size / body.Config.HeightMap.maxHeight; heightMap.minHeight = body.Config.HeightMap.minHeight * size / body.Config.HeightMap.maxHeight;
heightMap.stretch = body.Config.HeightMap.stretch; 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 // Hacky but whatever I just want a sphere
size = Mathf.Clamp(body.Config.Atmosphere.size / 10, minSize, maxSize); size = Mathf.Clamp(body.Config.Atmosphere.size / 10, minSize, maxSize);

View File

@ -400,12 +400,14 @@
"x-enumNames": [ "x-enumNames": [
"GiantsDeep", "GiantsDeep",
"QuantumMoon", "QuantumMoon",
"Basic" "Basic",
"Transparent"
], ],
"enum": [ "enum": [
"giantsDeep", "giantsDeep",
"quantumMoon", "quantumMoon",
"basic" "basic",
"transparent"
] ]
}, },
"FluidType": { "FluidType": {