浏览代码

Added CameraComparer to sort camera array by depth. Moved some functions to LightweightUtils.

/RenderPassXR_Sandbox
Felipe Lira 7 年前
当前提交
d9c64960
共有 3 个文件被更改,包括 70 次插入35 次删除
  1. 58
      ScriptableRenderPipeline/LightweightPipeline/LightweightPipeline.cs
  2. 34
      ScriptableRenderPipeline/LightweightPipeline/LightweightPipelineUtils.cs
  3. 13
      ScriptableRenderPipeline/LightweightPipeline/LightweightPipelineUtils.cs.meta

58
ScriptableRenderPipeline/LightweightPipeline/LightweightPipeline.cs


private RenderTextureFormat m_ColorFormat = RenderTextureFormat.ARGB32;
private PostProcessRenderContext m_PostProcessRenderContext;
private CameraComparer m_CameraComparer = new CameraComparer();
public LightweightPipeline(LightweightPipelineAsset asset)
{
m_Asset = asset;

// instead this should be forced when using SRP, since all SRP use linear lighting.
GraphicsSettings.lightsUseLinearIntensity = true;
Array.Sort(cameras, m_CameraComparer);
foreach (Camera camera in cameras)
{
m_CurrCamera = camera;

CommandBufferPool.Release(setupShadow);
}
private void SetKeyword(CommandBuffer cmd, string keyword, bool enable)
{
if (enable)
cmd.EnableShaderKeyword(keyword);
else
cmd.DisableShaderKeyword(keyword);
}
SetKeyword(cmd, "LIGHTWEIGHT_LINEAR", m_Asset.ForceLinearRendering);
SetKeyword(cmd, "_VERTEX_LIGHTS", vertexLightSupport);
SetKeyword(cmd, "_ATTENUATION_TEXTURE", m_Asset.AttenuationTexture != null);
SetKeyword(cmd, "_LIGHT_PROBES_ON", m_Asset.EnableAmbientProbe);
SetKeyword(cmd, "LIGHTWEIGHT_LINEAR", m_Asset.ForceLinearRendering);
LightweightUtils.SetKeyword(cmd, "LIGHTWEIGHT_LINEAR", m_Asset.ForceLinearRendering);
LightweightUtils.SetKeyword(cmd, "_VERTEX_LIGHTS", vertexLightSupport);
LightweightUtils.SetKeyword(cmd, "_ATTENUATION_TEXTURE", m_Asset.AttenuationTexture != null);
LightweightUtils.SetKeyword(cmd, "_LIGHT_PROBES_ON", m_Asset.EnableAmbientProbe);
LightweightUtils.SetKeyword(cmd, "LIGHTWEIGHT_LINEAR", m_Asset.ForceLinearRendering);
SetKeyword(cmd, "_SINGLE_DIRECTIONAL_LIGHT", false);
SetKeyword(cmd, "_SINGLE_SPOT_LIGHT", false);
SetKeyword(cmd, "_SINGLE_POINT_LIGHT", false);
LightweightUtils.SetKeyword(cmd, "_SINGLE_DIRECTIONAL_LIGHT", false);
LightweightUtils.SetKeyword(cmd, "_SINGLE_SPOT_LIGHT", false);
LightweightUtils.SetKeyword(cmd, "_SINGLE_POINT_LIGHT", false);
}
else
{

SetKeyword(cmd, "_SINGLE_DIRECTIONAL_LIGHT", true);
SetKeyword(cmd, "_SINGLE_SPOT_LIGHT", false);
SetKeyword(cmd, "_SINGLE_POINT_LIGHT", false);
LightweightUtils.SetKeyword(cmd, "_SINGLE_DIRECTIONAL_LIGHT", true);
LightweightUtils.SetKeyword(cmd, "_SINGLE_SPOT_LIGHT", false);
LightweightUtils.SetKeyword(cmd, "_SINGLE_POINT_LIGHT", false);
SetKeyword(cmd, "_SINGLE_DIRECTIONAL_LIGHT", false);
SetKeyword(cmd, "_SINGLE_SPOT_LIGHT", true);
SetKeyword(cmd, "_SINGLE_POINT_LIGHT", false);
LightweightUtils.SetKeyword(cmd, "_SINGLE_DIRECTIONAL_LIGHT", false);
LightweightUtils.SetKeyword(cmd, "_SINGLE_SPOT_LIGHT", true);
LightweightUtils.SetKeyword(cmd, "_SINGLE_POINT_LIGHT", false);
SetKeyword(cmd, "_SINGLE_DIRECTIONAL_LIGHT", false);
SetKeyword(cmd, "_SINGLE_SPOT_LIGHT", false);
SetKeyword(cmd, "_SINGLE_POINT_LIGHT", true);
LightweightUtils.SetKeyword(cmd, "_SINGLE_DIRECTIONAL_LIGHT", false);
LightweightUtils.SetKeyword(cmd, "_SINGLE_SPOT_LIGHT", false);
LightweightUtils.SetKeyword(cmd, "_SINGLE_POINT_LIGHT", true);
break;
}
}

private bool GetRenderToIntermediateTarget()
{
bool allowMSAA = m_CurrCamera.allowMSAA && m_Asset.MSAASampleCount > 1 && !PlatformSupportsMSAABackBuffer();
bool allowMSAA = m_CurrCamera.allowMSAA &&
m_Asset.MSAASampleCount > 1 &&
!LightweightUtils.PlatformSupportsMSAABackBuffer();
if (m_CurrCamera.cameraType == CameraType.SceneView || allowMSAA || m_CurrCamera.targetTexture != null)
return true;

private PostProcessLayer GetCurrCameraPostProcessLayer()
{
return m_CurrCamera.GetComponent<PostProcessLayer>();
}
private bool PlatformSupportsMSAABackBuffer()
{
#if UNITY_ANDROID || UNITY_IPHONE || UNITY_TVOS || UNITY_SAMSUNGTV
return true;
#else
return false;
#endif
}
}
}

34
ScriptableRenderPipeline/LightweightPipeline/LightweightPipelineUtils.cs


using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Rendering;
namespace UnityEngine.Experimental.Rendering.LightweightPipeline
{
public class CameraComparer : IComparer<Camera>
{
public int Compare(Camera lhs, Camera rhs)
{
return (int)(lhs.depth - rhs.depth);
}
}
public static class LightweightUtils
{
public static void SetKeyword(CommandBuffer cmd, string keyword, bool enable)
{
if (enable)
cmd.EnableShaderKeyword(keyword);
else
cmd.DisableShaderKeyword(keyword);
}
public static bool PlatformSupportsMSAABackBuffer()
{
#if UNITY_ANDROID || UNITY_IPHONE || UNITY_TVOS || UNITY_SAMSUNGTV
return true;
#else
return false;
#endif
}
}
}

13
ScriptableRenderPipeline/LightweightPipeline/LightweightPipelineUtils.cs.meta


fileFormatVersion: 2
guid: 1556a6d19597541c8bed4b90c704fb06
timeCreated: 1505115136
licenseType: Free
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存