浏览代码

[hdloop]Add sky asset + common settings asset.

/main
Tim Cooper 8 年前
当前提交
32acc565
共有 17 个文件被更改,包括 221 次插入339 次删除
  1. 2
      Assets/ScriptableRenderLoop/HDRenderPipeline/Editor/HDRenderPipelineInspector.cs
  2. 1
      Assets/ScriptableRenderLoop/HDRenderPipeline/Editor/HDRenderPipelineMenuItems.cs
  3. 150
      Assets/ScriptableRenderLoop/HDRenderPipeline/HDRenderPipeline.cs
  4. 2
      Assets/ScriptableRenderLoop/HDRenderPipeline/Lighting/TilePass/TilePass.cs
  5. 104
      Assets/ScriptableRenderLoop/HDRenderPipeline/SceneSettings/CommonSettings.cs
  6. 34
      Assets/ScriptableRenderLoop/HDRenderPipeline/SceneSettings/CommonSettingsSingleton.cs
  7. 10
      Assets/ScriptableRenderLoop/HDRenderPipeline/Sky/HDRISky/HDRISkyParameters.cs
  8. 37
      Assets/ScriptableRenderLoop/HDRenderPipeline/Sky/HDRISky/HDRISkyRenderer.cs
  9. 5
      Assets/ScriptableRenderLoop/HDRenderPipeline/Sky/ProceduralSky/ProceduralSkyParameters.cs
  10. 35
      Assets/ScriptableRenderLoop/HDRenderPipeline/Sky/ProceduralSky/ProceduralSkyRenderer.cs
  11. 52
      Assets/ScriptableRenderLoop/HDRenderPipeline/Sky/SkyManager.cs
  12. 12
      Assets/ScriptableRenderLoop/HDRenderPipeline/Sky/SkyParameters.cs
  13. 21
      Assets/ScriptableRenderLoop/HDRenderPipeline/Sky/SkyParametersSingleton.cs
  14. 32
      Assets/ScriptableRenderLoop/HDRenderPipeline/Sky/SkyRenderer.cs
  15. 12
      Assets/ScriptableRenderLoop/core/Singleton.cs
  16. 39
      Assets/ScriptableRenderLoop/HDRenderPipeline/Editor/HDRenderPipeWindow.cs
  17. 12
      Assets/ScriptableRenderLoop/HDRenderPipeline/Editor/HDRenderPipeWindow.cs.meta

2
Assets/ScriptableRenderLoop/HDRenderPipeline/Editor/HDRenderPipelineInspector.cs


namespace UnityEngine.Experimental.Rendering.HDPipeline
{
[CustomEditor(typeof(HDRenderPipeline))]
//[CustomEditor(typeof(HDRenderPipeline))]
public class HDRenderPipelineInspector : Editor
{
private class Styles

1
Assets/ScriptableRenderLoop/HDRenderPipeline/Editor/HDRenderPipelineMenuItems.cs


using UnityEngine;
using UnityEngine.Experimental.Rendering.HDPipeline;
namespace UnityEditor.Experimental.Rendering.HDPipeline
{

150
Assets/ScriptableRenderLoop/HDRenderPipeline/HDRenderPipeline.cs


public class HDRenderPipeline : RenderPipelineAsset
{
const string k_HDRenderPipelinePath = "Assets/ScriptableRenderLoop/HDRenderPipeline/HDRenderPipeline.asset";
[UnityEditor.MenuItem("RenderPipeline/CreateHDRenderPipeline")]
[MenuItem("RenderPipeline/CreateHDRenderPipeline")]
instance.m_setup = UnityEditor.AssetDatabase.LoadAssetAtPath<HDRenderPipelineSetup>("Assets/HDRenderPipelineSetup.asset");
instance.m_Setup = AssetDatabase.LoadAssetAtPath<HDRenderPipelineSetup>("Assets/HDRenderPipelineSetup.asset");
[UnityEditor.MenuItem("RenderPipeline/UpdateHDLoop")]
static void UpdateHDLoop()
{

string path = AssetDatabase.GUIDToAssetPath(guid);
var loop = AssetDatabase.LoadAssetAtPath<HDRenderPipeline>(path);
loop.m_setup = AssetDatabase.LoadAssetAtPath<HDRenderPipelineSetup>("Assets/HDRenderPipelineSetup.asset");
loop.m_Setup = AssetDatabase.LoadAssetAtPath<HDRenderPipelineSetup>("Assets/HDRenderPipelineSetup.asset");
EditorUtility.SetDirty(loop);
}
}

{ }
[SerializeField]
private HDRenderPipelineSetup m_setup;
private HDRenderPipelineSetup m_Setup;
get { return m_setup; }
get { return m_Setup; }
}
[SerializeField]
private CommonSettings.Settings m_CommonSettings = CommonSettings.Settings.s_Defaultsettings;
public CommonSettings.Settings commonSettingsToUse
{
get
{
if (CommonSettingsSingleton.overrideSettings)
return CommonSettingsSingleton.overrideSettings.settings;
return m_CommonSettings;
}
}
[SerializeField]
private SkyParameters m_SkyParameters;
public SkyParameters skyParametersToUse
{
get
{
if (SkyParametersSingleton.overrideSettings)
return SkyParametersSingleton.overrideSettings;
return m_SkyParameters;
}
}
protected override IRenderPipeline InternalCreatePipeline()

public void UpdateCommonSettings()
{
var commonSettings = CommonSettingsSingleton.overrideSettings;
if (commonSettings == null)
{
m_ShadowSettings.maxShadowDistance = ShadowSettings.Default.maxShadowDistance;
m_ShadowSettings.directionalLightCascadeCount = ShadowSettings.Default.directionalLightCascadeCount;
m_ShadowSettings.directionalLightCascades = ShadowSettings.Default.directionalLightCascades;
}
else
{
m_ShadowSettings.directionalLightCascadeCount = commonSettings.shadowCascadeCount;
m_ShadowSettings.directionalLightCascades = new Vector3(commonSettings.shadowCascadeSplit0, commonSettings.shadowCascadeSplit1, commonSettings.shadowCascadeSplit2);
m_ShadowSettings.maxShadowDistance = commonSettings.shadowMaxDistance;
}
}
public void InstantiateSkyRenderer(Type skyRendererType)
{
var instances = CreatedInstances().OfType<HDRenderPipeline>();
foreach (var instance in instances)
instance.InstantiateSkyRenderer(skyRendererType);
}
public Type GetSkyParameterType()
{
var instance = CreatedInstances().OfType<HDRenderPipeline>().FirstOrDefault();
if (instance == null)
return null;
return instance.GetType();
var commonSettings = commonSettingsToUse;
m_ShadowSettings.directionalLightCascadeCount = commonSettings.shadowCascadeCount;
m_ShadowSettings.directionalLightCascades = new Vector3(commonSettings.shadowCascadeSplit0, commonSettings.shadowCascadeSplit1, commonSettings.shadowCascadeSplit2);
m_ShadowSettings.maxShadowDistance = commonSettings.shadowMaxDistance;
}
}

ShadowRenderPass m_ShadowPass;
// This must be allocate outside of Build() else the option in the class can't be set in the inspector (as it will in this case recreate the class with default value)
//readonly BaseLightLoop m_lightLoop;
SkyManager m_SkyManager;
public SkyManager skyManager
{
get
{
if (m_SkyManager == null)
{
m_SkyManager = new SkyManager();
m_SkyManager.skyParameters = SkyParametersSingleton.overrideSettings;
}
return m_SkyManager;
}
}
readonly SkyManager m_SkyManager = new SkyManager();
public void InstantiateSkyRenderer(Type skyRendererType)
{
skyManager.InstantiateSkyRenderer(skyRendererType);
}
public HDRenderPipelineInstance(HDRenderPipeline owner)
{
m_Owner = owner;

m_lightLoop = new LightLoop(owner);
m_lightLoop.Build(owner.textureSettings);
m_SkyManager.skyParameters = owner.skyParametersToUse;
}
public override void Dispose()

m_LitRenderLoop.Cleanup();
Utilities.Destroy(m_DebugViewMaterialGBuffer);
skyManager.Cleanup();
m_SkyManager.Cleanup();
#if UNITY_EDITOR
SupportedRenderingFeatures.active = SupportedRenderingFeatures.Default;

// TODO: This is the wrong way to handle resize/allocation. We can have several different camera here, mean that the loop on camera will allocate and deallocate
// the below buffer which is bad. Best is to have a set of buffer for each camera that is persistent and reallocate resource if need
// For now consider we have only one camera that go to this code, the main one.
skyManager.Resize(); // TODO: Also a bad naming, here we just want to realloc texture if skyparameters change (usefull for lookdev)
m_SkyManager.skyParameters = m_Owner.skyParametersToUse;
m_SkyManager.Resize(camera.nearClipPlane, camera.farClipPlane); // TODO: Also a bad naming, here we just want to realloc texture if skyparameters change (usefull for lookdev)
if (camera.pixelWidth != m_CurrentWidth || camera.pixelHeight != m_CurrentHeight || m_lightLoop.NeedResize())
{

public void PushGlobalParams(HDCamera hdCamera, ScriptableRenderContext renderContext)
{
if (skyManager.IsSkyValid())
if (m_SkyManager.IsSkyValid())
skyManager.SetGlobalSkyTexture();
m_SkyManager.SetGlobalSkyTexture();
Shader.SetGlobalInt("_EnvLightSkyEnabled", 1);
}
else

GraphicsSettings.lightsUseLinearIntensity = true;
GraphicsSettings.lightsUseCCT = true;
skyManager.Build();
m_SkyManager.Build();
if (!m_LitRenderLoop.isInit)
m_LitRenderLoop.RenderInit(renderContext);

renderContext.SetupCameraProperties(camera);
HDCamera hdCamera = Utilities.GetHDCamera(camera);
// TODO: Find a correct place to bind these material textures
// We have to bind the material specific global parameters in this mode
m_LitRenderLoop.Bind();
InitAndClearBuffer(camera, renderContext);

{
m_lightLoop.PrepareLightsForGPU(m_Owner.shadowSettings, cullResults, camera, ref shadows);
m_lightLoop.BuildGPULightLists(camera, renderContext, m_CameraDepthBufferRT); // TODO: Use async compute here to run light culling during shadow
PushGlobalParams(hdCamera, renderContext);
PushGlobalParams(hdCamera, renderContext);
// Caution: We require sun light here as some sky use the sun light to render, mean UpdateSkyEnvironment
// must be call after BuildGPULightLists.

Shader.SetGlobalInt("_DebugViewMaterial", (int)debugParameters.debugViewMaterial);
RenderOpaqueRenderList(cull, hdCamera.camera, renderContext, "DebugViewMaterial");
RenderOpaqueRenderList(cull, hdCamera.camera, renderContext, "DebugViewMaterial", Utilities.kRendererConfigurationBakedLighting);
}
// Render GBuffer opaque

// Render forward transparent
{
RenderTransparentRenderList(cull, hdCamera.camera, renderContext, "DebugViewMaterial");
RenderTransparentRenderList(cull, hdCamera.camera, renderContext, "DebugViewMaterial", Utilities.kRendererConfigurationBakedLighting);
}
// Last blit

{
return;
}
// Bind material data
m_LitRenderLoop.Bind();
skyManager.UpdateEnvironment(hdCamera, m_lightLoop.GetCurrentSunLight(), renderContext);
m_SkyManager.UpdateEnvironment(hdCamera, m_lightLoop.GetCurrentSunLight(), renderContext);
skyManager.RenderSky(hdCamera, m_lightLoop.GetCurrentSunLight(), m_CameraColorBufferRT, m_CameraDepthBufferRT, renderContext);
m_SkyManager.RenderSky(hdCamera, m_lightLoop.GetCurrentSunLight(), m_CameraColorBufferRT, m_CameraDepthBufferRT, renderContext);
}
void RenderForward(CullResults cullResults, Camera camera, ScriptableRenderContext renderContext, bool renderOpaque)

using (new Utilities.ProfilingSample("Forward Pass", renderContext))
{
// Bind material data
m_LitRenderLoop.Bind();
Utilities.SetRenderTarget(renderContext, m_CameraColorBufferRT, m_CameraDepthBufferRT);
m_lightLoop.RenderForward(camera, renderContext, renderOpaque);

RenderOpaqueRenderList(cullResults, camera, renderContext, "Forward");
RenderOpaqueRenderList(cullResults, camera, renderContext, "Forward", Utilities.kRendererConfigurationBakedLighting);
}
else
{

{
using (new Utilities.ProfilingSample("Forward Only Pass", renderContext))
{
// Bind material data
m_LitRenderLoop.Bind();
RenderOpaqueRenderList(cullResults, camera, renderContext, "ForwardOnlyOpaque");
RenderOpaqueRenderList(cullResults, camera, renderContext, "ForwardOnlyOpaque", Utilities.kRendererConfigurationBakedLighting);
}
}

}
// Clear GBuffers
using (new Utilities.ProfilingSample("Clear GBuffer", renderContext))
if (!debugParameters.ShouldUseForwardRenderingOnly())
Utilities.SetRenderTarget(renderContext, m_gbufferManager.GetGBuffers(), m_CameraDepthBufferRT, ClearFlag.ClearColor, Color.black);
using (new Utilities.ProfilingSample("Clear GBuffer", renderContext))
{
Utilities.SetRenderTarget(renderContext, m_gbufferManager.GetGBuffers(), m_CameraDepthBufferRT, ClearFlag.ClearColor, Color.black);
}
// END TEMP
}
}

2
Assets/ScriptableRenderLoop/HDRenderPipeline/Lighting/TilePass/TilePass.cs


Utilities.Destroy(m_SingleDeferredMaterial);
GameObject.DestroyImmediate(s_DefaultAdditionalLightDataGameObject);
GameObject.Destroy(s_DefaultAdditionalLightDataGameObject);
s_DefaultAdditionalLightDataGameObject = null;
s_DefaultAdditionalLightData = null;
}

104
Assets/ScriptableRenderLoop/HDRenderPipeline/SceneSettings/CommonSettings.cs


namespace UnityEngine.Experimental.Rendering.HDPipeline
{
[ExecuteInEditMode]
[DisallowMultipleComponent]
public class CommonSettings : MonoBehaviour
public class CommonSettings : ScriptableObject
public class Settings
{
public struct Settings
{
string m_SkyRendererTypeName = ""; // Serialize a string because serialize a Type.
float m_ShadowMaxDistance;
float m_ShadowMaxDistance = ShadowSettings.Default.maxShadowDistance;
int m_ShadowCascadeCount;
int m_ShadowCascadeCount = ShadowSettings.Default.directionalLightCascadeCount;
float m_ShadowCascadeSplit0;
float m_ShadowCascadeSplit0 = ShadowSettings.Default.directionalLightCascades.x;
float m_ShadowCascadeSplit1;
float m_ShadowCascadeSplit1 = ShadowSettings.Default.directionalLightCascades.y;
float m_ShadowCascadeSplit2;
[SerializeField]
float m_ShadowCascadeSplit2 = ShadowSettings.Default.directionalLightCascades.z;
public float shadowMaxDistance { set { m_ShadowMaxDistance = value; OnValidate(); } get { return m_ShadowMaxDistance; } }
public int shadowCascadeCount { set { m_ShadowCascadeCount = value; OnValidate(); } get { return m_ShadowCascadeCount; } }
public float shadowCascadeSplit0 { set { m_ShadowCascadeSplit0 = value; OnValidate(); } get { return m_ShadowCascadeSplit0; } }

m_ShadowCascadeSplit1 = Mathf.Min(1.0f, Mathf.Max(0.0f, m_ShadowCascadeSplit1));
m_ShadowCascadeSplit2 = Mathf.Min(1.0f, Mathf.Max(0.0f, m_ShadowCascadeSplit2));
}
}
public static readonly Settings s_Defaultsettings = new Settings
{
m_ShadowCascadeCount = ShadowSettings.Default.directionalLightCascadeCount,
m_ShadowCascadeSplit0 = ShadowSettings.Default.directionalLightCascades.x,
m_ShadowMaxDistance = ShadowSettings.Default.maxShadowDistance,
m_ShadowCascadeSplit1 = ShadowSettings.Default.directionalLightCascades.y,
m_ShadowCascadeSplit2 = ShadowSettings.Default.directionalLightCascades.z
};
}
private Settings m_Settings = new Settings();
private Settings m_Settings = Settings.s_Defaultsettings;
}
public void OnEnable()
{
CommonSettingsSingleton.Refresh();
}
public void OnDisable()
{
CommonSettingsSingleton.Refresh();
}
void OnValidate()
{
if (settings != null)
settings.OnValidate();
set { m_Settings = value; }
/* public Type skyRendererType
{
set { settings.m_SkyRendererTypeName = value != null ? value.FullName : ""; OnSkyRendererChanged(); }
get { return settings.m_SkyRendererTypeName == "" ? null : Assembly.GetAssembly(typeof(CommonSettings)).GetType(settings.m_SkyRendererTypeName); }
}*/
/* void OnSkyRendererChanged()
{
HDRenderPipeline renderPipeline = Utilities.GetHDRenderPipeline();
if (renderPipeline == null)
{
return;
}
renderPipeline.InstantiateSkyRenderer(skyRendererType);
List<SkyParameters> result = new List<SkyParameters>();
gameObject.GetComponents<SkyParameters>(result);
Type skyParamType = renderPipeline.GetSkyParameterType();
// Disable all incompatible sky parameters and enable the compatible one
bool found = false;
foreach (SkyParameters param in result)
{
if (param.GetType() == skyParamType)
{
// This is a workaround the fact that we can't control the order in which components are initialized.
// So it can happen that a given SkyParameter is OnEnabled before the CommonSettings and so fail the setup because the SkyRenderer is not yet initialized.
// So we disable it to for OnEnable to be called again.
param.enabled = false;
param.enabled = true;
found = true;
}
else
{
param.enabled = false;
}
}
// If it does not exist, create the parameters
if (!found && skyParamType != null)
{
gameObject.AddComponent(skyParamType);
}
}
}*/
}

