Skip to content

Instantly share code, notes, and snippets.

@HolyFot
Created August 23, 2020 04:42
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save HolyFot/00f729a201a42037be5a5e1ec4c79db5 to your computer and use it in GitHub Desktop.
Save HolyFot/00f729a201a42037be5a5e1ec4c79db5 to your computer and use it in GitHub Desktop.
Enviro Scripts
using UnityEngine;
using System.Collections.Generic;
public class NightLight : MonoBehaviour
{
[SerializeField] public List<GameObject> objects;
public bool isNight = false;
private void Awake()
{
InvokeRepeating("EnviroCheck", 4.0f, 4.0f);
}
private void EnviroCheck()
{
if (EnviroSkyMgr.instance.IsNight())
{
//Night Time
if (!isNight)
{
if (objects != null)
{
for (int i = 0; i < objects.Count; i++)
{
objects[i].SetActive(true);
}
}
isNight = true;
//Debug.Log("[NightLight] Turned lights on.");
}
}
else
{
//Day Time
if (isNight)
{
if (objects != null)
{
for (int i = 0; i < objects.Count; i++)
{
objects[i].SetActive(false);
}
}
//Debug.Log("[NightLight] Turned off lights.");
isNight = false;
}
}
}
}
//Adjusts Fog Volumetrics for Enviro
//Editing HDRP Shadows/Highlights doesn't seem to work
//By HolyFot
using UnityEngine;
#if UNITY_2019_3 || UNITY_2019_4
using UnityEngine.Rendering;
using UnityEngine.Rendering.HighDefinition;
#else
using UnityEngine.Experimental.Rendering.HDPipeline;
#endif
public class PostAdjuster : MonoBehaviour
{
[SerializeField] public VolumeProfile post;
[SerializeField] public VolumeProfile fogPost;
//[SerializeField] public Color dayTimeShadows;
//[SerializeField] public Color nightTimeShadows;
//[SerializeField] public Color dayTimeHighlights;
//[SerializeField] public Color nightTimeHighlights;
[SerializeField] public float dayTimeAnisotropy;
[SerializeField] public float nightTimeAnisotropy;
[SerializeField] public float nightTimeShadows = 0.2f;
[SerializeField] public float dayTimeShadows = 0.7f;
[SerializeField] public float nightTimeVolumetric = 1f;
[SerializeField] public float dayTimeVolumetric = 5f;
[SerializeField] Light light1;
private ShadowsMidtonesHighlights shadowz;
private SplitToning splitTone;
private Fog fog1;
public bool isNight = false;
private void Awake()
{
post = GameOptions.Instance.hdrpProfile;
Debug.Log("Enviro PP Adjuster Started.");
/*for (int i = 0; i < post.components.Count; i++)
{
if (post.components[i].name.Contains("SplitToning"))
{
splitTone = (SplitToning)post.components[i];
}
}*/
/*for (int i = 0; i < post.components.Count; i++)
{
if (post.components[i].name.Contains("ShadowsMidtonesHighlights"))
{
shadowz = (ShadowsMidtonesHighlights)post.components[i];
}
}*/
for (int i = 0; i < fogPost.components.Count; i++)
{
if (fogPost.components[i].name.Contains("Fog"))
{
fog1 = (Fog)fogPost.components[i];
}
}
InvokeRepeating("EnviroCheck", 4.0f, 4.0f);
}
private void EnviroCheck()
{
if (EnviroSkyMgr.instance.IsNight())
{
//Night Time
if (!isNight)
{
//ColorParameter test = new ColorParameter(nightTimeShadows, false);
//splitTone.shadows = test;
//ColorParameter test2 = new ColorParameter(nightTimeHighlights, false);
//splitTone.highlights = test2;
//Fog
fog1.colorMode.value = FogColorMode.ConstantColor;
fog1.anisotropy.value = nightTimeAnisotropy;
isNight = true;
//Volumetrics
light1.GetComponent<UnityEngine.Rendering.HighDefinition.HDAdditionalLightData>().volumetricDimmer = nightTimeVolumetric;
Debug.Log("[PostAdjuster] Night time set volumetrics to: " + light1.GetComponent<UnityEngine.Rendering.HighDefinition.HDAdditionalLightData>().volumetricDimmer.ToString());
/*if (shadowz == null)
{
Debug.Log("couldnt get ShadowMidtonesHighlights");
return;
}
else
{
//New Shadows
Vector4 temp = new Vector4(1f, 1f, 1f, nightTimeShadows-1f);
Vector4Parameter shadowsNew = new Vector4Parameter(temp, true);
shadowz.shadows.SetValue(shadowsNew);
}*/
}
}
else
{
//Day Time
if (isNight)
{
//ColorParameter test = new ColorParameter(dayTimeShadows, false);
//splitTone.shadows = test;
//ColorParameter test2 = new ColorParameter(dayTimeHighlights, false);
//splitTone.highlights = test2;
//Fog
fog1.colorMode.value = FogColorMode.SkyColor;
fog1.anisotropy.value = dayTimeAnisotropy;
isNight = false;
//Volumetrics
light1.GetComponent<UnityEngine.Rendering.HighDefinition.HDAdditionalLightData>().volumetricDimmer = dayTimeVolumetric;
//Shadows
/*if (shadowz == null)
{
Debug.Log("couldnt get ShadowMidtonesHighlights");
return;
}
else
{
//New Shadows
Vector4 temp = new Vector4(1f, 1f, 1f, dayTimeShadows-1f);
Vector4Parameter shadowsNew = new Vector4Parameter(temp, true);
shadowz.shadows.SetValue(shadowsNew);
}*/
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment