浏览代码

Use DrawProcedural instead of Blit for Screen-space Shadow Map

Because of stereo instancing issues with null source Blit, we can try using DrawProcedural.

Everything seems to work ok, except for some bizarre unity_StereoEyeIndex functionality inside of the fragment shader during instancing.
/lwrp-xr-sssm-DrawProc
Robert Srinivasiah 7 年前
当前提交
41ed1c6f
共有 2 个文件被更改,包括 25 次插入10 次删除
  1. 7
      ScriptableRenderPipeline/LightweightPipeline/LWRP/LightweightPipeline.cs
  2. 28
      ScriptableRenderPipeline/LightweightPipeline/LWRP/Shaders/LightweightScreenSpaceShadows.shader

7
ScriptableRenderPipeline/LightweightPipeline/LWRP/LightweightPipeline.cs


// doesn't like null sources when trying to determine a stereo-ized blit. So for proper
// stereo functionality, we use the screen-space shadow map as the source (until we have
// a better solution).
cmd.Blit(m_ScreenSpaceShadowMapRT, m_ScreenSpaceShadowMapRT, m_ScreenSpaceShadowsMaterial);
//cmd.Blit(m_ScreenSpaceShadowMapRT, m_ScreenSpaceShadowMapRT, m_ScreenSpaceShadowsMaterial);
//cmd.Blit(null, m_ScreenSpaceShadowMapRT, m_ScreenSpaceShadowsMaterial);
// Can't use CoreUtils.DrawFullScreen yet because it doesn't support stereo texture arrays yet
SetRenderTarget(cmd, m_ScreenSpaceShadowMapRT);
cmd.DrawProcedural(Matrix4x4.identity, m_ScreenSpaceShadowsMaterial, 0, MeshTopology.Triangles, 3, 1);
if (LightweightUtils.HasFlag(frameRenderingConfiguration, FrameRenderingConfiguration.Stereo))
context.StartMultiEye(m_CurrCamera);

28
ScriptableRenderPipeline/LightweightPipeline/LWRP/Shaders/LightweightScreenSpaceShadows.shader


UNITY_VERTEX_INPUT_INSTANCE_ID
};
struct FullScreenInput
{
uint vertexID : SV_VertexID;
UNITY_VERTEX_INPUT_INSTANCE_ID
};
struct Interpolators
{
half4 pos : SV_POSITION;

};
Interpolators Vertex(VertexInput i)
//Interpolators Vertex(VertexInput i)
Interpolators Vertex(FullScreenInput i)
{
Interpolators o;
UNITY_SETUP_INSTANCE_ID(i);

o.pos = TransformObjectToHClip(i.vertex.xyz);
//o.pos = TransformObjectToHClip(i.vertex.xyz);
o.pos = GetFullScreenTriangleVertexPosition(i.vertexID);
o.texcoord.xy = UnityStereoTransformScreenSpaceTex(i.texcoord.xy);
//o.texcoord.xy = UnityStereoTransformScreenSpaceTex(i.texcoord.xy);
o.texcoord.xy = GetFullScreenTriangleTexCoord(i.vertexID);
o.texcoord.zw = projPos.xy;
return o;

UNITY_SETUP_INSTANCE_ID(i);
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(i);
// TODO
// declare texture correctly as tex2darray
// pass in stereo eye index in correctly so it can sample texture
// Fix up sampling from a depth texture array
float2 adjTexCoords = UnityStereoTransformScreenSpaceTex(i.texcoord.xy);
float deviceDepth = SAMPLE_TEXTURE2D_ARRAY(_CameraDepthTexture, sampler_CameraDepthTexture, i.texcoord.xy, unity_StereoEyeIndex).r;
// Completely unclear why i.stereoTargetEyeIndex doesn't work here, considering
// this has to be correct in order for the texture array slices to be rasterized to
unity_StereoEyeIndex = i.instanceID;
float deviceDepth = SAMPLE_TEXTURE2D_ARRAY(_CameraDepthTexture, sampler_CameraDepthTexture, adjTexCoords, unity_StereoEyeIndex).r;
float deviceDepth = SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, sampler_CameraDepthTexture, i.texcoord.xy);
float deviceDepth = SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, sampler_CameraDepthTexture, adjTexCoords);
#endif
#if UNITY_REVERSED_Z

正在加载...
取消
保存