浏览代码

Moved frustum corners to shadow buffer

/main
John 7 年前
当前提交
2d3db4b5
共有 5 个文件被更改,包括 15 次插入9 次删除
  1. 5
      ScriptableRenderPipeline/LightweightPipeline/LWRP/Editor/LightweightAssetEditor.cs
  2. 1
      ScriptableRenderPipeline/LightweightPipeline/LWRP/LightweightConstantBuffer.cs
  3. 12
      ScriptableRenderPipeline/LightweightPipeline/LWRP/LightweightPipeline.cs
  4. 3
      ScriptableRenderPipeline/LightweightPipeline/LWRP/ShaderLibrary/Shadows.hlsl
  5. 3
      ScriptableRenderPipeline/LightweightPipeline/LWRP/Shaders/LightweightScreenSpaceShadows.shader

5
ScriptableRenderPipeline/LightweightPipeline/LWRP/Editor/LightweightAssetEditor.cs


void UpdateAnimationValues()
{
m_ShowSoftParticles.target = m_RequireDepthTextureProp.boolValue;
m_ShowScreenSpaceShadows.target = m_RequireDepthTextureProp.boolValue;
//TODO: Right now disabling MSAA cuts the depth prepass to generate the depth texture. For now, disable SS shadows as well.
// When the depth prepass does not occur, depth is copied *after* opaque, which does not help us in this situation.
m_ShowScreenSpaceShadows.target = m_RequireDepthTextureProp.boolValue && m_MSAA.intValue > 1;
}
void DrawAnimatedProperty(SerializedProperty prop, GUIContent content, AnimBool animation)

1
ScriptableRenderPipeline/LightweightPipeline/LWRP/LightweightConstantBuffer.cs


public static int _ShadowOffset2;
public static int _ShadowOffset3;
public static int _ShadowmapSize;
public static int _FrustumCorners;
}
}

12
ScriptableRenderPipeline/LightweightPipeline/LWRP/LightweightPipeline.cs


ShadowConstantBuffer._ShadowOffset2 = Shader.PropertyToID("_ShadowOffset2");
ShadowConstantBuffer._ShadowOffset3 = Shader.PropertyToID("_ShadowOffset3");
ShadowConstantBuffer._ShadowmapSize = Shader.PropertyToID("_ShadowmapSize");
ShadowConstantBuffer._FrustumCorners = Shader.PropertyToID("_FrustumCorners");
m_ShadowMapRTID = Shader.PropertyToID("_ShadowMap");
m_ScreenSpaceShadowMapRTID = Shader.PropertyToID("_ScreenSpaceShadowMap");

if (LightweightUtils.HasFlag(frameRenderingConfiguration, FrameRenderingConfiguration.DepthPrePass))
{
DepthPass(ref context);
if(m_Asset.UsesScreenSpaceShadows) //NOTE: Should this be added to the FrameRenderingConfiguration?
if(m_UseScreenSpaceShadows) //NOTE: Should this be added to the FrameRenderingConfiguration?
ShadowCollectPass(ref context, visibleLights, ref lightData);
}

}
//NOTE: Currently shader keywords are set before the forward pass, so the collect pass is one frame behind the current keyword.
// Might be best to move keyword + constant setup before shadow collect?
private void ShadowCollectPass(ref ScriptableRenderContext context, List<VisibleLight> lights, ref LightData lightData)
{
if (m_Asset.AreShadowsEnabled() && lightData.mainLightIndex != -1)

SetupShadowReceiverConstants(cmd, lights[lightData.mainLightIndex]); //Reciever constants set up here in case of screen space shadows.
cmd.GetTemporaryRT(m_ScreenSpaceShadowMapRTID, m_CurrCamera.pixelWidth, m_CurrCamera.pixelHeight, 0, FilterMode.Bilinear, RenderTextureFormat.R8);
cmd.SetGlobalVectorArray("_FrustumCorners", LightweightUtils.GetFarPlaneCorners(m_CurrCamera)); //TODO: Move to a constant buffer. Shadow or Camera?
cmd.Blit(null, m_ScreenSpaceShadowMapRT, m_ScreenSpaceShadowsMaterial);
context.ExecuteCommandBuffer(cmd);

configuration |= FrameRenderingConfiguration.DepthPrePass;
}
}
m_UseScreenSpaceShadows = m_Asset.UsesScreenSpaceShadows && LightweightUtils.HasFlag(configuration, FrameRenderingConfiguration.DepthPrePass);
Rect cameraRect = m_CurrCamera.rect;
if (!(Math.Abs(cameraRect.x) > 0.0f || Math.Abs(cameraRect.y) > 0.0f || Math.Abs(cameraRect.width) < 1.0f || Math.Abs(cameraRect.height) < 1.0f))

// Main light has an optimized shader path for main light. This will benefit games that only care about a single light.
// Lightweight pipeline also supports only a single shadow light, if available it will be the main light.
SetupMainLightConstants(cmd, lights, lightData.mainLightIndex);
if (lightData.shadowMapSampleType != LightShadows.None && !m_Asset.UsesScreenSpaceShadows) //TODO: Nicer way to know about SSS.
if (lightData.shadowMapSampleType != LightShadows.None && !m_UseScreenSpaceShadows) //TODO: Nicer way to know about SSS.
SetupShadowReceiverConstants(cmd, lights[lightData.mainLightIndex]);
SetupAdditionalListConstants(cmd, lights, ref lightData);

cmd.SetGlobalVector(ShadowConstantBuffer._ShadowOffset2, new Vector4(-invHalfShadowResolution, invHalfShadowResolution, 0.0f, 0.0f));
cmd.SetGlobalVector(ShadowConstantBuffer._ShadowOffset3, new Vector4( invHalfShadowResolution, invHalfShadowResolution, 0.0f, 0.0f));
cmd.SetGlobalVector(ShadowConstantBuffer._ShadowmapSize, new Vector4(invShadowResolution, invShadowResolution, m_Asset.ShadowAtlasResolution, m_Asset.ShadowAtlasResolution));
cmd.SetGlobalVectorArray(ShadowConstantBuffer._FrustumCorners, LightweightUtils.GetFarPlaneCorners(m_CurrCamera));
}
private void SetShaderKeywords(CommandBuffer cmd, ref LightData lightData, List<VisibleLight> visibleLights)

if (m_Asset.CascadeCount > 1)
m_MainLightKeywordString.Append("_CASCADE");
if(m_Asset.UsesScreenSpaceShadows)
if(m_UseScreenSpaceShadows)
m_MainLightKeywordString.Append("_SCREEN");
}
else

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


half4 _ShadowOffset3;
half4 _ShadowData; // (x: shadowStrength)
float4 _ShadowmapSize; // (xy: 1/width and 1/height, zw: width and height)
float4 _FrustumCorners[4];
return SAMPLE_TEXTURE2D(_ScreenSpaceShadowMap, sampler_ScreenSpaceShadowMap, shadowCoord.xy / shadowCoord.w);
return SAMPLE_TEXTURE2D(_ScreenSpaceShadowMap, sampler_ScreenSpaceShadowMap, shadowCoord.xy / shadowCoord.w).x;
}
inline half SampleShadowmap(float4 shadowCoord)

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


//Scene Depth
TEXTURE2D(_CameraDepthTexture);
SAMPLER(sampler_CameraDepthTexture);
//Far plane corners in view space
float4 _FrustumCorners[4];
struct VertexInput
{

正在加载...
取消
保存