浏览代码

Initial prototype.

/lw-bias_per_cascade
Felipe Lira 7 年前
当前提交
9d9d5435
共有 5 个文件被更改,包括 38 次插入3 次删除
  1. 8
      ScriptableRenderPipeline/LightweightPipeline/LWRP/Data/LightweightPipelineAsset.cs
  2. 13
      ScriptableRenderPipeline/LightweightPipeline/LWRP/Editor/LightweightAssetEditor.cs
  3. 3
      ScriptableRenderPipeline/LightweightPipeline/LWRP/LightweightPipeline.cs
  4. 14
      ScriptableRenderPipeline/LightweightPipeline/LWRP/ShaderLibrary/Shadows.hlsl
  5. 3
      Tests/GraphicsTests/RenderPipeline/LightweightPipeline/LightweightPipelineAsset.asset

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


public class LightweightPipelineAsset : RenderPipelineAsset
{
private const int PACKAGE_MANAGER_PATH_INDEX = 1;
private const float kDefaultBias = 0.05f;
private Shader m_DefaultShader;
public static readonly string m_SearchPathProject = "Assets";
public static readonly string m_SearchPathPackage = "Packages/com.unity.render-pipelines.lightweight";

[SerializeField] private ShadowCascades m_ShadowCascades = ShadowCascades.FOUR_CASCADES;
[SerializeField] private float m_Cascade2Split = 0.25f;
[SerializeField] private Vector3 m_Cascade4Split = new Vector3(0.067f, 0.2f, 0.467f);
[SerializeField] private Vector3 m_CascadeBiasOffset = new Vector3(kDefaultBias, kDefaultBias, kDefaultBias);
[SerializeField]
private LightweightPipelineResources m_ResourcesAsset;

{
get { return m_Cascade4Split; }
private set { m_Cascade4Split = value; }
}
public Vector3 CascadeBiasOffset
{
get { return m_CascadeBiasOffset; }
}
public override Material GetDefaultMaterial()

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


public static GUIContent shadowCascadeSplit = new GUIContent("Cascades Split",
"Percentages to split shadow volume");
public static GUIContent shadowCascadeBias = new GUIContent("Shadow Cascade Bias Offset", "Applies a global bias to shadow cascade");
public static GUIContent hdrContent = new GUIContent("HDR", "Controls the global HDR settings.");
public static GUIContent msaaContent = new GUIContent("Anti Aliasing (MSAA)", "Controls the global anti aliasing settings.");

private SerializedProperty m_ShadowCascade4SplitProp;
private SerializedProperty m_HDR;
private SerializedProperty m_MSAA;
private SerializedProperty m_ShadowCascadeBias;
void OnEnable()
{

m_ShadowCascade4SplitProp = serializedObject.FindProperty("m_Cascade4Split");
m_HDR = serializedObject.FindProperty("m_SupportsHDR");
m_MSAA = serializedObject.FindProperty("m_MSAA");
m_ShadowCascadeBias = serializedObject.FindProperty("m_CascadeBiasOffset");
m_ShowSoftParticles.valueChanged.AddListener(Repaint);
m_ShowSoftParticles.value = m_RequireSoftParticlesProp.boolValue;

EditorGUILayout.PropertyField(prop, content);
}
void DrawShadowCascadeBias(int cascadeCount)
{
if (cascadeCount > 0)
{
EditorGUILayout.PropertyField(m_ShadowCascadeBias, Styles.shadowCascadeBias);
}
}
public override void OnInspectorGUI()
{
serializedObject.Update();

CoreEditorUtils.DrawPopup(Styles.shadowCascades, m_ShadowCascadesProp, Styles.shadowCascadeOptions);
ShadowCascades cascades = (ShadowCascades)m_ShadowCascadesProp.intValue;
DrawShadowCascadeBias(m_ShadowCascadesProp.intValue);
if (cascades == ShadowCascades.FOUR_CASCADES)
CoreEditorUtils.DrawCascadeSplitGUI<Vector3>(ref m_ShadowCascade4SplitProp);
else if (cascades == ShadowCascades.TWO_CASCADES)

3
ScriptableRenderPipeline/LightweightPipeline/LWRP/LightweightPipeline.cs


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));
Vector3 cascadeBias = m_Asset.CascadeBiasOffset;
cmd.SetGlobalVector("_ShadowCascadeBiasOffset", new Vector4(cascadeBias.x, cascadeBias.y, cascadeBias.z, 0.05f));
}
private void SetShaderKeywords(CommandBuffer cmd, ref LightData lightData, List<VisibleLight> visibleLights)

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


float4 _ShadowmapSize; // (xy: 1/width and 1/height, zw: width and height)
CBUFFER_END
float4 _ShadowCascadeBiasOffset;
#if UNITY_REVERSED_Z
#define BEYOND_SHADOW_FAR(shadowCoord) shadowCoord.z <= UNITY_RAW_FAR_CLIP_VALUE
#else

float4 ComputeScreenSpaceShadowCoords(float3 positionWS)
{
#ifdef _SHADOWS_CASCADE
#ifdef _SHADOWS_CASCADE
return mul(_WorldToShadow[cascadeIndex], float4(positionWS, 1.0));
float4 coord = mul(_WorldToShadow[cascadeIndex], float4(positionWS, 1.0));
#if UNITY_REVERSED_Z
coord.z += _ShadowCascadeBiasOffset[cascadeIndex];
#else
coord.z -= _ShadowCascadeBiasOffset[cascadeIndex];
#endif
return coord;
#else
return mul(_WorldToShadow[0], float4(positionWS, 1.0));
#endif

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


m_ShadowType: 1
m_ShadowAtlasResolution: 2048
m_ShadowNearPlaneOffset: 2
m_ShadowDistance: 50
m_ShadowDistance: 200
m_CascadeBiasOffset: {x: 0, y: 0, z: 0}
m_ResourcesAsset: {fileID: 11400000, guid: aac5a08c32552a14c89394b703f1978a, type: 2}
正在加载...
取消
保存