Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using UnityEngine.Rendering;
- namespace StylizedGrass
- {
- [ExecuteInEditMode]
- public class SetGrassForwardDir : MonoBehaviour
- {
- private static readonly int _CameraForwardVector = Shader.PropertyToID("_CameraForwardVector");
- private Vector4 vector;
- private void OnEnable()
- {
- RenderPipelineManager.beginCameraRendering += OnCameraRender;
- }
- private void OnDisable()
- {
- RenderPipelineManager.beginCameraRendering -= OnCameraRender;
- Shader.SetGlobalVector(_CameraForwardVector, Vector4.zero);
- }
- private void OnCameraRender(ScriptableRenderContext context, Camera targetCamera)
- {
- vector = targetCamera.transform.forward;
- //If the .w component is 1, the shader starts using this vector
- vector.w = 1f;
- Shader.SetGlobalVector(_CameraForwardVector, vector);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement