mirror of
https://github.com/Outer-Wilds-New-Horizons/new-horizons.git
synced 2025-12-11 20:15:44 +01:00
Make cloud fog default to prefab if no tint is given #182
This commit is contained in:
parent
b8e326ad63
commit
eff2ab8ad9
@ -8,6 +8,7 @@ using NewHorizons.Utility.OWML;
|
||||
using OWML.Common;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Tessellation;
|
||||
using UnityEngine;
|
||||
|
||||
@ -15,11 +16,12 @@ namespace NewHorizons.Builder.Atmosphere
|
||||
{
|
||||
public static class CloudsBuilder
|
||||
{
|
||||
private static Material[] _gdCloudMaterials;
|
||||
private static Material[] _qmCloudMaterials;
|
||||
private static Material[] _qmBottomMaterials;
|
||||
private static Material[] _gdCloudMaterials, _gdBottomMaterials;
|
||||
private static Mesh _gdTopCloudMesh;
|
||||
private static Tessellation.MeshGroup _qmBottomMeshGroup;
|
||||
|
||||
private static Material[] _qmCloudMaterials, _qmBottomMaterials;
|
||||
private static MeshGroup _qmBottomMeshGroup;
|
||||
|
||||
private static Material _transparentCloud;
|
||||
private static GameObject _lightningPrefab;
|
||||
private static Texture2D _colorRamp;
|
||||
@ -41,10 +43,14 @@ namespace NewHorizons.Builder.Atmosphere
|
||||
_isInit = true;
|
||||
|
||||
if (_lightningPrefab == null) _lightningPrefab = SearchUtilities.Find("GiantsDeep_Body/Sector_GD/Clouds_GD/LightningGenerator_GD").InstantiateInactive().Rename("LightningGenerator").DontDestroyOnLoad();
|
||||
|
||||
if (_gdTopCloudMesh == null) _gdTopCloudMesh = SearchUtilities.Find("CloudsTopLayer_GD").GetComponent<MeshFilter>().mesh.DontDestroyOnLoad();
|
||||
if (_gdCloudMaterials == null) _gdCloudMaterials = SearchUtilities.Find("CloudsTopLayer_GD").GetComponent<MeshRenderer>().sharedMaterials.MakePrefabMaterials();
|
||||
if (_gdBottomMaterials == null) _gdBottomMaterials = SearchUtilities.Find("CloudsBottomLayer_GD").GetComponent<TessellatedSphereRenderer>().sharedMaterials.MakePrefabMaterials();
|
||||
|
||||
if (_qmCloudMaterials == null) _qmCloudMaterials = SearchUtilities.Find("CloudsTopLayer_QM").GetComponent<MeshRenderer>().sharedMaterials.MakePrefabMaterials();
|
||||
if (_qmBottomMaterials == null) _qmBottomMaterials = SearchUtilities.Find("CloudsBottomLayer_QM").GetComponent<TessellatedSphereRenderer>().sharedMaterials.MakePrefabMaterials();
|
||||
|
||||
if (_qmBottomMeshGroup == null)
|
||||
{
|
||||
var originalMeshGroup = SearchUtilities.Find("CloudsBottomLayer_QM").GetComponent<TessellatedSphereRenderer>().tessellationMeshGroup;
|
||||
@ -67,7 +73,7 @@ namespace NewHorizons.Builder.Atmosphere
|
||||
{
|
||||
InitPrefabs();
|
||||
|
||||
GameObject cloudsMainGO = new GameObject("Clouds");
|
||||
var cloudsMainGO = new GameObject("Clouds");
|
||||
cloudsMainGO.SetActive(false);
|
||||
cloudsMainGO.transform.parent = sector?.transform ?? planetGO.transform;
|
||||
|
||||
@ -81,20 +87,24 @@ namespace NewHorizons.Builder.Atmosphere
|
||||
return;
|
||||
}
|
||||
|
||||
GameObject cloudsBottomGO = new GameObject("BottomClouds");
|
||||
var cloudsBottomGO = new GameObject("BottomClouds");
|
||||
cloudsBottomGO.SetActive(false);
|
||||
cloudsBottomGO.transform.parent = cloudsMainGO.transform;
|
||||
cloudsBottomGO.transform.localScale = Vector3.one * atmo.clouds.innerCloudRadius;
|
||||
|
||||
TessellatedSphereRenderer bottomTSR = cloudsBottomGO.AddComponent<TessellatedSphereRenderer>();
|
||||
var bottomTSR = cloudsBottomGO.AddComponent<TessellatedSphereRenderer>();
|
||||
bottomTSR.tessellationMeshGroup = _qmBottomMeshGroup;
|
||||
var bottomTSRMaterials = _qmBottomMaterials;
|
||||
|
||||
// If they set a colour apply it to all the materials else keep the default QM one
|
||||
if (atmo.clouds.tint != null)
|
||||
var bottomTSRMaterials = atmo.clouds.cloudsPrefab == CloudPrefabType.GiantsDeep ? _gdBottomMaterials : _qmBottomMaterials;
|
||||
|
||||
// If they set a colour apply it to all the materials else keep the defaults
|
||||
if (atmo.clouds.tint == null)
|
||||
{
|
||||
bottomTSR.sharedMaterials = bottomTSRMaterials.Select(x => new Material(x)).ToArray();
|
||||
}
|
||||
else
|
||||
{
|
||||
var bottomColor = atmo.clouds.tint.ToColor();
|
||||
|
||||
var bottomTSRTempArray = new Material[2];
|
||||
|
||||
bottomTSRTempArray[0] = new Material(bottomTSRMaterials[0]);
|
||||
@ -105,34 +115,34 @@ namespace NewHorizons.Builder.Atmosphere
|
||||
|
||||
bottomTSR.sharedMaterials = bottomTSRTempArray;
|
||||
}
|
||||
else
|
||||
{
|
||||
bottomTSR.sharedMaterials = bottomTSRMaterials;
|
||||
}
|
||||
|
||||
bottomTSR.maxLOD = 6;
|
||||
bottomTSR.LODBias = 0;
|
||||
bottomTSR.LODRadius = 1f;
|
||||
|
||||
if (cloaked)
|
||||
{
|
||||
cloudsBottomGO.AddComponent<CloakedTessSphereSectorToggle>()._sector = sector;
|
||||
}
|
||||
else
|
||||
{
|
||||
cloudsBottomGO.AddComponent<TessSphereSectorToggle>()._sector = sector;
|
||||
}
|
||||
|
||||
GameObject cloudsFluidGO = new GameObject("CloudsFluid");
|
||||
var cloudsFluidGO = new GameObject("CloudsFluid");
|
||||
cloudsFluidGO.SetActive(false);
|
||||
cloudsFluidGO.layer = Layer.BasicEffectVolume;
|
||||
cloudsFluidGO.transform.parent = cloudsMainGO.transform;
|
||||
|
||||
SphereCollider fluidSC = cloudsFluidGO.AddComponent<SphereCollider>();
|
||||
var fluidSC = cloudsFluidGO.AddComponent<SphereCollider>();
|
||||
fluidSC.isTrigger = true;
|
||||
fluidSC.radius = atmo.clouds.outerCloudRadius;
|
||||
|
||||
OWShellCollider fluidOWSC = cloudsFluidGO.AddComponent<OWShellCollider>();
|
||||
var fluidOWSC = cloudsFluidGO.AddComponent<OWShellCollider>();
|
||||
fluidOWSC._innerRadius = atmo.clouds.innerCloudRadius;
|
||||
|
||||
// copied from gd
|
||||
CloudLayerFluidVolume fluidCLFV = cloudsFluidGO.AddComponent<CloudLayerFluidVolume>();
|
||||
var fluidCLFV = cloudsFluidGO.AddComponent<CloudLayerFluidVolume>();
|
||||
fluidCLFV._layer = 5;
|
||||
fluidCLFV._priority = 1;
|
||||
fluidCLFV._density = 1.2f;
|
||||
@ -212,6 +222,7 @@ namespace NewHorizons.Builder.Atmosphere
|
||||
|
||||
if (atmo.clouds.capPath == null) cap = ImageUtilities.ClearTexture(128, 128, wrap: true);
|
||||
else cap = ImageUtilities.GetTexture(mod, atmo.clouds.capPath, wrap: true);
|
||||
|
||||
if (atmo.clouds.rampPath == null) ramp = ImageUtilities.CanvasScaled(image, 1, image.height);
|
||||
else ramp = ImageUtilities.GetTexture(mod, atmo.clouds.rampPath);
|
||||
}
|
||||
@ -221,17 +232,17 @@ namespace NewHorizons.Builder.Atmosphere
|
||||
return null;
|
||||
}
|
||||
|
||||
GameObject cloudsTopGO = new GameObject("TopClouds");
|
||||
var cloudsTopGO = new GameObject("TopClouds");
|
||||
cloudsTopGO.SetActive(false);
|
||||
cloudsTopGO.transform.parent = rootObject.transform;
|
||||
cloudsTopGO.transform.localScale = Vector3.one * atmo.clouds.outerCloudRadius;
|
||||
|
||||
MeshFilter topMF = cloudsTopGO.AddComponent<MeshFilter>();
|
||||
var topMF = cloudsTopGO.AddComponent<MeshFilter>();
|
||||
topMF.mesh = _gdTopCloudMesh;
|
||||
|
||||
MeshRenderer topMR = cloudsTopGO.AddComponent<MeshRenderer>();
|
||||
var topMR = cloudsTopGO.AddComponent<MeshRenderer>();
|
||||
|
||||
Material[] prefabMaterials = atmo.clouds.cloudsPrefab == CloudPrefabType.GiantsDeep ? _gdCloudMaterials : _qmCloudMaterials;
|
||||
var prefabMaterials = atmo.clouds.cloudsPrefab == CloudPrefabType.GiantsDeep ? _gdCloudMaterials : _qmCloudMaterials;
|
||||
var tempArray = new Material[2];
|
||||
|
||||
if (atmo.clouds.cloudsPrefab == CloudPrefabType.Basic)
|
||||
@ -297,7 +308,7 @@ namespace NewHorizons.Builder.Atmosphere
|
||||
return null;
|
||||
}
|
||||
|
||||
GameObject cloudsTransparentGO = new GameObject("TransparentClouds");
|
||||
var cloudsTransparentGO = new GameObject("TransparentClouds");
|
||||
cloudsTransparentGO.SetActive(false);
|
||||
cloudsTransparentGO.transform.parent = rootObject.transform;
|
||||
cloudsTransparentGO.transform.localScale = Vector3.one * atmo.clouds.outerCloudRadius;
|
||||
@ -305,7 +316,7 @@ namespace NewHorizons.Builder.Atmosphere
|
||||
MeshFilter filter = cloudsTransparentGO.AddComponent<MeshFilter>();
|
||||
filter.mesh = _gdTopCloudMesh;
|
||||
|
||||
MeshRenderer renderer = cloudsTransparentGO.AddComponent<MeshRenderer>();
|
||||
var renderer = cloudsTransparentGO.AddComponent<MeshRenderer>();
|
||||
var material = new Material(_transparentCloud);
|
||||
material.name = "TransparentClouds_" + image.name;
|
||||
material.SetTexture(MainTex, image);
|
||||
@ -313,7 +324,7 @@ namespace NewHorizons.Builder.Atmosphere
|
||||
|
||||
if (!isProxy)
|
||||
{
|
||||
GameObject tcrqcGO = new GameObject("TransparentCloudRenderQueueController");
|
||||
var tcrqcGO = new GameObject("TransparentCloudRenderQueueController");
|
||||
tcrqcGO.transform.SetParent(cloudsTransparentGO.transform, false);
|
||||
tcrqcGO.layer = Layer.BasicEffectVolume;
|
||||
|
||||
@ -323,7 +334,7 @@ namespace NewHorizons.Builder.Atmosphere
|
||||
var owTriggerVolume = tcrqcGO.AddComponent<OWTriggerVolume>();
|
||||
owTriggerVolume._shape = shape;
|
||||
|
||||
TransparentCloudRenderQueueController tcrqc = tcrqcGO.AddComponent<TransparentCloudRenderQueueController>();
|
||||
var tcrqc = tcrqcGO.AddComponent<TransparentCloudRenderQueueController>();
|
||||
tcrqc.renderer = renderer;
|
||||
}
|
||||
|
||||
|
||||
@ -7,8 +7,7 @@ namespace NewHorizons.Builder.Atmosphere
|
||||
{
|
||||
private static readonly int FogColor = Shader.PropertyToID("_FogColor");
|
||||
|
||||
private static Material _gdMaterial;
|
||||
private static Material _gdCloudMaterial;
|
||||
private static Material _gdMaterial, _gdCloudMaterial;
|
||||
|
||||
private static bool _isInit;
|
||||
|
||||
@ -21,7 +20,7 @@ namespace NewHorizons.Builder.Atmosphere
|
||||
if (_gdMaterial == null) _gdMaterial = new Material(SearchUtilities.Find("GiantsDeep_Body/Sector_GD/Volumes_GD/RulesetVolumes_GD").GetComponent<EffectRuleset>()._material).DontDestroyOnLoad();
|
||||
if (_gdCloudMaterial == null) _gdCloudMaterial = new Material(SearchUtilities.Find("GiantsDeep_Body/Sector_GD/Volumes_GD/RulesetVolumes_GD").GetComponent<EffectRuleset>()._cloudMaterial).DontDestroyOnLoad();
|
||||
}
|
||||
|
||||
|
||||
public static void Make(GameObject planetGO, OWRigidbody owrb, PlanetConfig config, float sphereOfInfluence)
|
||||
{
|
||||
InitPrefabs();
|
||||
@ -59,12 +58,23 @@ namespace NewHorizons.Builder.Atmosphere
|
||||
|
||||
ER._material = _gdMaterial;
|
||||
|
||||
var cloudMaterial = new Material(_gdCloudMaterial);
|
||||
if (config.Atmosphere?.clouds?.tint != null)
|
||||
if (config.Atmosphere?.clouds != null)
|
||||
{
|
||||
cloudMaterial.SetColor(FogColor, config.Atmosphere.clouds.tint.ToColor());
|
||||
var cloudMaterial = new Material(_gdCloudMaterial);
|
||||
|
||||
if (config.Atmosphere?.clouds?.tint != null)
|
||||
{
|
||||
cloudMaterial.SetColor(FogColor, config.Atmosphere.clouds.tint.ToColor());
|
||||
}
|
||||
// For all prefabs but GD we want grey fog between clouds
|
||||
// I can't find an EffectsRuleset on the QM so I don't know how it works
|
||||
else if (config.Atmosphere.clouds.cloudsPrefab != External.Modules.CloudPrefabType.GiantsDeep)
|
||||
{
|
||||
cloudMaterial.SetColor(FogColor, new Color(43f/255f, 51f/255f, 57f/255f));
|
||||
}
|
||||
|
||||
ER._cloudMaterial = cloudMaterial;
|
||||
}
|
||||
ER._cloudMaterial = cloudMaterial;
|
||||
|
||||
volumesGO.transform.position = planetGO.transform.position;
|
||||
rulesetGO.SetActive(true);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user