浏览代码

Refactorentrypoint (#68)

Update to the RenderPipes to support the new paradigm on how to go about writing a renderpipe.

Renderloops now should only contain configuration information + a call out to the rendering logic (preferably living in a static function). A loop now executes within a 'rendering context' that passes along a sidecar configuration file called a 'DataStore'. Any transient information that is needed between frames should be stored in this datastore (things like the materials / rendertextures). When the renderloop is destroyed this sidecar data is automatically cleaned up. It can also be cleaned manually.

Currently only the BasicRenderLoop has been ported to this new model due to the other loops not having a separation of concerns between transient data and configuration. They need the loop owners to detangle this before porting to the new model can take place. These existing loops still work, but they suffer from the same lifecycle issues they have had up unti...
/main
GitHub 8 年前
当前提交
7a0c40da
共有 21 个文件被更改,包括 358 次插入1099 次删除
  1. 40
      Assets/BasicRenderLoopTutorial/BasicRenderLoop.cs
  2. 2
      Assets/Editor/Tests/RenderloopTests/CullResultsTest.cs
  3. 31
      Assets/Editor/Tests/RenderloopTests/RenderloopTestFixture.cs
  4. 10
      Assets/ScriptableRenderLoop/HDRenderLoop/Editor/HDRenderLoopInspector.cs
  5. 78
      Assets/ScriptableRenderLoop/HDRenderLoop/HDRenderLoop.cs
  6. 8
      Assets/ScriptableRenderLoop/HDRenderLoop/Lighting/LightLoop.cs
  7. 1001
      Assets/ScriptableRenderLoop/HDRenderLoop/Lighting/TilePass/TilePass.cs
  8. 2
      Assets/ScriptableRenderLoop/HDRenderLoop/Material/Lit/Lit.cs
  9. 8
      Assets/ScriptableRenderLoop/HDRenderLoop/Sky/SkyManager.cs
  10. 18
      Assets/ScriptableRenderLoop/HDRenderLoop/Utilities.cs
  11. 6
      Assets/ScriptableRenderLoop/RenderPasses/ShadowRenderPass.cs
  12. 4
      Assets/ScriptableRenderLoop/common/SkyboxHelper.cs
  13. 68
      Assets/ScriptableRenderLoop/fptl/FptlLighting.cs
  14. 9
      Assets/ScriptableRenderLoop/core.meta
  15. 33
      Assets/ScriptableRenderLoop/core/DefaultCameraProvider.cs
  16. 12
      Assets/ScriptableRenderLoop/core/DefaultCameraProvider.cs.meta
  17. 63
      Assets/ScriptableRenderLoop/core/RenderPipeline.cs
  18. 12
      Assets/ScriptableRenderLoop/core/RenderPipeline.cs.meta
  19. 40
      Assets/ScriptableRenderLoop/core/RenderingDataStore.cs
  20. 12
      Assets/ScriptableRenderLoop/core/RenderingDataStore.cs.meta

40
Assets/BasicRenderLoopTutorial/BasicRenderLoop.cs


using System;
using System.Collections.Generic;
using UnityEngine.ScriptableRenderPipeline;
// Very basic scriptable rendering loop example:
// - Use with BasicRenderLoopShader.shader (the loop expects "BasicPass" pass type to exist)

[ExecuteInEditMode]
public class BasicRenderLoop : RenderPipeline
{
#if UNITY_EDITOR
[UnityEditor.MenuItem("Renderloop/Create BasicRenderLoop")]
static void CreateBasicRenderLoop()

}
#endif
public override void Build()
{
}
public override void Cleanup()
[NonSerialized]
readonly List<Camera> m_CamerasToRender = new List<Camera>();
public override void Render(ScriptableRenderContext renderLoop, IScriptableRenderDataStore dataStore)
base.Render(renderLoop, dataStore);
cameraProvider.GetCamerasToRender(m_CamerasToRender);
Render(renderLoop, m_CamerasToRender);
CleanCameras(m_CamerasToRender);
m_CamerasToRender.Clear();
public override void Render(Camera[] cameras, RenderLoop loop)
public static void Render(ScriptableRenderContext context, IEnumerable<Camera> cameras)
{
foreach (var camera in cameras)
{

continue;
CullResults cull = CullResults.Cull (ref cullingParams, loop);
CullResults cull = CullResults.Cull (ref cullingParams, context);
loop.SetupCameraProperties (camera);
context.SetupCameraProperties (camera);
loop.ExecuteCommandBuffer(cmd);
context.ExecuteCommandBuffer(cmd);
SetupLightShaderVariables (cull.visibleLights, loop);
SetupLightShaderVariables (cull.visibleLights, context);
loop.DrawRenderers (ref settings);
context.DrawRenderers (ref settings);
loop.DrawSkybox (camera);
context.DrawSkybox (camera);
loop.DrawRenderers (ref settings);
context.DrawRenderers (ref settings);
loop.Submit ();
context.Submit ();
static void SetupLightShaderVariables (VisibleLight[] lights, RenderLoop loop)
static void SetupLightShaderVariables (VisibleLight[] lights, ScriptableRenderContext context)
{
// We only support up to 8 visible lights here. More complex approaches would
// be doing some sort of per-object light setups, but here we go for simplest possible

cmd.SetGlobalVectorArray ("globalLightAtten", lightAtten);
cmd.SetGlobalVector ("globalLightCount", new Vector4 (lightCount, 0, 0, 0));
cmd.SetGlobalVectorArray ("globalSH", shConstants);
loop.ExecuteCommandBuffer (cmd);
context.ExecuteCommandBuffer (cmd);
cmd.Dispose ();
}

outCoefficients[6].z = ambientProbe[2, 8];
outCoefficients[6].w = 1.0f;
}
}

2
Assets/Editor/Tests/RenderloopTests/CullResultsTest.cs


[TestFixture]
public class CullResultsTest
{
void InspectCullResults(Camera camera, CullResults cullResults, RenderLoop renderLoop)
void InspectCullResults(Camera camera, CullResults cullResults, ScriptableRenderContext renderLoop)
{
VisibleReflectionProbe[] probes = cullResults.visibleReflectionProbes;

31
Assets/Editor/Tests/RenderloopTests/RenderloopTestFixture.cs


using System.Collections;
using System;
using UnityEngine.Experimental.ScriptableRenderLoop;
using UnityEngine.ScriptableRenderPipeline;
public delegate void TestDelegate(Camera camera, CullResults cullResults, RenderLoop renderLoop);
public delegate void TestDelegate(Camera camera, CullResults cullResults, ScriptableRenderContext renderLoop);
public override void Render(Camera[] cameras, RenderLoop renderLoop)
[NonSerialized]
readonly List<Camera> m_CamerasToRender = new List<Camera>();
public override void Render(ScriptableRenderContext renderLoop, IScriptableRenderDataStore dataStore)
foreach (var camera in cameras)
cameraProvider.GetCamerasToRender(m_CamerasToRender);
foreach (var camera in m_CamerasToRender)
if (!camera.enabled)
continue;
CullingParameters cullingParams;
bool gotCullingParams = CullResults.GetCullingParameters(camera, out cullingParams);
Assert.IsTrue(gotCullingParams);

}
renderLoop.Submit();
}
public override void Build()
{
CleanCameras(m_CamerasToRender);
m_CamerasToRender.Clear();
public override void Cleanup()
{
}
public static void Run(TestDelegate renderCallback)
{
if (m_Instance == null)

10
Assets/ScriptableRenderLoop/HDRenderLoop/Editor/HDRenderLoopInspector.cs


public readonly GUIContent bigTilePrepass = new GUIContent("Enable big tile prepass", "Toggle");
public readonly GUIContent clustered = new GUIContent("Enable clustered", "Toggle");
public readonly GUIContent disableTileAndCluster = new GUIContent("Disable Tile/clustered", "Toggle");
public readonly GUIContent disableDeferredShadingInCompute = new GUIContent("Disable deferred shading in compute", "Toggle");
public readonly GUIContent disableDeferredShadingInCompute = new GUIContent("Disable deferred shading in compute", "Toggle");
public readonly GUIContent textureSettings = new GUIContent("Texture Settings");
public readonly GUIContent spotCookieSize = new GUIContent("Spot cookie size");

EditorUtility.SetDirty(renderLoop); // Repaint
// SetAssetDirty will tell renderloop to rebuild
renderLoop.SetAssetDirty();
renderLoop.ClearCachedData();
}
EditorGUI.BeginChangeCheck();

78
Assets/ScriptableRenderLoop/HDRenderLoop/HDRenderLoop.cs


using UnityEngine.Experimental.Rendering;
using System.Collections.Generic;
using System;
using UnityEngine.ScriptableRenderPipeline;
namespace UnityEngine.Experimental.ScriptableRenderLoop
{

}
}
#endif
private class HDLoopDataStore : RenderingDataStore
{
public HDLoopDataStore(BaseRenderPipeline owner) : base(owner)
{ }
protected override void InternalBuild()
{
base.InternalBuild();
HDRenderLoop theOwner = owner as HDRenderLoop;
if (theOwner != null)
theOwner.Build();
}
protected override void InternalCleanup()
{
base.InternalCleanup();
HDRenderLoop theOwner = owner as HDRenderLoop;
if (theOwner != null)
theOwner.Cleanup();
}
}
public override IScriptableRenderDataStore ConstructDataStore()
{
return new HDLoopDataStore(this);
}
SkyManager m_SkyManager = new SkyManager();
public SkyManager skyManager

get { return m_CommonSettings; }
}
public override void Build()
public void Build()
{
#if UNITY_EDITOR
UnityEditor.SupportedRenderingFeatures.active = new UnityEditor.SupportedRenderingFeatures

m_lightLoop.Build(m_TextureSettings);
}
public override void Cleanup()
public void Cleanup()
{
m_lightLoop.Cleanup();
m_LitRenderLoop.Cleanup();

UnityEngine.Rendering.GraphicsSettings.lightsUseCCT = previousLightsUseCCT;
}
void InitAndClearBuffer(Camera camera, RenderLoop renderLoop)
void InitAndClearBuffer(Camera camera, ScriptableRenderContext renderLoop)
{
using (new Utilities.ProfilingSample("InitAndClearBuffer", renderLoop))
{

}
}
void RenderOpaqueRenderList(CullResults cull, Camera camera, RenderLoop renderLoop, string passName, RendererConfiguration rendererConfiguration = 0)
void RenderOpaqueRenderList(CullResults cull, Camera camera, ScriptableRenderContext renderLoop, string passName, RendererConfiguration rendererConfiguration = 0)
{
if (!debugParameters.displayOpaqueObjects)
return;

renderLoop.DrawRenderers(ref settings);
}
void RenderTransparentRenderList(CullResults cull, Camera camera, RenderLoop renderLoop, string passName, RendererConfiguration rendererConfiguration = 0)
void RenderTransparentRenderList(CullResults cull, Camera camera, ScriptableRenderContext renderLoop, string passName, RendererConfiguration rendererConfiguration = 0)
{
if (!debugParameters.displayTransparentObjects)
return;

renderLoop.DrawRenderers(ref settings);
}
void RenderDepthPrepass(CullResults cull, Camera camera, RenderLoop renderLoop)
void RenderDepthPrepass(CullResults cull, Camera camera, ScriptableRenderContext renderLoop)
{
// If we are forward only we will do a depth prepass
// TODO: Depth prepass should be enabled based on light loop settings. LightLoop define if they need a depth prepass + forward only...

}
}
void RenderGBuffer(CullResults cull, Camera camera, RenderLoop renderLoop)
void RenderGBuffer(CullResults cull, Camera camera, ScriptableRenderContext renderLoop)
{
if (debugParameters.useForwardRenderingOnly)
{

}
// This pass is use in case of forward opaque and deferred rendering. We need to render forward objects before tile lighting pass
void RenderForwardOnlyDepthPrepass(CullResults cull, Camera camera, RenderLoop renderLoop)
void RenderForwardOnlyDepthPrepass(CullResults cull, Camera camera, ScriptableRenderContext renderLoop)
{
// If we are forward only we don't need to render ForwardOpaqueDepth object
// But in case we request a prepass we render it

}
}
void RenderDebugViewMaterial(CullResults cull, HDCamera hdCamera, RenderLoop renderLoop)
void RenderDebugViewMaterial(CullResults cull, HDCamera hdCamera, ScriptableRenderContext renderLoop)
{
using (new Utilities.ProfilingSample("DebugView Material Mode Pass", renderLoop))
// Render Opaque forward

}
}
void RenderDeferredLighting(HDCamera hdCamera, RenderLoop renderLoop)
void RenderDeferredLighting(HDCamera hdCamera, ScriptableRenderContext renderLoop)
{
if (debugParameters.useForwardRenderingOnly)
{

m_lightLoop.RenderDeferredLighting(hdCamera, renderLoop, m_CameraColorBuffer);
}
void UpdateSkyEnvironment(HDCamera hdCamera, RenderLoop renderLoop)
void UpdateSkyEnvironment(HDCamera hdCamera, ScriptableRenderContext renderLoop)
void RenderSky(HDCamera hdCamera, RenderLoop renderLoop)
void RenderSky(HDCamera hdCamera, ScriptableRenderContext renderLoop)
void RenderForward(CullResults cullResults, Camera camera, RenderLoop renderLoop, bool renderOpaque)
void RenderForward(CullResults cullResults, Camera camera, ScriptableRenderContext renderLoop, bool renderOpaque)
{
// TODO: Currently we can't render opaque object forward when deferred is enabled
// miss option

// Render material that are forward opaque only (like eye)
// TODO: Think about hair that could be render both as opaque and transparent...
void RenderForwardOnly(CullResults cullResults, Camera camera, RenderLoop renderLoop)
void RenderForwardOnly(CullResults cullResults, Camera camera, ScriptableRenderContext renderLoop)
{
using (new Utilities.ProfilingSample("Forward Only Pass", renderLoop))
{

}
}
void RenderForwardUnlit(CullResults cullResults, Camera camera, RenderLoop renderLoop)
void RenderForwardUnlit(CullResults cullResults, Camera camera, ScriptableRenderContext renderLoop)
{
using (new Utilities.ProfilingSample("Forward Unlit Pass", renderLoop))
{

}
}
void RenderVelocity(CullResults cullResults, Camera camera, RenderLoop renderLoop)
void RenderVelocity(CullResults cullResults, Camera camera, ScriptableRenderContext renderLoop)
{
using (new Utilities.ProfilingSample("Velocity Pass", renderLoop))
{

}
}
void RenderDistortion(CullResults cullResults, Camera camera, RenderLoop renderLoop)
void RenderDistortion(CullResults cullResults, Camera camera, ScriptableRenderContext renderLoop)
{
if (!debugParameters.useDistortion)
return ;

}
}
void FinalPass(RenderLoop renderLoop)
void FinalPass(ScriptableRenderContext renderLoop)
{
using (new Utilities.ProfilingSample("Final Pass", renderLoop))
{

}
}
public void PushGlobalParams(HDCamera hdCamera, RenderLoop renderLoop)
public void PushGlobalParams(HDCamera hdCamera, ScriptableRenderContext renderLoop)
{
if (m_SkyManager.IsSkyValid())
{

}
}
public override void Render(Camera[] cameras, RenderLoop renderLoop)
[NonSerialized]
readonly List<Camera> m_CamerasToRender = new List<Camera>();
public override void Render(ScriptableRenderContext renderLoop, IScriptableRenderDataStore dataStore)
base.Render(renderLoop, dataStore);
cameraProvider.GetCamerasToRender(m_CamerasToRender);
if (!m_LitRenderLoop.isInit)
{
m_LitRenderLoop.RenderInit(renderLoop);

// Set Frame constant buffer
// TODO...
foreach (var camera in cameras)
foreach (var camera in m_CamerasToRender)
{
// Set camera constant buffer
// TODO...

renderLoop.Submit();
}
CleanCameras(m_CamerasToRender);
m_CamerasToRender.Clear();
// Post effects
}

8
Assets/ScriptableRenderLoop/HDRenderLoop/Lighting/LightLoop.cs


public virtual void PrepareLightsForGPU(ShadowSettings shadowSettings, CullResults cullResults, Camera camera, ref ShadowOutput shadowOutput) { }
// TODO: this should not be part of the interface but for now make something working
public virtual void BuildGPULightLists(Camera camera, RenderLoop loop, RenderTargetIdentifier cameraDepthBufferRT) { }
public virtual void BuildGPULightLists(Camera camera, ScriptableRenderContext loop, RenderTargetIdentifier cameraDepthBufferRT) { }
public virtual void PushGlobalParams(Camera camera, RenderLoop loop) {}
public virtual void PushGlobalParams(Camera camera, ScriptableRenderContext loop) {}
public virtual void RenderDeferredLighting(HDRenderLoop.HDCamera hdCamera, RenderLoop renderLoop, RenderTargetIdentifier cameraColorBufferRT) {}
public virtual void RenderDeferredLighting(HDRenderLoop.HDCamera hdCamera, ScriptableRenderContext renderLoop, RenderTargetIdentifier cameraColorBufferRT) {}
public virtual void RenderForward(Camera camera, RenderLoop renderLoop, bool renderOpaque) {}
public virtual void RenderForward(Camera camera, ScriptableRenderContext renderLoop, bool renderOpaque) {}
public Light GetCurrentSunLight() { return m_CurrentSunLight; }
}