34
Assets/ScriptableRenderLoop/HDRenderPipeline/SceneSettings/CommonSettingsSingleton.cs


using System.Linq;
using UnityEngine.SceneManagement;
private CommonSettings.Settings settings { get; set; }
private CommonSettings settings { get; set; }
public static CommonSettings.Settings overrideSettings
public static CommonSettings overrideSettings
}
protected override void OnEnable()
{
SceneManager.activeSceneChanged += SceneManagerOnActiveSceneChanged;
}
protected override void OnDisable()
{
SceneManager.activeSceneChanged -= SceneManagerOnActiveSceneChanged;
set { instance.settings = value; }
protected override void SceneManagerOnActiveSceneChanged(Scene from, Scene to)
{
Refresh();
}
public static void Refresh()
{
instance.settings = null;
//TODO: Slow, and linq, make good and fast
var overrideSettings = FindObjectsOfType<CommonSettings>().Where(x => x.isActiveAndEnabled && x.gameObject.scene == SceneManager.GetActiveScene());
if (overrideSettings.Any())
instance.settings = overrideSettings.FirstOrDefault().settings;
}
}
}

10
Assets/ScriptableRenderLoop/HDRenderPipeline/Sky/HDRISky/HDRISkyParameters.cs


using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace UnityEngine.Experimental.Rendering.HDPipeline
{
[DisallowMultipleComponent]

public Cubemap skyHDRI;
public override SkyRenderer GetRenderer()
{
return new HDRISkyRenderer(this);
}
}
}

