浏览代码

Merge branch 'master' into move-lw-to-lwrp

/feature-ReflectionProbeFit
sebastienlagarde 7 年前
当前提交
72c9c06e
共有 13 个文件被更改,包括 60 次插入117 次删除
  1. 15
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/HDAssetFactory.cs
  2. 4
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/HDEditorUtils.cs
  3. 2
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/HDRenderPipelineInspector.Styles.cs
  4. 20
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/HDRenderPipelineInspector.cs
  5. 6
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/HDRenderPipeline.cs
  6. 22
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/HDRenderPipelineAsset.cs
  7. 3
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/RenderPipelineResources/HDRenderPipelineResources.asset
  8. 4
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/RenderPipelineResources/RenderPipelineResources.cs
  9. 30
      ScriptableRenderPipeline/LightweightPipeline/LWRP/Data/LightweightPipelineAsset.cs
  10. 28
      ScriptableRenderPipeline/LightweightPipeline/LWRP/Editor/LightweightAssetEditor.cs
  11. 33
      ScriptableRenderPipeline/LightweightPipeline/LWRP/LightweightPipeline.cs
  12. 3
      ScriptableRenderPipeline/LightweightPipeline/LWRP/Shaders/LightweightShaderLibrary/Lighting.hlsl
  13. 7
      Tests/GraphicsTests/RenderPipeline/LightweightPipeline/LightweightPipelineAsset.asset

15
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/HDAssetFactory.cs


get { return HDEditorUtils.GetHDRenderPipelinePath() + "RenderPipelineResources/HDRenderPipelineResources.asset"; }
}
static string s_DefaultMaterialPath
{
get { return HDEditorUtils.GetHDRenderPipelinePath() + "RenderPipelineResources/DefaultHDMaterial.mat"; }
}
static string s_DefaultShaderPath
{
get { return HDEditorUtils.GetHDRenderPipelinePath() + "Material/Lit/Lit.shader"; }
}
class DoCreateNewAssetHDRenderPipeline : ProjectWindowCallback.EndNameEditAction
{
public override void Action(int instanceId, string pathName, string resourceFile)

// Load default renderPipelineResources / Material / Shader
newAsset.renderPipelineResources = AssetDatabase.LoadAssetAtPath<RenderPipelineResources>(s_RenderPipelineResourcesPath);
newAsset.defaultDiffuseMaterial = AssetDatabase.LoadAssetAtPath<Material>(s_DefaultMaterialPath);
newAsset.defaultShader = AssetDatabase.LoadAssetAtPath<Shader>(s_DefaultShaderPath);
AssetDatabase.CreateAsset(newAsset, pathName);
ProjectWindowUtil.ShowCreatedAsset(newAsset);
}

string HDRenderPipelinePath = HDEditorUtils.GetHDRenderPipelinePath();
string PostProcessingPath = HDEditorUtils.GetPostProcessingPath();
string CorePath = HDEditorUtils.GetCorePath();
newAsset.defaultDiffuseMaterial = Load<Material>(HDRenderPipelinePath + "RenderPipelineResources/DefaultHDMaterial.mat");
newAsset.defaultShader = Load<Shader>(HDRenderPipelinePath + "Material/Lit/Lit.shader");
newAsset.debugDisplayLatlongShader = Load<Shader>(HDRenderPipelinePath + "Debug/DebugDisplayLatlong.Shader");
newAsset.debugViewMaterialGBufferShader = Load<Shader>(HDRenderPipelinePath + "Debug/DebugViewMaterialGBuffer.Shader");

4
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/HDEditorUtils.cs


{
var srpPath = GetScriptableRenderPipelinePath();
if (srpPath != null)
return Path.Combine(srpPath, "ScriptableRenderPipeline/Core/CoreRP");
return Path.Combine(srpPath, "ScriptableRenderPipeline/Core/CoreRP/");
return "Packages/com.unity.render-pipelines.core/";
return "Packages/com.unity.render-pipelines.core/CoreRP/";
}
public static bool ResetMaterialKeywords(Material material)

2
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/HDRenderPipelineInspector.Styles.cs


