浏览代码

Merge pull request #707 from Unity-Technologies/LW_UI_Improvements

Lightweight UI improvements
/feature-ReflectionProbeFit
GitHub 7 年前
当前提交
71a0b586
共有 5 个文件被更改,包括 41 次插入60 次删除
  1. 30
      ScriptableRenderPipeline/LightweightPipeline/Data/LightweightPipelineAsset.cs
  2. 28
      ScriptableRenderPipeline/LightweightPipeline/Editor/LightweightAssetEditor.cs
  3. 33
      ScriptableRenderPipeline/LightweightPipeline/LightweightPipeline.cs
  4. 3
      ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightShaderLibrary/Lighting.hlsl
  5. 7
      Tests/GraphicsTests/RenderPipeline/LightweightPipeline/LightweightPipelineAsset.asset

30
ScriptableRenderPipeline/LightweightPipeline/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/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/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/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}
正在加载...
取消
保存