37
Assets/ScriptableRenderLoop/HDRenderPipeline/Sky/HDRISky/HDRISkyRenderer.cs


using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Experimental.Rendering.HDPipeline;
public class HDRISkyRenderer
: SkyRenderer<HDRISkyParameters>
public class HDRISkyRenderer : SkyRenderer
Material m_SkyHDRIMaterial = null; // Renders a cubemap into a render texture (can be cube or 2D)
Material m_SkyHDRIMaterial; // Renders a cubemap into a render texture (can be cube or 2D)
private HDRISkyParameters m_HdriSkyParams;
override public void Build()
public HDRISkyRenderer(HDRISkyParameters hdriSkyParams)
m_SkyHDRIMaterial = Utilities.CreateEngineMaterial("Hidden/HDRenderPipeline/Sky/SkyHDRI");
m_HdriSkyParams = hdriSkyParams;
override public void Cleanup()
public override void Build()
Utilities.Destroy(m_SkyHDRIMaterial);
m_SkyHDRIMaterial = Utilities.CreateEngineMaterial("Hidden/HDRenderPipeline/Sky/SkyHDRI");
override public bool IsSkyValid(SkyParameters skyParameters)
public override void Cleanup()
return GetParameters(skyParameters).skyHDRI != null;
Utilities.Destroy(m_SkyHDRIMaterial);
public override void SetRenderTargets(BuiltinSkyParameters builtinParams)
{
if (builtinParams.depthBuffer == BuiltinSkyParameters.nullRT)

}
}
override public void RenderSky(BuiltinSkyParameters builtinParams, SkyParameters skyParameters, bool renderForCubemap)
public override void RenderSky(BuiltinSkyParameters builtinParams, SkyParameters skyParameters, bool renderForCubemap)
HDRISkyParameters hdriSkyParams = GetParameters(skyParameters);
m_SkyHDRIMaterial.SetTexture("_Cubemap", hdriSkyParams.skyHDRI);
m_SkyHDRIMaterial.SetVector("_SkyParam", new Vector4(hdriSkyParams.exposure, hdriSkyParams.multiplier, hdriSkyParams.rotation, 0.0f));
m_SkyHDRIMaterial.SetTexture("_Cubemap", m_HdriSkyParams.skyHDRI);
m_SkyHDRIMaterial.SetVector("_SkyParam", new Vector4(m_HdriSkyParams.exposure, m_HdriSkyParams.multiplier, m_HdriSkyParams.rotation, 0.0f));
}
public override bool IsSkyValid()
{
return m_HdriSkyParams != null && m_SkyHDRIMaterial != null;
}
}
}

