SHARE
TWEET

Untitled

a guest Mar 18th, 2019 51 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using UnityEngine;
  2. using UnityEngine.Rendering;
  3.  
  4. [RequireComponent(typeof(Camera))]
  5. public class RawShadowmapDepth : MonoBehaviour
  6. {
  7.     public Light m_Light;
  8.     RenderTexture m_ShadowmapCopy;
  9.     public Material mat;
  10.  
  11.     void Start()
  12.     {
  13.         RenderTargetIdentifier shadowmap = BuiltinRenderTextureType.CurrentActive;
  14.         m_ShadowmapCopy = new RenderTexture(1024, 1024, 0);
  15.         CommandBuffer cb = new CommandBuffer();
  16.  
  17.         // Change shadow sampling mode for m_Light's shadowmap.
  18.         cb.SetShadowSamplingMode(shadowmap, ShadowSamplingMode.RawDepth);
  19.  
  20.         // The shadowmap values can now be sampled normally - copy it to a different render texture.
  21.         cb.Blit(shadowmap, new RenderTargetIdentifier(m_ShadowmapCopy));
  22.  
  23.         // Execute after the shadowmap has been filled.
  24.         m_Light.AddCommandBuffer(LightEvent.AfterShadowMap, cb);
  25.  
  26.         // Sampling mode is restored automatically after this command buffer completes, so shadows will render normally.
  27.         mat.SetTexture("m_ShadowmapCopy", m_ShadowmapCopy);
  28.     }
  29.  
  30.     void OnRenderImage(RenderTexture src, RenderTexture dest)
  31.     {
  32.         // Display the shadowmap in the corner.
  33.         //Camera.main.rect = new Rect(0, 0, 0.5f, 0.5f);
  34.         //Graphics.Blit(m_ShadowmapCopy, mat);
  35.         //mat.SetTexture("m_ShadowmapCopy", m_ShadowmapCopy);
  36.         Graphics.Blit(src, dest);
  37.         //Camera.main.rect = new Rect(0, 0, 1, 1);
  38.     }
  39. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top