Created
May 3, 2022 11:38
-
-
Save niuage/975581a0d2844a2c8150ff915b512657 to your computer and use it in GitHub Desktop.
Caustics pass for setting the light direction
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using UnityEngine.Rendering; | |
using UnityEngine.Rendering.Universal; | |
public class CausticsPass : ScriptableRenderPass | |
{ | |
private CausticsFeature.CausticsSettings settings; | |
public CausticsPass(CausticsFeature.CausticsSettings settings) | |
{ | |
this.settings = settings; | |
renderPassEvent = settings.renderPassEvent; | |
} | |
public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData) | |
{ | |
var cam = renderingData.cameraData.camera; | |
if (cam.cameraType == CameraType.Preview || !settings.causticsMaterial) return; | |
var sunMatrix = RenderSettings.sun != null | |
? RenderSettings.sun.transform.localToWorldMatrix | |
: Matrix4x4.TRS(Vector3.zero, Quaternion.Euler(-45f, 45f, 0f), Vector3.one); | |
settings.causticsMaterial.SetMatrix("_MainLightDirection", sunMatrix); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment