浏览代码

- Changed ExecuteBeforeCameraRender callback to pass pipeline instance instead of pipeline settings and renderer. (#1919)

- RenderSingleCamera now has default setup as null.
 - Removed unused code and made restricted a few interfaces/classes to internal/private.
 - Fixed typo in MaterialHandles.ScreenSpaceShadow
/main
GitHub 6 年前
当前提交
cda0e4a3
共有 11 个文件被更改,包括 59 次插入149 次删除
  1. 37
      com.unity.render-pipelines.lightweight/LWRP/Data/LightweightPipelineAsset.cs
  2. 2
      com.unity.render-pipelines.lightweight/LWRP/DefaultRendererSetup.cs
  3. 14
      com.unity.render-pipelines.lightweight/LWRP/Editor/LightweightPipelineAssetEditor.cs
  4. 32
      com.unity.render-pipelines.lightweight/LWRP/Editor/ShaderPreprocessor.cs
  5. 42
      com.unity.render-pipelines.lightweight/LWRP/LightweightPipeline.cs
  6. 57
      com.unity.render-pipelines.lightweight/LWRP/LightweightPipelineCore.cs
  7. 2
      com.unity.render-pipelines.lightweight/LWRP/MaterialHandles.cs
  8. 2
      com.unity.render-pipelines.lightweight/LWRP/Passes/ScreenSpaceShadowResolvePass.cs
  9. 2
      com.unity.render-pipelines.lightweight/LWRP/SceneViewDrawMode.cs
  10. 7
      com.unity.render-pipelines.lightweight/LWRP/RenderTargetHandles.cs
  11. 11
      com.unity.render-pipelines.lightweight/LWRP/RenderTargetHandles.cs.meta

37
com.unity.render-pipelines.lightweight/LWRP/Data/LightweightPipelineAsset.cs


[SerializeField] bool m_LocalShadowsSupported = true;
[SerializeField] ShadowResolution m_LocalShadowsAtlasResolution = ShadowResolution._512;
[SerializeField] bool m_SoftShadowsSupported = false;
[SerializeField] bool m_KeepAdditionalLightVariants = true;
[SerializeField] bool m_KeepVertexLightVariants = true;
[SerializeField] bool m_KeepDirectionalShadowVariants = true;
[SerializeField] bool m_KeepLocalShadowVariants = true;
[SerializeField] bool m_KeepSoftShadowVariants = true;
[SerializeField] XRGraphicsConfig m_SavedXRConfig = XRGraphicsConfig.s_DefaultXRConfig;
[SerializeField] XRGraphicsConfig m_SavedXRConfig = XRGraphicsConfig.s_DefaultXRConfig;
// Deprecated
[SerializeField] ShadowType m_ShadowType = ShadowType.HARD_SHADOWS;

public bool supportsSoftShadows
{
get { return m_SoftShadowsSupported; }
}
public bool customShaderVariantStripping
{
get { return false; }
}
public bool keepAdditionalLightVariants
{
get { return m_KeepAdditionalLightVariants; }
}
public bool keepVertexLightVariants
{
get { return m_KeepVertexLightVariants; }
}
public bool keepDirectionalShadowVariants
{
get { return m_KeepDirectionalShadowVariants; }
}
public bool keepLocalShadowVariants
{
get { return m_KeepLocalShadowVariants; }
}
public bool keepSoftShadowVariants
{
get { return m_KeepSoftShadowVariants; }
}
public override Material GetDefaultMaterial()

2
com.unity.render-pipelines.lightweight/LWRP/DefaultRendererSetup.cs


namespace UnityEngine.Experimental.Rendering.LightweightPipeline
{
public class DefaultRendererSetup : IRendererSetup
internal class DefaultRendererSetup : IRendererSetup
{
private DepthOnlyPass m_DepthOnlyPass;
private DirectionalShadowsPass m_DirectionalShadowPass;

14
com.unity.render-pipelines.lightweight/LWRP/Editor/LightweightPipelineAssetEditor.cs


using System.Linq;
using UnityEditor;
using UnityEditor.AnimatedValues;
using UnityEditor.Experimental.Rendering;

public static string[] opaqueDownsamplingOptions = {"None", "2x (Bilinear)", "4x (Box)", "4x (Bilinear)"};
public static GUIContent XRConfig = new GUIContent("XR Graphics Settings", "SRP will attempt to set this configuration to the VRDevice.");
}
public static class StrippingStyles
{
public static GUIContent strippingLabel = new GUIContent("Shader Stripping");
public static GUIContent pipelineCapabilitiesLabel = new GUIContent("Pipeline Capabilities", "Select pipeline capabilities variants to be kept in the build.");
public static string[] strippingOptions = {"Automatic", "Custom"};
public static GUIContent localLightsLabel = new GUIContent("Additional Lights", "If enabled additional lights variants won't be stripped from build.");
public static GUIContent vertexLightsLabel = new GUIContent("Vertex Lights", "If enabled vertex lights variants wont' be stripped from build.");
public static GUIContent directionalShadowsLabel = new GUIContent("Directional Shadows", "If enabled directional shadows variants won't be stripped from build.");
public static GUIContent localShadowsLabel = new GUIContent("Local Shadows", "If enabled local shadows variants won't be stripped from build.");
public static GUIContent softShadowsLabel = new GUIContent("Soft Shadows", "If enabled soft shadows variants won't be stripped from build.");
}
AnimBool m_ShowSoftParticles = new AnimBool();

32
com.unity.render-pipelines.lightweight/LWRP/Editor/ShaderPreprocessor.cs


// The first one executed is the one where callbackOrder is returning the smallest number.
public int callbackOrder { get { return 0; } }
bool StripUnusedShader(PipelineCapabilities capabilities, Shader shader)
bool StripUnusedShader(ShaderFeatures features, Shader shader)
{
if (shader.name.Contains("Debug"))
return true;

if (!CoreUtils.HasFlag(capabilities, PipelineCapabilities.DirectionalShadows) &&
if (!CoreUtils.HasFlag(features, ShaderFeatures.DirectionalShadows) &&
shader.name.Contains("ScreenSpaceShadows"))
return true;

bool StripUnusedPass(PipelineCapabilities capabilities, ShaderSnippetData snippetData)
bool StripUnusedPass(ShaderFeatures features, ShaderSnippetData snippetData)
if (!CoreUtils.HasFlag(capabilities, PipelineCapabilities.DirectionalShadows) && !CoreUtils.HasFlag(capabilities, PipelineCapabilities.LocalShadows))
if (!CoreUtils.HasFlag(features, ShaderFeatures.DirectionalShadows) && !CoreUtils.HasFlag(features, ShaderFeatures.LocalShadows))
bool StripUnusedVariant(PipelineCapabilities capabilities, ShaderCompilerData compilerData)
bool StripUnusedVariant(ShaderFeatures features, ShaderCompilerData compilerData)
!CoreUtils.HasFlag(capabilities, PipelineCapabilities.AdditionalLights))
!CoreUtils.HasFlag(features, ShaderFeatures.AdditionalLights))
!CoreUtils.HasFlag(capabilities, PipelineCapabilities.VertexLights))
!CoreUtils.HasFlag(features, ShaderFeatures.VertexLights))
!CoreUtils.HasFlag(capabilities, PipelineCapabilities.DirectionalShadows))
!CoreUtils.HasFlag(features, ShaderFeatures.DirectionalShadows))
!CoreUtils.HasFlag(capabilities, PipelineCapabilities.LocalShadows))
!CoreUtils.HasFlag(features, ShaderFeatures.LocalShadows))
!CoreUtils.HasFlag(capabilities, PipelineCapabilities.SoftShadows))
!CoreUtils.HasFlag(features, ShaderFeatures.SoftShadows))
return true;
return false;

