You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
60 lines
1.5 KiB
60 lines
1.5 KiB
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.Rendering.HighDefinition;
|
|
using UnityEngine.Rendering;
|
|
|
|
|
|
[ExecuteAlways]
|
|
public class LinkDirectionalToCustomNightSky : MonoBehaviour
|
|
{
|
|
public Material SkyMat;
|
|
Vector3 Dir;
|
|
public bool update = true;
|
|
Light mainLight;
|
|
float previousIntensity;
|
|
Color previousColor;
|
|
|
|
void OnEnable()
|
|
{
|
|
var hdrp = RenderPipelineManager.currentPipeline as HDRenderPipeline;
|
|
if (hdrp != null && hdrp.GetMainLight() != null)
|
|
{
|
|
mainLight = hdrp.GetMainLight();
|
|
|
|
//This is to force the mainlight to specific intensity and color for good presentation
|
|
previousIntensity = mainLight.intensity;
|
|
previousColor = mainLight.color;
|
|
mainLight.intensity = 1000f;
|
|
mainLight.color= new Color(0.5f,0.75f,1f,1f);
|
|
}
|
|
|
|
}
|
|
|
|
void OnDisable()
|
|
{
|
|
//Reverting the forced values
|
|
if(mainLight != null)
|
|
{
|
|
mainLight.intensity = previousIntensity;
|
|
mainLight.color= previousColor;
|
|
|
|
}
|
|
}
|
|
|
|
void Update()
|
|
{
|
|
if (update)
|
|
{
|
|
if (mainLight != null)
|
|
{
|
|
//Sending the forward vector to the material
|
|
Dir = mainLight.gameObject.transform.forward;
|
|
SkyMat.SetVector("_Moonlight_Forward_Direction", Dir);
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
|
|
}
|