5
Assets/ScriptableRenderLoop/HDRenderPipeline/Sky/ProceduralSky/ProceduralSkyParameters.cs


occlusionBiasSkyRayleigh = Mathf.Clamp01(occlusionBiasSkyRayleigh);
*/
}
public override SkyRenderer GetRenderer()
{
return new ProceduralSkyRenderer(this);
}
}
}

35
Assets/ScriptableRenderLoop/HDRenderPipeline/Sky/ProceduralSky/ProceduralSkyRenderer.cs


using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Experimental.Rendering.HDPipeline;
public class ProceduralSkyRenderer
: SkyRenderer<ProceduralSkyParameters>
public class ProceduralSkyRenderer : SkyRenderer
private ProceduralSkyParameters m_ProceduralSkyParameters;
override public void Build()
public ProceduralSkyRenderer(ProceduralSkyParameters proceduralSkyParameters)
{
m_ProceduralSkyParameters = proceduralSkyParameters;
}
public override void Build()
override public void Cleanup()
public override void Cleanup()
override public bool IsSkyValid(SkyParameters skyParameters)
public override bool IsSkyValid()
ProceduralSkyParameters allParams = GetParameters(skyParameters);
if (m_ProceduralSkyMaterial == null || m_ProceduralSkyParameters == null)
return false;
return allParams.skyHDRI != null &&
allParams.worldMieColorRamp != null &&
allParams.worldRayleighColorRamp != null;
return m_ProceduralSkyParameters.skyHDRI != null &&
m_ProceduralSkyParameters.worldMieColorRamp != null &&
m_ProceduralSkyParameters.worldRayleighColorRamp != null;
}
public override void SetRenderTargets(BuiltinSkyParameters builtinParams)