return false;
}
bool StripUnused(PipelineCapabilities capabilities, Shader shader, ShaderSnippetData snippetData, ShaderCompilerData compilerData)
bool StripUnused(ShaderFeatures features, Shader shader, ShaderSnippetData snippetData, ShaderCompilerData compilerData)
if (StripUnusedShader(capabilities, shader))
if (StripUnusedShader(features, shader))
if (StripUnusedPass(capabilities, snippetData))
if (StripUnusedPass(features, snippetData))
if (StripUnusedVariant(capabilities, compilerData))
if (StripUnusedVariant(features, compilerData))
return true;
if (StripInvalidVariants(compilerData))

if (lw == null)
return;
PipelineCapabilities capabilities = LightweightRP.GetPipelineCapabilities();
ShaderFeatures features = LightweightRP.GetSupportedShaderFeatures();
if (StripUnused(capabilities, shader, snippetData, compilerDataList[i]))
if (StripUnused(features, shader, snippetData, compilerDataList[i]))
{
compilerDataList.RemoveAt(i);
--i;

42
com.unity.render-pipelines.lightweight/LWRP/LightweightPipeline.cs


public static int _ScaledScreenParams;
}
public LightweightPipelineAsset pipelineAsset { get; private set; }
private static IRendererSetup m_DefaultRendererSetup;
private static IRendererSetup defaultRendererSetup
{

}
const string k_RenderCameraTag = "Render Camera";
ScriptableRenderer m_Renderer;
PipelineSettings m_PipelineSettings;
public ScriptableRenderer renderer { get; private set; }
public PipelineSettings settings { get; private set; }
public struct PipelineSettings
{

cache.supportsVertexLight = asset.supportsVertexLight;
cache.localShadowAtlasResolution = asset.localShadowAtlasResolution;
cache.supportsSoftShadows = asset.supportsSoftShadows;
cache.savedXRGraphicsConfig.renderScale = cache.renderScale;
cache.savedXRGraphicsConfig.viewportScale = 1.0f; // Placeholder until viewportScale is all hooked up
// Apply any changes to XRGConfig prior to this point
cache.savedXRGraphicsConfig.SetConfig();
return cache;
}
}