1001
Assets/ScriptableRenderLoop/HDRenderLoop/Lighting/TilePass/TilePass.cs
文件差异内容过多而无法显示
查看文件

2
Assets/ScriptableRenderLoop/HDRenderLoop/Material/Lit/Lit.cs


isInit = false;
}
public void RenderInit(UnityEngine.Experimental.Rendering.RenderLoop renderLoop)
public void RenderInit(Rendering.ScriptableRenderContext renderLoop)
{
var cmd = new CommandBuffer();
cmd.name = "Init PreFGD";

8
Assets/ScriptableRenderLoop/HDRenderLoop/Sky/SkyManager.cs


public Vector3 cameraPosWS;
public Vector4 screenSize;
public Mesh skyMesh;
public RenderLoop renderLoop;
public ScriptableRenderContext renderLoop;
public Light sunLight;
public RenderTargetIdentifier colorBuffer;
public RenderTargetIdentifier depthBuffer;

}
}
private void RenderCubemapGGXConvolution(RenderLoop renderLoop, BuiltinSkyParameters builtinParams, SkyParameters skyParams, Texture input, RenderTexture target)
private void RenderCubemapGGXConvolution(ScriptableRenderContext renderLoop, BuiltinSkyParameters builtinParams, SkyParameters skyParams, Texture input, RenderTexture target)
{
using (new Utilities.ProfilingSample("Sky Pass: GGX Convolution", renderLoop))
{

m_UpdateRequired = true;
}
public void UpdateEnvironment(HDRenderLoop.HDCamera camera, Light sunLight, RenderLoop renderLoop)
public void UpdateEnvironment(HDRenderLoop.HDCamera camera, Light sunLight, ScriptableRenderContext renderLoop)
{
{
using (new Utilities.ProfilingSample("Sky Environment Pass", renderLoop))

}
}
public void RenderSky(HDRenderLoop.HDCamera camera, Light sunLight, RenderTargetIdentifier colorBuffer, RenderTargetIdentifier depthBuffer, RenderLoop renderLoop)
public void RenderSky(HDRenderLoop.HDCamera camera, Light sunLight, RenderTargetIdentifier colorBuffer, RenderTargetIdentifier depthBuffer, ScriptableRenderContext renderLoop)
{
using (new Utilities.ProfilingSample("Sky Pass", renderLoop))
{

18
Assets/ScriptableRenderLoop/HDRenderLoop/Utilities.cs


// Render Target Management.
public const ClearFlag kClearAll = ClearFlag.ClearDepth | ClearFlag.ClearColor;
public static void SetRenderTarget(RenderLoop renderLoop, RenderTargetIdentifier buffer, ClearFlag clearFlag = ClearFlag.ClearNone, int miplevel = 0, CubemapFace cubemapFace = CubemapFace.Unknown)
public static void SetRenderTarget(ScriptableRenderContext renderLoop, RenderTargetIdentifier buffer, ClearFlag clearFlag = ClearFlag.ClearNone, int miplevel = 0, CubemapFace cubemapFace = CubemapFace.Unknown)
{
var cmd = new CommandBuffer();
cmd.name = "";

}
public static void SetRenderTarget(RenderLoop renderLoop, RenderTargetIdentifier colorBuffer, RenderTargetIdentifier depthBuffer, int miplevel = 0, CubemapFace cubemapFace = CubemapFace.Unknown)
public static void SetRenderTarget(ScriptableRenderContext renderLoop, RenderTargetIdentifier colorBuffer, RenderTargetIdentifier depthBuffer, int miplevel = 0, CubemapFace cubemapFace = CubemapFace.Unknown)
public static void SetRenderTarget(RenderLoop renderLoop, RenderTargetIdentifier colorBuffer, RenderTargetIdentifier depthBuffer, ClearFlag clearFlag, int miplevel = 0, CubemapFace cubemapFace = CubemapFace.Unknown)
public static void SetRenderTarget(ScriptableRenderContext renderLoop, RenderTargetIdentifier colorBuffer, RenderTargetIdentifier depthBuffer, ClearFlag clearFlag, int miplevel = 0, CubemapFace cubemapFace = CubemapFace.Unknown)
public static void SetRenderTarget(RenderLoop renderLoop, RenderTargetIdentifier colorBuffer, RenderTargetIdentifier depthBuffer, ClearFlag clearFlag, Color clearColor, int miplevel = 0, CubemapFace cubemapFace = CubemapFace.Unknown)
public static void SetRenderTarget(ScriptableRenderContext renderLoop, RenderTargetIdentifier colorBuffer, RenderTargetIdentifier depthBuffer, ClearFlag clearFlag, Color clearColor, int miplevel = 0, CubemapFace cubemapFace = CubemapFace.Unknown)
{
var cmd = new CommandBuffer();
cmd.name = "";

cmd.Dispose();
}
public static void SetRenderTarget(RenderLoop renderLoop, RenderTargetIdentifier[] colorBuffers, RenderTargetIdentifier depthBuffer)
public static void SetRenderTarget(ScriptableRenderContext renderLoop, RenderTargetIdentifier[] colorBuffers, RenderTargetIdentifier depthBuffer)
public static void SetRenderTarget(RenderLoop renderLoop, RenderTargetIdentifier[] colorBuffers, RenderTargetIdentifier depthBuffer, ClearFlag clearFlag = ClearFlag.ClearNone)
public static void SetRenderTarget(ScriptableRenderContext renderLoop, RenderTargetIdentifier[] colorBuffers, RenderTargetIdentifier depthBuffer, ClearFlag clearFlag = ClearFlag.ClearNone)
public static void SetRenderTarget(RenderLoop renderLoop, RenderTargetIdentifier[] colorBuffers, RenderTargetIdentifier depthBuffer, ClearFlag clearFlag, Color clearColor)
public static void SetRenderTarget(ScriptableRenderContext renderLoop, RenderTargetIdentifier[] colorBuffers, RenderTargetIdentifier depthBuffer, ClearFlag clearFlag, Color clearColor)
{
var cmd = new CommandBuffer();
cmd.name = "";

: IDisposable
{
bool disposed = false;
RenderLoop renderLoop;
ScriptableRenderContext renderLoop;
public ProfilingSample(string _name, RenderLoop _renderloop)
public ProfilingSample(string _name, ScriptableRenderContext _renderloop)
{
renderLoop = _renderloop;
name = _name;

6
Assets/ScriptableRenderLoop/RenderPasses/ShadowRenderPass.cs


parameters.shadowDistance = Mathf.Min(m_Settings.maxShadowDistance, parameters.shadowDistance);
}
public void Render(RenderLoop loop, CullResults cullResults, out ShadowOutput packedShadows)
public void Render(ScriptableRenderContext loop, CullResults cullResults, out ShadowOutput packedShadows)
{
if (!m_Settings.enabled)
{

//---------------------------------------------------------------------------------------------------------------------------------------------------
// Render shadows
//---------------------------------------------------------------------------------------------------------------------------------------------------
void RenderPackedShadows(RenderLoop loop, CullResults cullResults, ref ShadowOutput packedShadows)
void RenderPackedShadows(ScriptableRenderContext loop, CullResults cullResults, ref ShadowOutput packedShadows)
{
var setRenderTargetCommandBuffer = new CommandBuffer();

}
//---------------------------------------------------------------------------------------------------------------------------------------------------
private void RenderShadowSplit(ref ShadowSliceData slice, Vector3 lightDirection, Matrix4x4 proj, Matrix4x4 view, ref RenderLoop loop, DrawShadowsSettings settings)
private void RenderShadowSplit(ref ShadowSliceData slice, Vector3 lightDirection, Matrix4x4 proj, Matrix4x4 view, ref ScriptableRenderContext loop, DrawShadowsSettings settings)
{
var commandBuffer = new CommandBuffer { name = "ShadowSetup" };

4
Assets/ScriptableRenderLoop/common/SkyboxHelper.cs


using System.Collections.Generic;
using UnityEngine.Rendering;
using UnityEngine.Experimental.Rendering;
using UnityEngine.Experimental.Rendering;
public class SkyboxHelper
{

get { return m_Mesh; }
}
public void Draw(RenderLoop loop, Camera camera)
public void Draw(ScriptableRenderContext loop, Camera camera)
{
if (camera.clearFlags != CameraClearFlags.Skybox)
{

68
Assets/ScriptableRenderLoop/fptl/FptlLighting.cs


using UnityEngine.Experimental.Rendering;
using System;
using System.Collections.Generic;
using UnityEngine.ScriptableRenderPipeline;
namespace UnityEngine.Experimental.ScriptableRenderLoop
{

UnityEditor.AssetDatabase.CreateAsset(instance, "Assets/renderloopfptl.asset");
//AssetDatabase.CreateAsset(instance, "Assets/ScriptableRenderLoop/fptl/renderloopfptl.asset");
}
private class FptlLightingDataStore : RenderingDataStore
{
public FptlLightingDataStore(BaseRenderPipeline owner) : base(owner)
{}
protected override void InternalBuild()
{
base.InternalBuild();
FptlLighting theOwner = owner as FptlLighting;
if (theOwner != null)
theOwner.Build();
}
protected override void InternalCleanup()
{
base.InternalCleanup();
FptlLighting theOwner = owner as FptlLighting;
if (theOwner != null)
theOwner.Cleanup();
}
}
[SerializeField]
ShadowSettings m_ShadowSettings = ShadowSettings.Default;
ShadowRenderPass m_ShadowPass;

private Texture2D m_LightAttentuationTexture;
private int m_shadowBufferID;
public override void Cleanup()
public void Cleanup()
{
if (m_DeferredMaterial) DestroyImmediate(m_DeferredMaterial);
if (m_DeferredReflectionMaterial) DestroyImmediate(m_DeferredReflectionMaterial);

}
}
public override void Build()
public void Build()
{
s_GBufferAlbedo = Shader.PropertyToID("_CameraGBufferTexture0");
s_GBufferSpecRough = Shader.PropertyToID("_CameraGBufferTexture1");

m_shadowBufferID = Shader.PropertyToID("g_tShadowBuffer");
}
public override IScriptableRenderDataStore ConstructDataStore()
{
return new FptlLightingDataStore(this);
}
static void SetupGBuffer(int width, int height, CommandBuffer cmd)
{
var format10 = RenderTextureFormat.ARGB32;

//@TODO: render VR occlusion mesh
}
static void RenderGBuffer(CullResults cull, Camera camera, RenderLoop loop)
static void RenderGBuffer(CullResults cull, Camera camera, ScriptableRenderContext loop)
{
// setup GBuffer for rendering
var cmd = new CommandBuffer { name = "Create G-Buffer" };

loop.DrawRenderers(ref settings);
}
void RenderForward(CullResults cull, Camera camera, RenderLoop loop, bool opaquesOnly)
void RenderForward(CullResults cull, Camera camera, ScriptableRenderContext loop, bool opaquesOnly)
{
var cmd = new CommandBuffer { name = opaquesOnly ? "Prep Opaques Only Forward Pass" : "Prep Forward Pass" };

loop.DrawRenderers(ref settings);
}
static void DepthOnlyForForwardOpaques(CullResults cull, Camera camera, RenderLoop loop)
static void DepthOnlyForForwardOpaques(CullResults cull, Camera camera, ScriptableRenderContext loop)
{
var cmd = new CommandBuffer { name = "Forward Opaques - Depth Only" };
cmd.SetRenderTarget(new RenderTargetIdentifier(s_GBufferZ));

}
}
static void CopyDepthAfterGBuffer(RenderLoop loop)
static void CopyDepthAfterGBuffer(ScriptableRenderContext loop)
{
var cmd = new CommandBuffer { name = "Copy depth" };
cmd.CopyTexture(new RenderTargetIdentifier(s_GBufferZ), new RenderTargetIdentifier(s_CameraDepthTexture));

void DoTiledDeferredLighting(Camera camera, RenderLoop loop, int numLights, int numDirLights)
void DoTiledDeferredLighting(Camera camera, ScriptableRenderContext loop, int numLights, int numDirLights)
{
var bUseClusteredForDeferred = !usingFptl;
var cmd = new CommandBuffer();

return numLightsOut + numProbesOut;
}
public override void Render(Camera[] cameras, RenderLoop renderLoop)
[NonSerialized]
readonly List<Camera> m_CamerasToRender = new List<Camera>();
public override void Render(ScriptableRenderContext renderLoop, IScriptableRenderDataStore dataStore)
foreach (var camera in cameras)
base.Render(renderLoop, dataStore);
cameraProvider.GetCamerasToRender(m_CamerasToRender);
foreach (var camera in m_CamerasToRender)
{
CullingParameters cullingParams;
if (!CullResults.GetCullingParameters(camera, out cullingParams))

}
renderLoop.Submit();
CleanCameras(m_CamerasToRender);
m_CamerasToRender.Clear();
void FinalPass(RenderLoop loop)
void FinalPass(ScriptableRenderContext loop)
{
var cmd = new CommandBuffer { name = "FinalPass" };
cmd.Blit(s_CameraTarget, BuiltinRenderTextureType.CameraTarget, m_BlitMaterial, 0);

void ExecuteRenderLoop(Camera camera, CullResults cullResults, RenderLoop loop)
void ExecuteRenderLoop(Camera camera, CullResults cullResults, ScriptableRenderContext loop)
{
var w = camera.pixelWidth;
var h = camera.pixelHeight;

}
void DrawLightBoundsDebug(RenderLoop loop, int numLights)
void DrawLightBoundsDebug(ScriptableRenderContext loop, int numLights)
{
var cmd = new CommandBuffer { name = "DrawLightBoundsDebug" };
m_DebugLightBoundsMaterial.SetBuffer("g_data", s_ConvexBoundsBuffer);

m_CubeReflTexArray.NewFrame();
}
void RenderShadowMaps(CullResults cullResults, RenderLoop loop)
void RenderShadowMaps(CullResults cullResults, ScriptableRenderContext loop)
{
ShadowOutput shadows;
m_ShadowPass.Render(loop, cullResults, out shadows);

cmd.DispatchCompute(buildPerVoxelLightListShader, s_GenListPerVoxelKernel, numTilesX, numTilesY, 1);
}
void BuildPerTileLightLists(Camera camera, RenderLoop loop, int numLights, Matrix4x4 projscr, Matrix4x4 invProjscr)
void BuildPerTileLightLists(Camera camera, ScriptableRenderContext loop, int numLights, Matrix4x4 projscr, Matrix4x4 invProjscr)
{
var w = camera.pixelWidth;
var h = camera.pixelHeight;

cmd.Dispose();
}
void PushGlobalParams(Camera camera, RenderLoop loop, Matrix4x4 viewToWorld, Matrix4x4 scrProj, Matrix4x4 incScrProj, int numDirLights)
void PushGlobalParams(Camera camera, ScriptableRenderContext loop, Matrix4x4 viewToWorld, Matrix4x4 scrProj, Matrix4x4 incScrProj, int numDirLights)
{
var cmd = new CommandBuffer { name = "Push Global Parameters" };

9
Assets/ScriptableRenderLoop/core.meta


fileFormatVersion: 2
guid: 2850f79359a84d84793e8feefa3ebb54
folderAsset: yes
timeCreated: 1483004461
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

33
Assets/ScriptableRenderLoop/core/DefaultCameraProvider.cs


using System.Collections.Generic;
using UnityEngine.Experimental.Rendering;
namespace UnityEngine.ScriptableRenderPipeline
{
public class DefaultCameraProvider : ICameraProvider
{
public Camera overrideCamera { get; set; }
public static void GetCamerasToRenderDefault(List<Camera> cameras)
{
cameras.Clear();
foreach (var c in Camera.allCameras)
{
if (c.enabled)
cameras.Add(c);
}
}
public void GetCamerasToRender(List<Camera> cameras)
{
if (overrideCamera != null)
{
cameras.Clear();
cameras.Add(overrideCamera);
}
else
{
GetCamerasToRenderDefault(cameras);
}
}
}
}

12
Assets/ScriptableRenderLoop/core/DefaultCameraProvider.cs.meta


fileFormatVersion: 2
guid: 3ac0b0f83d74a194f8578dc2907cacf6
timeCreated: 1483007679
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

63
Assets/ScriptableRenderLoop/core/RenderPipeline.cs


using System;
using System.Collections.Generic;
using UnityEngine.Experimental.Rendering;
namespace UnityEngine.ScriptableRenderPipeline
{
public abstract class RenderPipeline : BaseRenderPipeline
{
private readonly HashSet<IScriptableRenderDataStore> m_AssociatedDataStores = new HashSet<IScriptableRenderDataStore>();
private ICameraProvider m_CameraProvider;
public override ICameraProvider cameraProvider
{
get
{
if (m_CameraProvider == null)
m_CameraProvider = ConstructCameraProvider();
return m_CameraProvider;
}
set { m_CameraProvider = value; }
}
public override void Render(ScriptableRenderContext renderContext, IScriptableRenderDataStore dataStore)
{
if (dataStore == null)
throw new ArgumentException(string.Format("Null DataStore has been passed into pipe {0}", this));
if (dataStore.owner == null)
throw new ArgumentException(string.Format("DataStore owner is null. It needs o be owned by loop {0}", this));
if (dataStore.owner != null && !ReferenceEquals(dataStore.owner, this))
throw new ArgumentException(string.Format("DataStore {0} has been passed into pipe {1}, but is owned by {2}", dataStore, this, dataStore.owner));
m_AssociatedDataStores.Add(dataStore);
dataStore.Build();
}
public override void ClearCachedData()
{
foreach (var store in m_AssociatedDataStores)
store.Cleanup();
m_AssociatedDataStores.Clear();
}
public override ICameraProvider ConstructCameraProvider()
{
return new DefaultCameraProvider();
}
public override IScriptableRenderDataStore ConstructDataStore()
{
return new RenderingDataStore(this);
}
public static void CleanCameras(IEnumerable<Camera> cameras)
{
foreach (var camera in cameras)
camera.ClearIntermediateRenderers();
}
}
}

12
Assets/ScriptableRenderLoop/core/RenderPipeline.cs.meta


fileFormatVersion: 2
guid: 841216767fdff24409a31bd55d2f6f72
timeCreated: 1483005410
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

40
Assets/ScriptableRenderLoop/core/RenderingDataStore.cs


using UnityEngine.Experimental.Rendering;
namespace UnityEngine.ScriptableRenderPipeline
{
public class RenderingDataStore : IScriptableRenderDataStore
{
private bool m_NeedsBuild = true;
public RenderingDataStore(IRenderPipeline owner)
{
this.owner = owner;
}
public void Build()
{
if (m_NeedsBuild)
{
InternalBuild();
m_NeedsBuild = false;
}
}
protected virtual void InternalBuild()
{}
public void Cleanup()
{
if (!m_NeedsBuild)
{
InternalCleanup();
m_NeedsBuild = true;
}
}
protected virtual void InternalCleanup()
{}
public IRenderPipeline owner { get; private set; }
}
}

12
Assets/ScriptableRenderLoop/core/RenderingDataStore.cs.meta


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