override public void RenderSky(BuiltinSkyParameters builtinParams, SkyParameters skyParameters, bool renderForCubemap)
{
ProceduralSkyParameters proceduralSkyParams = GetParameters(skyParameters);
SetKeywords(builtinParams, proceduralSkyParams);
SetKeywords(builtinParams, m_ProceduralSkyParameters);
SetUniforms(builtinParams, proceduralSkyParams, ref properties);
SetUniforms(builtinParams, m_ProceduralSkyParameters, ref properties);
var cmd = new CommandBuffer { name = "" };

builtinParams.renderContext.ExecuteCommandBuffer(cmd);
cmd.Dispose();
}
}
}

52
Assets/ScriptableRenderLoop/HDRenderPipeline/Sky/SkyManager.cs


bool m_useMIS = false;
SkyParameters m_SkyParameters = null;
private SkyParameters m_SkyParameters;
if(m_Renderer != null)
if (m_SkyParameters == value)
return;
if (m_Renderer != null)
if (value == null || IsSkyParameterValid(value))
{
m_SkyParametersHash = 0;
m_SkyParameters = value;
m_UpdateRequired = true;
}
else
{
Debug.LogWarning("Sky renderer needs an instance of " + GetSkyParameterType().ToString() + " to be able to render.");
}
m_Renderer.Cleanup();
m_Renderer = null;
}
get { return m_SkyParameters; }
}
public void InstantiateSkyRenderer(Type skyRendererType)
{
if(skyRendererType == null)
{
m_Renderer = null;
}
else if (m_Renderer == null || m_Renderer.GetType() != skyRendererType)
{
m_Renderer = Activator.CreateInstance(skyRendererType) as SkyRenderer;
m_Renderer.Build();
if (value == null)
return;
m_Renderer = value.GetRenderer();
m_SkyParametersHash = 0;
m_SkyParameters = value;
m_UpdateRequired = true;
get { return m_SkyParameters; }
}
protected Mesh BuildSkyMesh(Vector3 cameraPosition, Matrix4x4 cameraInvViewProjectionMatrix, bool forceUVBottom)

public bool IsSkyValid()
{
return m_Renderer != null && m_Renderer.IsParameterValid(skyParameters) && m_Renderer.IsSkyValid(skyParameters);
return m_Renderer != null && m_Renderer.IsSkyValid();
}
private void RenderSkyToCubemap(BuiltinSkyParameters builtinParams, SkyParameters skyParameters, RenderTexture target)

m_iblFilterGgx.FilterCubemap(renderContext, input, target, mipCount, m_CubemapFaceMesh);
}
}
}
public bool IsSkyParameterValid(SkyParameters parameters)
{
return m_Renderer != null && m_Renderer.IsParameterValid(parameters);
}
public Type GetSkyParameterType()
{
return (m_Renderer == null) ? null : m_Renderer.GetSkyParameterType();
}
public void RequestEnvironmentUpdate()

12
Assets/ScriptableRenderLoop/HDRenderPipeline/Sky/SkyParameters.cs


namespace UnityEngine.Experimental.Rendering.HDPipeline
{
[ExecuteInEditMode]
public class SkyParameters : MonoBehaviour
public abstract class SkyParameters : ScriptableObject
{
protected class Unhashed : System.Attribute {}

m_Properties = GetType()
.GetFields(BindingFlags.Public | BindingFlags.Instance)
.ToArray();
SkyParametersSingleton.Refresh();
public void OnDisable()
{
SkyParametersSingleton.Refresh();
}
public int GetHash()
{
unchecked

return hash;
}
}
public abstract SkyRenderer GetRenderer();
}
}

21
Assets/ScriptableRenderLoop/HDRenderPipeline/Sky/SkyParametersSingleton.cs


using System.Linq;
using UnityEngine.SceneManagement;
#if UNITY_EDITOR
using UnityEditor;
#endif
namespace UnityEngine.Experimental.Rendering.HDPipeline
{

public static SkyParameters overrideSettings
{
get { return instance.settings; }
}
protected override void SceneManagerOnActiveSceneChanged(Scene from, Scene to)
{
Refresh();
}
public static void Refresh()
{
instance.settings = null;
//TODO: Slow, and linq, make good and fast
var overrideSettings = FindObjectsOfType<SkyParameters>().Where(x => x.isActiveAndEnabled && x.gameObject.scene == SceneManager.GetActiveScene());
if (overrideSettings.Any())
instance.settings = overrideSettings.FirstOrDefault();
set { instance.settings = value; }
}
}
}