m_PipelineSettings = PipelineSettings.Create(asset);
settings = PipelineSettings.Create(asset);
renderer = new ScriptableRenderer(asset);
SetPipelineCapabilities(asset);
SetSupportedShaderFeatures(asset);
PerFrameBuffer._GlossyEnvironmentColor = Shader.PropertyToID("_GlossyEnvironmentColor");
PerFrameBuffer._SubtractiveShadowColor = Shader.PropertyToID("_SubtractiveShadowColor");

m_Renderer = new ScriptableRenderer(asset);
if (QualitySettings.antiAliasing != m_PipelineSettings.msaaSampleCount)
QualitySettings.antiAliasing = m_PipelineSettings.msaaSampleCount;
if (QualitySettings.antiAliasing != settings.msaaSampleCount)
QualitySettings.antiAliasing = settings.msaaSampleCount;
Shader.globalRenderPipeline = "LightweightPipeline";

SceneViewDrawMode.ResetDrawMode();
#endif
m_Renderer.Dispose();
renderer.Dispose();
Lightmapping.ResetDelegate();
}

void ExecuteBeforeCameraRender(ScriptableRenderContext context, Camera camera, PipelineSettings pipelineSettings, ScriptableRenderer renderer);
void ExecuteBeforeCameraRender(LightweightPipeline pipelineInstance, ScriptableRenderContext context, Camera camera);
m_PipelineSettings.savedXRGraphicsConfig.renderScale = m_PipelineSettings.renderScale;
m_PipelineSettings.savedXRGraphicsConfig.viewportScale = 1.0f; // Placeholder until viewportScale is all hooked up
// Apply any changes to XRGConfig prior to this point
m_PipelineSettings.savedXRGraphicsConfig.SetConfig();
base.Render(context, cameras);
BeginFrameRendering(cameras);

BeginCameraRendering(camera);
foreach (var beforeCamera in camera.GetComponents<IBeforeCameraRender>())
beforeCamera.ExecuteBeforeCameraRender(context, camera, m_PipelineSettings, m_Renderer);
beforeCamera.ExecuteBeforeCameraRender(this, context, camera);
RenderSingleCamera(context, m_PipelineSettings, camera, ref m_CullResults, camera.GetComponent<IRendererSetup>(), m_Renderer);
RenderSingleCamera(this, context, camera, ref m_CullResults, camera.GetComponent<IRendererSetup>());
public static void RenderSingleCamera(ScriptableRenderContext context, PipelineSettings settings, Camera camera, ref CullResults cullResults, IRendererSetup setup, ScriptableRenderer renderer)
public static void RenderSingleCamera(LightweightPipeline pipelineInstance, ScriptableRenderContext context, Camera camera, ref CullResults cullResults, IRendererSetup setup = null)
PipelineSettings settings = pipelineInstance.settings;
ScriptableRenderer renderer = pipelineInstance.renderer;
InitializeCameraData(settings, camera, out cameraData);
SetupPerCameraShaderConstants(cameraData);

57
com.unity.render-pipelines.lightweight/LWRP/LightweightPipelineCore.cs


using System;
using System.Collections.Generic;
using UnityEngine.Rendering;
using UnityEngine.Rendering.PostProcessing;
using UnityEngine.XR;
using UnityEngine.Experimental.Rendering;

