浏览代码

Added softparticles option to lightweight asset.

/LightweightPipelineExperimental
Felipe Lira 7 年前
当前提交
41d85d61
共有 3 个文件被更改,包括 60 次插入25 次删除
  1. 18
      ScriptableRenderPipeline/LightweightPipeline/LWRP/Data/LightweightPipelineAsset.cs
  2. 37
      ScriptableRenderPipeline/LightweightPipeline/LWRP/Editor/LightweightAssetEditor.cs
  3. 30
      ScriptableRenderPipeline/LightweightPipeline/LWRP/LightweightPipeline.cs

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


public static readonly string[] m_SearchPaths = {"Assets", "Packages/com.unity.render-pipelines.lightweight"};
// Default values set when a new LightweightPipeline asset is created
[SerializeField] private float kAssetVersion = 1.0f;
[SerializeField] private bool m_RequireCameraDepthTexture = false;
[SerializeField] private bool m_RequireDepthTexture = false;
[SerializeField] private bool m_RequireSoftParticles = false;
[SerializeField] private bool m_SupportsHDR = false;
[SerializeField] private MSAAQuality m_MSAA = MSAAQuality._4x;
[SerializeField] private float m_RenderScale = 1.0f;

return ShadowSetting != ShadowType.NO_SHADOW;
}
public float GetAssetVersion()
{
return kAssetVersion;
}
public int MaxPixelLights
{
get { return m_MaxPixelLights; }

get { return m_SupportsVertexLight; }
}
public bool RequireCameraDepthTexture
public bool RequireDepthTexture
get { return m_RequireCameraDepthTexture; }
get { return m_RequireDepthTexture; }
}
public bool RequireSoftParticles
{
get { return m_RequireSoftParticles; }
}
public bool SupportsHDR

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


using UnityEditor;
using UnityEditor.AnimatedValues;
namespace UnityEngine.Experimental.Rendering.LightweightPipeline
{

public static GUIContent enableVertexLightLabel = new GUIContent("Vertex Lighting",
"If enabled shades additional lights exceeding the maximum number of pixel lights per-vertex up to the maximum of 8 lights.");
public static GUIContent requireCameraDepthTexture = new GUIContent("Camera Depth Texture", "If enabled the pipeline will generate camera's depth that can be bound in shaders as _CameraDepthTexture. This is necessary for some effect like Soft Particles.");
public static GUIContent requireDepthTexture = new GUIContent("Depth Texture", "If enabled the pipeline will generate camera's depth that can be bound in shaders as _CameraDepthTexture.");
public static GUIContent requireSoftParticles = new GUIContent("Soft Particles", "If enabled the pipeline will enable SOFT_PARTICLES keyword.");
public static GUIContent shadowType = new GUIContent("Type",
"Global shadow settings. Options are NO_SHADOW, HARD_SHADOWS and SOFT_SHADOWS.");

public static string[] shadowCascadeOptions = {"No Cascades", "Two Cascades", "Four Cascades"};
}
AnimBool m_ShowSoftParticles = new AnimBool();
private int kMaxSupportedPixelLights = 8;
private float kMinRenderScale = 0.1f;
private float kMaxRenderScale = 4.0f;

private SerializedProperty m_RequireCameraDepthTextureProp;
private SerializedProperty m_RequireDepthTextureProp;
private SerializedProperty m_RequireSoftParticlesProp;
private SerializedProperty m_ShadowTypeProp;
private SerializedProperty m_ShadowNearPlaneOffsetProp;
private SerializedProperty m_ShadowDistanceProp;

m_RenderScale = serializedObject.FindProperty("m_RenderScale");
m_MaxPixelLights = serializedObject.FindProperty("m_MaxPixelLights");
m_SupportsVertexLightProp = serializedObject.FindProperty("m_SupportsVertexLight");
m_RequireCameraDepthTextureProp = serializedObject.FindProperty("m_RequireCameraDepthTexture");
m_RequireDepthTextureProp = serializedObject.FindProperty("m_RequireDepthTexture");
m_RequireSoftParticlesProp = serializedObject.FindProperty("m_RequireSoftParticles");
m_ShadowTypeProp = serializedObject.FindProperty("m_ShadowType");
m_ShadowNearPlaneOffsetProp = serializedObject.FindProperty("m_ShadowNearPlaneOffset");
m_ShadowDistanceProp = serializedObject.FindProperty("m_ShadowDistance");

m_ShadowCascade4SplitProp = serializedObject.FindProperty("m_Cascade4Split");
m_HDR = serializedObject.FindProperty("m_SupportsHDR");
m_MSAA = serializedObject.FindProperty("m_MSAA");
m_ShowSoftParticles.valueChanged.AddListener(Repaint);
m_ShowSoftParticles.value = m_RequireSoftParticlesProp.boolValue;
}
void OnDisable()
{
m_ShowSoftParticles.valueChanged.RemoveListener(Repaint);
}
void UpdateAnimationValues()
{
m_ShowSoftParticles.target = m_RequireDepthTextureProp.boolValue;
}
void DrawAnimatedProperty(SerializedProperty prop, GUIContent content, AnimBool animation)
{
using (var group = new EditorGUILayout.FadeGroupScope(animation.faded))
if (group.visible)
EditorGUILayout.PropertyField(prop, content);
}
protected void DoPopup(GUIContent label, SerializedProperty property, string[] options)

{
serializedObject.Update();
UpdateAnimationValues();
EditorGUILayout.Space();
EditorGUILayout.LabelField(Styles.renderingLabel, EditorStyles.boldLabel);
EditorGUI.indentLevel++;

m_MaxPixelLights.intValue = EditorGUILayout.IntSlider(m_MaxPixelLights.intValue, 0, kMaxSupportedPixelLights);
EditorGUILayout.EndHorizontal();
EditorGUILayout.PropertyField(m_SupportsVertexLightProp, Styles.enableVertexLightLabel);
EditorGUILayout.PropertyField(m_RequireCameraDepthTextureProp, Styles.requireCameraDepthTexture);
EditorGUILayout.PropertyField(m_RequireDepthTextureProp, Styles.requireDepthTexture);
DrawAnimatedProperty(m_RequireSoftParticlesProp, Styles.requireSoftParticles, m_ShowSoftParticles);
EditorGUILayout.PropertyField(m_HDR, Styles.hdrContent);
EditorGUILayout.PropertyField(m_MSAA, Styles.msaaContent);

30
ScriptableRenderPipeline/LightweightPipeline/LWRP/LightweightPipeline.cs


private RenderTargetIdentifier m_Color;
private bool m_IntermediateTextureArray;
private bool m_RequireDepth;
private bool m_RequireDepthTexture;
private bool m_RequireCopyColor;
private bool m_DepthRenderBuffer;
private MixedLightingSetup m_MixedLightingSetup;

private void AfterOpaque(ref ScriptableRenderContext context, FrameRenderingConfiguration config)
{
if (!m_RequireDepth)
if (!m_RequireDepthTexture)
return;
CommandBuffer cmd = CommandBufferPool.Get("After Opaque");

m_Asset.RenderScale < 1.0f || hdrEnabled;
m_ColorFormat = hdrEnabled ? RenderTextureFormat.DefaultHDR : RenderTextureFormat.Default;
m_RequireDepth = false;
m_RequireCopyColor = false;
m_DepthRenderBuffer = false;
m_CameraPostProcessLayer = m_CurrCamera.GetComponent<PostProcessLayer>();

// TODO: PostProcessing and SoftParticles are currently not support for VR
bool postProcessEnabled = m_CameraPostProcessLayer != null && m_CameraPostProcessLayer.enabled && !stereoEnabled;
bool softParticlesEnabled = m_Asset.RequireCameraDepthTexture && !stereoEnabled;
m_RequireDepthTexture = m_Asset.RequireDepthTexture && !stereoEnabled;
m_RequireDepth = true;
m_RequireDepthTexture = true;
intermediateTexture = true;
configuration |= FrameRenderingConfiguration.PostProcess;

}
}
// In case of soft particles we need depth copy. If depth copy not supported fallback to depth prepass
if (softParticlesEnabled)
{
m_RequireDepth = true;
intermediateTexture = true;
}
if (msaaEnabled)
{
configuration |= FrameRenderingConfiguration.Msaa;

if (m_RequireDepth)
if (m_RequireDepthTexture)
{
// If msaa is enabled we don't use a depth renderbuffer as we might not have support to Texture2DMS to resolve depth.
// Instead we use a depth prepass and whenever depth is needed we use the 1 sample depth from prepass.

m_DepthRenderBuffer = true;
intermediateTexture = true;
// Soft particles need separate depth as it reads/write to depth at same time
if (softParticlesEnabled)
// If requiring a camera depth texture we need separate depth as it reads/write to depth at same time
// Post process doesn't need the copy
if (!m_Asset.RequireDepthTexture && postProcessEnabled)
configuration |= (supportsDepthCopy) ? FrameRenderingConfiguration.DepthCopy : FrameRenderingConfiguration.DepthPrePass;
}
else

int rtWidth = (int)((float)m_CurrCamera.pixelWidth * renderScale);
int rtHeight = (int)((float)m_CurrCamera.pixelHeight * renderScale);
if (m_RequireDepth)
if (m_RequireDepthTexture)
{
RenderTextureDescriptor depthRTDesc = new RenderTextureDescriptor(rtWidth, rtHeight, RenderTextureFormat.Depth, kDepthStencilBufferBits);
cmd.GetTemporaryRT(CameraRenderTargetID.depth, depthRTDesc, FilterMode.Bilinear);

CoreUtils.SetKeyword(cmd, "_ADDITIONAL_LIGHTS", lightData.totalAdditionalLightsCount > 0);
CoreUtils.SetKeyword(cmd, "_MIXED_LIGHTING_SUBTRACTIVE", m_MixedLightingSetup == MixedLightingSetup.Subtractive);
CoreUtils.SetKeyword(cmd, "_VERTEX_LIGHTS", vertexLightsCount > 0);
CoreUtils.SetKeyword(cmd, "SOFTPARTICLES_ON", m_Asset.RequireCameraDepthTexture);
CoreUtils.SetKeyword(cmd, "SOFTPARTICLES_ON", m_RequireDepthTexture && m_Asset.RequireSoftParticles);
bool linearFogModeEnabled = false;
bool exponentialFogModeEnabled = false;

if (!m_IsOffscreenCamera)
colorRT = m_CurrCameraColorRT;
if (m_RequireDepth)
if (m_RequireDepthTexture)
depthRT = m_DepthRT;
}

正在加载...
取消
保存