浏览代码

Doing some hacks. Do two passes for collect shadows, do draw mesh instead of blit

/lwrp-xr-tim-hacks
Tim Cooper 7 年前
当前提交
6e7638aa
共有 4 个文件被更改,包括 42 次插入23 次删除
  1. 33
      ScriptableRenderPipeline/LightweightPipeline/LWRP/LightweightPipeline.cs
  2. 11
      ScriptableRenderPipeline/LightweightPipeline/LWRP/ShaderLibrary/Shadows.hlsl
  3. 16
      ScriptableRenderPipeline/LightweightPipeline/LWRP/Shaders/LightweightScreenSpaceShadows.shader
  4. 5
      Tests/Scripts/Editor/GraphicTests/Framework/TestFramework.cs.meta

33
ScriptableRenderPipeline/LightweightPipeline/LWRP/LightweightPipeline.cs


desc.depthBufferBits = 0;
desc.colorFormat = RenderTextureFormat.R8;
cmd.GetTemporaryRT(m_ScreenSpaceShadowMapRTID, desc, FilterMode.Bilinear);
cmd.SetRenderTarget(m_ScreenSpaceShadowMapRTID, 0, CubemapFace.Unknown, 0);
cmd.SetViewProjectionMatrices(Matrix4x4.identity, Matrix4x4.identity);
cmd.SetViewport(m_CurrCamera.pixelRect);
cmd.SetGlobalInt("unity_StereoEyeIndex", 0);
cmd.DrawMesh(blitQuad, Matrix4x4.identity, m_ScreenSpaceShadowsMaterial);
cmd.SetRenderTarget(m_ScreenSpaceShadowMapRTID, 0, CubemapFace.Unknown, 1);
cmd.SetViewProjectionMatrices(Matrix4x4.identity, Matrix4x4.identity);
cmd.SetViewport(m_CurrCamera.pixelRect);
cmd.SetGlobalInt("unity_StereoEyeIndex", 1);
cmd.DrawMesh(blitQuad, Matrix4x4.identity, m_ScreenSpaceShadowsMaterial);
cmd.Blit(Texture2D.whiteTexture, m_ScreenSpaceShadowMapRT, m_ScreenSpaceShadowsMaterial);
cmd.Blit(null, m_ScreenSpaceShadowMapRT, m_ScreenSpaceShadowsMaterial);
if (LightweightUtils.HasFlag(frameRenderingConfiguration, FrameRenderingConfiguration.Stereo))
context.StartMultiEye(m_CurrCamera);

return (Application.platform == RuntimePlatform.Android || Application.platform == RuntimePlatform.IPhonePlayer);
}
Mesh blitQuad
{
get
{
if (m_BlitQuad == null)
{
if (m_BlitQuad == null)
m_BlitQuad = LightweightUtils.CreateQuadMesh(false);
}
return m_BlitQuad;
}
}
private void Blit(CommandBuffer cmd, FrameRenderingConfiguration renderingConfig, RenderTargetIdentifier sourceRT, RenderTargetIdentifier destRT, Material material = null)
{
cmd.SetGlobalTexture(m_BlitTexID, sourceRT);

}
else
{
if (m_BlitQuad == null)
m_BlitQuad = LightweightUtils.CreateQuadMesh(false);
cmd.DrawMesh(m_BlitQuad, Matrix4x4.identity, material);
cmd.DrawMesh(blitQuad, Matrix4x4.identity, material);
}
}

11
ScriptableRenderPipeline/LightweightPipeline/LWRP/ShaderLibrary/Shadows.hlsl


#define MAX_SHADOW_CASCADES 4
#if defined(UNITY_STEREO_INSTANCING_ENABLED) || defined(UNITY_STEREO_MULTIVIEW_ENABLED)
TEXTURE2D_ARRAY(_ScreenSpaceShadowMap);
SAMPLER(sampler_ScreenSpaceShadowMap);
#else
#endif
TEXTURE2D_SHADOW(_ShadowMap);
SAMPLER_CMP(sampler_ShadowMap);

// The stereo transform has to happen after the manual perspective divide
shadowCoord.xy = UnityStereoTransformScreenSpaceTex(shadowCoord.xy);
#if defined(UNITY_STEREO_INSTANCING_ENABLED) || defined(UNITY_STEREO_MULTIVIEW_ENABLED)
float attenuation = SAMPLE_TEXTURE2D_ARRAY(_ScreenSpaceShadowMap, sampler_ScreenSpaceShadowMap, shadowCoord.xy, unity_StereoEyeIndex).x;
#else
#endif
// Apply shadow strength
return LerpWhiteTo(attenuation, GetShadowStrength());

float4 ComputeScreenSpaceShadowCoords(float3 positionWS)
{
#ifdef _SHADOWS_CASCADE
#ifdef _SHADOWS_CASCADE
half cascadeIndex = ComputeCascadeIndex(positionWS);
return mul(_WorldToShadow[cascadeIndex], float4(positionWS, 1.0));
#else

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


{
float4 vertex : POSITION;
float2 texcoord : TEXCOORD0;
UNITY_VERTEX_INPUT_INSTANCE_ID
};
struct Interpolators

UNITY_VERTEX_INPUT_INSTANCE_ID
UNITY_VERTEX_OUTPUT_STEREO
UNITY_SETUP_INSTANCE_ID(i);
UNITY_TRANSFER_INSTANCE_ID(i, o);
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
o.pos = TransformObjectToHClip(i.vertex.xyz);
o.pos = i.vertex.xyzw;
float4 projPos = o.pos * 0.5;
projPos.xy = projPos.xy + projPos.w;

half Fragment(Interpolators i) : SV_Target
{
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
#if defined(UNITY_STEREO_INSTANCING_ENABLED) || defined(UNITY_STEREO_MULTIVIEW_ENABLED)
float deviceDepth = SAMPLE_TEXTURE2D_ARRAY(_CameraDepthTexture, sampler_CameraDepthTexture, i.texcoord.xy, unity_StereoEyeIndex).r;
#else

Cull Off
HLSLPROGRAM
#pragma enable_d3d11_debug_symbols
#pragma multi_compile _ _SHADOWS_SOFT
#pragma multi_compile _ _SHADOWS_CASCADE

5
Tests/Scripts/Editor/GraphicTests/Framework/TestFramework.cs.meta


fileFormatVersion: 2
guid: ce4414d6bbf59a54686b40bffc0bab08
timeCreated: 1454664639
licenseType: Pro
guid: f4b0abe23bf749b40b6c4848774b4b22
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0

正在加载...
取消
保存