{
public readonly GUIContent defaults = new GUIContent("Defaults");
public readonly GUIContent renderPipelineResources = new GUIContent("Render Pipeline Resources", "Set of resources that need to be loaded when creating stand alone");
public readonly GUIContent defaultDiffuseMaterial = new GUIContent("Default Diffuse Material", "Material to use when creating objects");
public readonly GUIContent defaultShader = new GUIContent("Default Shader", "Shader to use when creating materials");
public readonly GUIContent settingsLabel = new GUIContent("Settings");

20
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/HDRenderPipelineInspector.cs


public sealed partial class HDRenderPipelineInspector : HDBaseEditor<HDRenderPipelineAsset>
{
SerializedProperty m_RenderPipelineResources;
SerializedProperty m_DefaultDiffuseMaterial;
SerializedProperty m_DefaultShader;
// Global Frame Settings
// Global Render settings

void InitializeProperties()
{
m_RenderPipelineResources = properties.Find("m_RenderPipelineResources");
m_DefaultDiffuseMaterial = properties.Find("m_DefaultDiffuseMaterial");
m_DefaultShader = properties.Find("m_DefaultShader");
// Global FrameSettings
// Global Render settings

void SettingsUI(HDRenderPipelineAsset hdAsset)
{
EditorGUILayout.LabelField(s_Styles.settingsLabel, EditorStyles.boldLabel);
EditorGUI.indentLevel++;
GlobalRenderSettingsUI(hdAsset);
GlobalShadowSettingsUI(hdAsset);
GlobalLightLoopSettingsUI(hdAsset);

RendereringSettingsUI(hdAsset);
LightLoopSettingsUI(hdAsset);
EditorGUI.indentLevel--;
EditorGUILayout.Space();
EditorGUILayout.PropertyField(m_SubsurfaceScatteringSettings, s_Styles.sssSettings);
}
protected override void OnEnable()

serializedObject.Update();
EditorGUILayout.LabelField(s_Styles.defaults, EditorStyles.boldLabel);
EditorGUI.indentLevel++;
EditorGUILayout.PropertyField(m_DefaultDiffuseMaterial, s_Styles.defaultDiffuseMaterial);
EditorGUILayout.PropertyField(m_DefaultShader, s_Styles.defaultShader);
EditorGUI.indentLevel--;
EditorGUILayout.Space();
EditorGUILayout.PropertyField(m_SubsurfaceScatteringSettings, s_Styles.sssSettings);
EditorGUILayout.Space();
SettingsUI(m_Target);

6
ScriptableRenderPipeline/HDRenderPipeline/HDRP/HDRenderPipeline.cs


InitAndClearBuffer(hdCamera, enableBakeShadowMask, cmd);
RenderDepthPrepass(m_CullResults, hdCamera, renderContext, cmd, true);
RenderDepthPrepass(m_CullResults, hdCamera, renderContext, cmd);
RenderObjectsVelocity(m_CullResults, hdCamera, renderContext, cmd);

// Forward only renderer: We always render everything
// Deferred renderer: We render a depth prepass only if engine request it. We can decide if we render everything or only opaque alpha tested object.
// Forward opaque with deferred renderer (DepthForwardOnly pass): We always render everything
void RenderDepthPrepass(CullResults cull, HDCamera hdCamera, ScriptableRenderContext renderContext, CommandBuffer cmd, bool hasDecals)
void RenderDepthPrepass(CullResults cull, HDCamera hdCamera, ScriptableRenderContext renderContext, CommandBuffer cmd)
{
// In case of deferred renderer, we can have forward opaque material. These materials need to be render in the depth buffer to correctly build the light list.
// And they will tag the stencil to not be lit during the deferred lighting pass.

using (new ProfilingSample(cmd, addAlphaTestedOnly ? "Depth Prepass alpha test" : "Depth Prepass", GetSampler(CustomSamplerId.DepthPrepass)))
{
CoreUtils.SetRenderTarget(cmd, m_CameraDepthStencilBufferRT);
if (hasDecals || (addFullDepthPrepass && !addAlphaTestedOnly)) // Always true in case of forward rendering, use in case of deferred rendering if requesting a full depth prepass
if (m_FrameSettings.enableDBuffer || (addFullDepthPrepass && !addAlphaTestedOnly)) // Always true in case of forward rendering, use in case of deferred rendering if requesting a full depth prepass
{
// We render first the opaque object as opaque alpha tested are more costly to render and could be reject by early-z (but not Hi-z as it is disable with clip instruction)
// This is handled automatically with the RenderQueue value (OpaqueAlphaTested have a different value and thus are sorted after Opaque)

22
ScriptableRenderPipeline/HDRenderPipeline/HDRP/HDRenderPipelineAsset.cs


[SerializeField]
public SubsurfaceScatteringSettings sssSettings;
// Default Material / Shader
[SerializeField]
Material m_DefaultDiffuseMaterial;
[SerializeField]
Shader m_DefaultShader;
public Material defaultDiffuseMaterial
{
get { return m_DefaultDiffuseMaterial; }
set { m_DefaultDiffuseMaterial = value; }
}
public Shader defaultShader
{
get { return m_DefaultShader; }
set { m_DefaultShader = value; }
}
return m_DefaultShader;
return m_RenderPipelineResources.defaultShader;
return m_DefaultDiffuseMaterial;
return m_RenderPipelineResources.defaultDiffuseMaterial;
}
public override Material GetDefaultParticleMaterial()

3
ScriptableRenderPipeline/HDRenderPipeline/HDRP/RenderPipelineResources/HDRenderPipelineResources.asset


m_Script: {fileID: 11500000, guid: 8b6f86e1523e69a4282e92d393be89a4, type: 3}
m_Name: HDRenderPipelineResources
m_EditorClassIdentifier:
defaultDiffuseMaterial: {fileID: 2100000, guid: 73c176f402d2c2f4d929aa5da7585d17,
type: 2}
defaultShader: {fileID: 4800000, guid: 6e4ae4064600d784cac1e41a9e6f2e59, type: 3}
debugDisplayLatlongShader: {fileID: 4800000, guid: c1d1d149a043a5349ba367da6c2051ba,
type: 3}
debugViewMaterialGBufferShader: {fileID: 4800000, guid: 439949ea1bfa91b4ba0d04269fcde33d,

4
ScriptableRenderPipeline/HDRenderPipeline/HDRP/RenderPipelineResources/RenderPipelineResources.cs


{
public class RenderPipelineResources : ScriptableObject
{
// Default Material / Shader
public Material defaultDiffuseMaterial;
public Shader defaultShader;
// Debug
public Shader debugDisplayLatlongShader;
public Shader debugViewMaterialGBufferShader;

30
ScriptableRenderPipeline/LightweightPipeline/LWRP/Data/LightweightPipelineAsset.cs


[SerializeField] private Shader m_DefaultShader;
[SerializeField] private Shader m_BlitShader;
[SerializeField] private Shader m_CopyDepthShader;
[SerializeField] private LightweightPipelineResource m_ResourceAsset;
[SerializeField] private Material m_DefaultMaterial;
[SerializeField] private Material m_DefaultParticleMaterial;
[SerializeField] private Material m_DefaultTerrainMaterial;
[MenuItem("Assets/Create/Render Pipeline/Lightweight/Pipeline Asset", priority = CoreUtils.assetCreateMenuPriority1)]
static void CreateLightweightPipeline()

resourceAsset = AssetDatabase.LoadAssetAtPath<LightweightPipelineResource>(path);
}
if (resourceAsset != null)
{
instance.m_DefaultMaterial = resourceAsset.DefaultMaterial;
instance.m_DefaultParticleMaterial = resourceAsset.DefaultParticleMaterial;
instance.m_DefaultTerrainMaterial = resourceAsset.DefaultTerrainMaterial;
}
instance.m_ResourceAsset = resourceAsset;
instance.m_DefaultShader = Shader.Find(LightweightShaderUtils.GetShaderPath(ShaderPathID.STANDARD_PBS));
instance.m_BlitShader = Shader.Find(LightweightShaderUtils.GetShaderPath(ShaderPathID.HIDDEN_BLIT));
instance.m_CopyDepthShader = Shader.Find(LightweightShaderUtils.GetShaderPath(ShaderPathID.HIDDEN_DEPTH_COPY));

public override Material GetDefaultMaterial()
{
#if UNITY_EDITOR
return m_DefaultMaterial;
#else
if (m_ResourceAsset != null)
return m_ResourceAsset.DefaultMaterial;
#endif
#endif
return m_DefaultParticleMaterial;
#else
return null;
if (m_ResourceAsset != null)
return m_ResourceAsset.DefaultParticleMaterial;
return null;
}
public override Material GetDefaultLineMaterial()

public override Material GetDefaultTerrainMaterial()
{
#if UNITY_EDITOR
return m_DefaultTerrainMaterial;
#else
return null;
if (m_ResourceAsset != null)
return m_ResourceAsset.DefaultTerrainMaterial;
return null;
}
public override Material GetDefaultUIMaterial()

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


{
public static GUIContent renderingLabel = new GUIContent("Rendering");
public static GUIContent shadowLabel = new GUIContent("Shadows");
public static GUIContent defaults = new GUIContent("Default Materials");
public static GUIContent renderScaleLabel = new GUIContent("Render Scale", "Scales the camera render target allowing the game to render at a resolution different than native resolution. UI is always rendered at native resolution. When in VR mode, VR scaling configuration is used instead.");

public static GUIContent shadowCascadeSplit = new GUIContent("Cascades Split",
"Percentages to split shadow volume");
public static GUIContent defaultMaterial = new GUIContent("Mesh",
"Material to use when creating 3D objects");
public static GUIContent defaultParticleMaterial = new GUIContent("Particles",
"Material to use when creating Particle Systems");
public static GUIContent defaultTerrainMaterial = new GUIContent("Terrain",
"Material to use in Terrains");
public static GUIContent msaaContent = new GUIContent("Anti Aliasing (MSAA)", "Controls the global anti aliasing settings.");
public static string[] shadowTypeOptions = {"No Shadows", "Hard Shadows", "Hard and Soft Shadows"};

private SerializedProperty m_ShadowCascadesProp;
private SerializedProperty m_ShadowCascade2SplitProp;
private SerializedProperty m_ShadowCascade4SplitProp;
private SerializedProperty m_DefaultMaterial;
private SerializedProperty m_DefaultParticleMaterial;
private SerializedProperty m_DefaultTerrainMaterial;
private SerializedProperty m_MSAA;
void OnEnable()

m_ShadowCascadesProp = serializedObject.FindProperty("m_ShadowCascades");
m_ShadowCascade2SplitProp = serializedObject.FindProperty("m_Cascade2Split");
m_ShadowCascade4SplitProp = serializedObject.FindProperty("m_Cascade4Split");
m_DefaultMaterial = serializedObject.FindProperty("m_DefaultMaterial");
m_DefaultParticleMaterial = serializedObject.FindProperty("m_DefaultParticleMaterial");
m_DefaultTerrainMaterial = serializedObject.FindProperty("m_DefaultTerrainMaterial");
m_MSAA = serializedObject.FindProperty("m_MSAA");
}

EditorGUI.BeginChangeCheck();
if (mode >= options.Length)
Debug.LogError(string.Format("Invalid option while trying to set {0}", label.text));
mode = EditorGUILayout.Popup(label, mode, options);
if (EditorGUI.EndChangeCheck())
{

EditorGUILayout.PropertyField(m_ShadowCascade2SplitProp, Styles.shadowCascadeSplit);
}
EditorGUI.indentLevel--;
EditorGUILayout.Space();
EditorGUILayout.LabelField(Styles.defaults, EditorStyles.boldLabel);
EditorGUI.indentLevel++;
EditorGUILayout.PropertyField(m_DefaultMaterial, Styles.defaultMaterial);
EditorGUILayout.PropertyField(m_DefaultParticleMaterial, Styles.defaultParticleMaterial);
EditorGUILayout.PropertyField(m_DefaultTerrainMaterial, Styles.defaultTerrainMaterial);
EditorGUI.indentLevel--;
serializedObject.ApplyModifiedProperties();

33
ScriptableRenderPipeline/LightweightPipeline/LWRP/LightweightPipeline.cs


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

m_Asset = asset;
BuildShadowSettings();
SetRenderingFeatures();
PerFrameBuffer._GlossyEnvironmentColor = Shader.PropertyToID("_GlossyEnvironmentColor");
PerFrameBuffer._SubtractiveShadowColor = Shader.PropertyToID("_SubtractiveShadowColor");

CoreUtils.Destroy(m_BlitMaterial);
}
private void SetRenderingFeatures()
{
#if UNITY_EDITOR
SupportedRenderingFeatures.active = new SupportedRenderingFeatures()
{
reflectionProbeSupportFlags = SupportedRenderingFeatures.ReflectionProbeSupportFlags.None,
defaultMixedLightingMode = SupportedRenderingFeatures.LightmapMixedBakeMode.Subtractive,
supportedMixedLightingModes = SupportedRenderingFeatures.LightmapMixedBakeMode.Subtractive,
supportedLightmapBakeTypes = LightmapBakeType.Baked | LightmapBakeType.Mixed,
supportedLightmapsModes = LightmapsMode.CombinedDirectional | LightmapsMode.NonDirectional,
rendererSupportsLightProbeProxyVolumes = false,
rendererSupportsMotionVectors = false,
rendererSupportsReceiveShadows = true,
rendererSupportsReflectionProbes = true
};
#endif
}
// TODO: This is at the moment required for all pipes. We should not implicitly change user project settings
// instead this should be forced when using SRP, since all SRP use linear lighting.
SetupPerFrameShaderConstants();
// Sort cameras array by camera depth

// invAngleRange = 1.0 / (cosInnerAngle - cosOuterAngle)
// SdotL * invAngleRange + (-cosOuterAngle * invAngleRange)
// If we precompute the terms in a MAD instruction
float spotAngle = Mathf.Deg2Rad * lightData.spotAngle;
float cosOuterAngle = Mathf.Cos(spotAngle * 0.5f);
float cosInneAngle = Mathf.Cos(spotAngle * 0.25f);
float smoothAngleRange = cosInneAngle - cosOuterAngle;
if (Mathf.Approximately(smoothAngleRange, 0.0f))
smoothAngleRange = 1.0f;
float cosOuterAngle = Mathf.Cos(Mathf.Deg2Rad * lightData.spotAngle * 0.5f);
float cosInneAngle = Mathf.Cos(LightmapperUtils.ExtractInnerCone(lightData.light) * 0.5f);
float smoothAngleRange = Mathf.Max(0.001f, cosInneAngle - cosOuterAngle);
float invAngleRange = 1.0f / smoothAngleRange;
float add = -cosOuterAngle * invAngleRange;
lightSpotAttenuation = new Vector4(invAngleRange, add, 0.0f);

3
ScriptableRenderPipeline/LightweightPipeline/LWRP/Shaders/LightweightShaderLibrary/Lighting.hlsl


// If we precompute the terms in a MAD instruction
half SdotL = dot(spotDirection, lightDirection);
return saturate(SdotL * spotAttenuation.x + spotAttenuation.y);
half atten = saturate(SdotL * spotAttenuation.x + spotAttenuation.y);
return atten * atten;
}
inline half GetLightDirectionAndRealtimeAttenuation(LightInput lightInput, half3 normal, float3 worldPos, out half3 lightDirection)

7
Tests/GraphicsTests/RenderPipeline/LightweightPipeline/LightweightPipelineAsset.asset


m_ShadowAtlasResolution: 2048
m_ShadowNearPlaneOffset: 2
m_ShadowDistance: 50
m_ShadowCascades: 4
m_ShadowCascades: 0
m_DefaultMaterial: {fileID: 2100000, guid: 31321ba15b8f8eb4c954353edc038b1d, type: 2}
m_DefaultParticleMaterial: {fileID: 2100000, guid: e823cd5b5d27c0f4b8256e7c12ee3e6d,
type: 2}
m_DefaultTerrainMaterial: {fileID: 2100000, guid: 594ea882c5a793440b60ff72d896021e,
type: 2}
正在加载...
取消
保存