32
Assets/ScriptableRenderLoop/HDRenderPipeline/Sky/SkyRenderer.cs


{
abstract public class SkyRenderer
{
abstract public void Build();
abstract public void Cleanup();
abstract public void SetRenderTargets(BuiltinSkyParameters builtinParams);
public abstract void Build();
public abstract void Cleanup();
public abstract void SetRenderTargets(BuiltinSkyParameters builtinParams);
abstract public void RenderSky(BuiltinSkyParameters builtinParams, SkyParameters skyParameters, bool renderForCubemap);
abstract public bool IsSkyValid(SkyParameters skyParameters);
virtual public bool IsParameterValid(SkyParameters skyParameters) { return false; }
virtual public Type GetSkyParameterType() { return typeof(SkyParameters); }
}
abstract public class SkyRenderer<ParameterType> : SkyRenderer
where ParameterType : SkyParameters
{
override public bool IsParameterValid(SkyParameters skyParameters)
{
return GetParameters(skyParameters) != null;
}
override public Type GetSkyParameterType()
{
return typeof(ParameterType);
}
protected ParameterType GetParameters(SkyParameters parameters)
{
return parameters as ParameterType;
}
public abstract void RenderSky(BuiltinSkyParameters builtinParams, SkyParameters skyParameters, bool renderForCubemap);
public abstract bool IsSkyValid();
}
}

12
Assets/ScriptableRenderLoop/core/Singleton.cs


}
}
protected virtual void OnEnable()
{
SceneManager.activeSceneChanged += SceneManagerOnActiveSceneChanged;
}
protected virtual void OnDisable()
{
SceneManager.activeSceneChanged -= SceneManagerOnActiveSceneChanged;
}
protected abstract void SceneManagerOnActiveSceneChanged(Scene arg0, Scene arg1);
static void LoadAsset()
{
if (!theInstance)

39
Assets/ScriptableRenderLoop/HDRenderPipeline/Editor/HDRenderPipeWindow.cs


using UnityEngine.Experimental.Rendering.HDPipeline;
using UnityEngine;
namespace UnityEditor.Experimental.Rendering.HDPipeline
{
public class HDRenderPipeWindow : EditorWindow
{
[MenuItem("HDRenderPipeline/Configure Overrides")]
static void ConfigureOverrides()
{
GetWindow<HDRenderPipeWindow>().Show();
}
void OnGUI()
{
CommonSettingsSingleton.overrideSettings = (CommonSettings)EditorGUILayout.ObjectField(new GUIContent("Common Settings"), CommonSettingsSingleton.overrideSettings, typeof(CommonSettings), false);
SkyParametersSingleton.overrideSettings = (SkyParameters)EditorGUILayout.ObjectField(new GUIContent("Sky Settings"), SkyParametersSingleton.overrideSettings, typeof(SkyParameters), false);
if (GUILayout.Button("Create new common settings"))
{
var instance = CreateInstance<CommonSettings>();
AssetDatabase.CreateAsset(instance, "Assets/NewCommonSettings.asset");
}
if (GUILayout.Button("Create new HDRI sky params"))
{
var instance = CreateInstance<HDRISkyParameters>();
AssetDatabase.CreateAsset(instance, "Assets/NewHDRISkyParameters.asset");
}
if (GUILayout.Button("Create new Procedural sky params"))
{
var instance = CreateInstance<ProceduralSkyParameters>();
AssetDatabase.CreateAsset(instance, "Assets/NewProceduralSkyParameters.asset");
}
}
}
}

12
Assets/ScriptableRenderLoop/HDRenderPipeline/Editor/HDRenderPipeWindow.cs.meta


fileFormatVersion: 2
guid: a6a2e8d7ee3eb2c46962c9b49ff6c8ef
timeCreated: 1485262288
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存