[Flags]
public enum PipelineCapabilities
public enum ShaderFeatures
{
AdditionalLights = (1 << 0),
VertexLights = (1 << 1),

public sealed partial class LightweightPipeline
{
static PipelineCapabilities s_PipelineCapabilities;
static ShaderFeatures s_ShaderFeatures;
public static PipelineCapabilities GetPipelineCapabilities()
public static ShaderFeatures GetSupportedShaderFeatures()
return s_PipelineCapabilities;
return s_ShaderFeatures;
public void SortCameras(Camera[] cameras)
void SortCameras(Camera[] cameras)
static void SetPipelineCapabilities(LightweightPipelineAsset pipelineAsset)
static void SetSupportedShaderFeatures(LightweightPipelineAsset pipelineAsset)
s_PipelineCapabilities = 0U;
s_ShaderFeatures = 0U;
if (!pipelineAsset.customShaderVariantStripping)
{
if (pipelineAsset.maxPixelLights > 1 || pipelineAsset.supportsVertexLight)
s_PipelineCapabilities |= PipelineCapabilities.AdditionalLights;
if (pipelineAsset.supportsVertexLight)
s_PipelineCapabilities |= PipelineCapabilities.VertexLights;
if (pipelineAsset.supportsDirectionalShadows)
s_PipelineCapabilities |= PipelineCapabilities.DirectionalShadows;
if (pipelineAsset.supportsLocalShadows)
s_PipelineCapabilities |= PipelineCapabilities.LocalShadows;
bool anyShadows = pipelineAsset.supportsDirectionalShadows || pipelineAsset.supportsLocalShadows;
if (pipelineAsset.supportsSoftShadows && anyShadows)
s_PipelineCapabilities |= PipelineCapabilities.SoftShadows;
}
else
{
if (pipelineAsset.keepAdditionalLightVariants)
s_PipelineCapabilities |= PipelineCapabilities.AdditionalLights;
if (pipelineAsset.maxPixelLights > 1 || pipelineAsset.supportsVertexLight)
s_ShaderFeatures |= ShaderFeatures.AdditionalLights;
if (pipelineAsset.keepVertexLightVariants)
s_PipelineCapabilities |= PipelineCapabilities.VertexLights;
if (pipelineAsset.supportsVertexLight)
s_ShaderFeatures |= ShaderFeatures.VertexLights;
if (pipelineAsset.keepDirectionalShadowVariants)
s_PipelineCapabilities |= PipelineCapabilities.DirectionalShadows;
if (pipelineAsset.supportsDirectionalShadows)
s_ShaderFeatures |= ShaderFeatures.DirectionalShadows;
if (pipelineAsset.keepLocalShadowVariants)
s_PipelineCapabilities |= PipelineCapabilities.LocalShadows;
if (pipelineAsset.supportsLocalShadows)
s_ShaderFeatures |= ShaderFeatures.LocalShadows;
if (pipelineAsset.keepSoftShadowVariants)
s_PipelineCapabilities |= PipelineCapabilities.SoftShadows;
}
bool anyShadows = pipelineAsset.supportsDirectionalShadows || pipelineAsset.supportsLocalShadows;
if (pipelineAsset.supportsSoftShadows && anyShadows)
s_ShaderFeatures |= ShaderFeatures.SoftShadows;
}
public static bool IsStereoEnabled(Camera camera)
{

2
com.unity.render-pipelines.lightweight/LWRP/MaterialHandles.cs


DepthCopy,
Sampling,
Blit,
ScrenSpaceShadow,
ScreenSpaceShadow,
Count,
}
}

2
com.unity.render-pipelines.lightweight/LWRP/Passes/ScreenSpaceShadowResolvePass.cs


RenderTargetIdentifier screenSpaceOcclusionTexture = colorAttachmentHandle.Identifier();
SetRenderTarget(cmd, screenSpaceOcclusionTexture, RenderBufferLoadAction.DontCare, RenderBufferStoreAction.Store,
ClearFlag.Color | ClearFlag.Depth, Color.white, descriptor.dimension);
cmd.Blit(screenSpaceOcclusionTexture, screenSpaceOcclusionTexture, renderer.GetMaterial(MaterialHandles.ScrenSpaceShadow));
cmd.Blit(screenSpaceOcclusionTexture, screenSpaceOcclusionTexture, renderer.GetMaterial(MaterialHandles.ScreenSpaceShadow));
if (renderingData.cameraData.isStereoEnabled)
{

2
com.unity.render-pipelines.lightweight/LWRP/SceneViewDrawMode.cs


#if UNITY_EDITOR
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace UnityEditor.Experimental.Rendering.LightweightPipeline
{

7
com.unity.render-pipelines.lightweight/LWRP/RenderTargetHandles.cs


namespace UnityEngine.Experimental.Rendering.LightweightPipeline
{
/*public static class RenderTargetHandles
{
}*/
}

11
com.unity.render-pipelines.lightweight/LWRP/RenderTargetHandles.cs.meta


fileFormatVersion: 2
guid: 8ad204571bda59f4cae99ed240e49bd4
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存