Skip to content

Instantly share code, notes, and snippets.

@Roland09
Forked from HolyFot/NightLight.cs
Created August 23, 2020 09:44
Show Gist options
  • Save Roland09/5aac33421ffd6a5d5d57ed5a4363dc97 to your computer and use it in GitHub Desktop.
Save Roland09/5aac33421ffd6a5d5d57ed5a4363dc97 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