Advertisement
Staggart

Stylized Grass v1.2.1 - Set perspective correction direction

Feb 22nd, 2022
1,454
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.00 KB | None | 0 0
  1. using UnityEngine;
  2. using UnityEngine.Rendering;
  3.  
  4. namespace StylizedGrass
  5. {
  6.     [ExecuteInEditMode]
  7.     public class SetGrassForwardDir : MonoBehaviour
  8.     {
  9.         private static readonly int _CameraForwardVector = Shader.PropertyToID("_CameraForwardVector");
  10.         private Vector4 vector;
  11.        
  12.         private void OnEnable()
  13.         {
  14.             RenderPipelineManager.beginCameraRendering += OnCameraRender;
  15.         }
  16.  
  17.         private void OnDisable()
  18.         {
  19.             RenderPipelineManager.beginCameraRendering -= OnCameraRender;
  20.            
  21.             Shader.SetGlobalVector(_CameraForwardVector, Vector4.zero);
  22.         }
  23.  
  24.         private void OnCameraRender(ScriptableRenderContext context, Camera targetCamera)
  25.         {
  26.             vector = targetCamera.transform.forward;
  27.             //If the .w component is 1, the shader starts using this vector
  28.             vector.w = 1f;
  29.            
  30.             Shader.SetGlobalVector(_CameraForwardVector, vector);
  31.         }
  32.     }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement