unity 拿shadowmap/ sample shadow map/拿_ShadowMapTexture

https://gamedev.stackexchange.com/questions/96051/unity-5-how-to-get-a-shadowmap

UNITY_DECLARE_SHADOWMAP(tex) - declares a shadowmap texture variable with name tex”. UNITY_SAMPLE_SHADOW(tex,uv) - samples shadowmap texture tex at given uv coordinate (XY components are texture location, Z component is depth to compare with). Returns single float value with the shadow term in 0..1 range. UNITY_SAMPLE_SHADOW_PROJ(tex,uv) - similar to above, but does a projective shadowmap read. uv is a float4, all other components are divided by .w for doing the lookup.

https://docs.unity3d.com/Manual/SL-BuiltinMacros.html

https://docs.unity3d.com/ScriptReference/Rendering.CommandBuffer.SetShadowSamplingMode.html

using UnityEngine;
using UnityEngine.Rendering;

[RequireComponent(typeof(Camera))] public class RawShadowmapDepth : MonoBehaviour { public Light m_Light; RenderTexture m_ShadowmapCopy;

void Start() { RenderTargetIdentifier shadowmap = BuiltinRenderTextureType.CurrentActive; m_ShadowmapCopy = new RenderTexture(1024, 1024, 0); CommandBuffer cb = new CommandBuffer();

// Change shadow sampling mode for m_Light's shadowmap. cb.SetShadowSamplingMode(shadowmap, ShadowSamplingMode.RawDepth);

// The shadowmap values can now be sampled normally - copy it to a different render texture. cb.Blit(shadowmap, new RenderTargetIdentifier(m_ShadowmapCopy));

// Execute after the shadowmap has been filled. m_Light.AddCommandBuffer(LightEvent.AfterShadowMap, cb);

// Sampling mode is restored automatically after this command buffer completes, so shadows will render normally. }

void OnRenderImage(RenderTexture src, RenderTexture dest) { // Display the shadowmap in the corner. Camera.main.rect = new Rect(0, 0, 0.5f, 0.5f); Graphics.Blit(m_ShadowmapCopy, dest); Camera.main.rect = new Rect(0, 0, 1, 1); } }
=================
拿 _CameraDepthTexture
https://docs.unity3d.com/Manual/SL-CameraDepthTexture.html
声明下
 _CameraDepthTexture就可以了
 

猜你喜欢

转载自www.cnblogs.com/minggoddess/p/9473254.html