浏览代码

Updated project and SRLs to use new GraphicsSettings registration interface.

In order to register a scriptable render loop goto GraphicsSettings and set there.
/main
Felipe Lira 8 年前
当前提交
d2f48b79
共有 14 个文件被更改,包括 125 次插入245 次删除
  1. 24
      Assets/BasicRenderLoopTutorial/BasicRenderLoop.cs
  2. 23
      Assets/BasicRenderLoopTutorial/BasicRenderLoopScene.unity
  3. 3
      Assets/Editor/Tests/RenderloopTests/CullResultsTest.cs
  4. 32
      Assets/Editor/Tests/RenderloopTests/RenderloopTestFixture.cs
  5. 35
      Assets/ScriptableRenderLoop/HDRenderLoop/HDRenderLoop.cs
  6. 63
      Assets/ScriptableRenderLoop/fptl/FptlLighting.cs
  7. 38
      ProjectSettings/GraphicsSettings.asset
  8. 13
      Assets/basicrenderloop.asset
  9. 8
      Assets/basicrenderloop.asset.meta
  10. 14
      Assets/ScriptableRenderLoop/ScriptableRenderLoop.cs
  11. 12
      Assets/ScriptableRenderLoop/ScriptableRenderLoop.cs.meta
  12. 93
      Assets/ScriptableRenderLoop/ScriptableRenderLoopPicker.cs
  13. 12
      Assets/ScriptableRenderLoop/ScriptableRenderLoopPicker.cs.meta

24
Assets/BasicRenderLoopTutorial/BasicRenderLoop.cs


using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.Experimental.Rendering;
using UnityEngine.Experimental.ScriptableRenderLoop;
// Very basic scriptable rendering loop example:
// - Use with BasicRenderLoopShader.shader (the loop expects "BasicPass" pass type to exist)

// - This loop also does not setup lightmaps, light probes, reflection probes or light cookies
[ExecuteInEditMode]
public class BasicRenderLoop : MonoBehaviour
public class BasicRenderLoop : ScriptableRenderLoop
private ShaderPassName shaderPassBasic;
public void OnEnable ()
#if UNITY_EDITOR
[UnityEditor.MenuItem("Renderloop/CreateBasicRenderLoop")]
static void CreateBasicRenderLoop()
shaderPassBasic = new ShaderPassName ("BasicPass");
RenderLoop.renderLoopDelegate += Render;
var instance = ScriptableObject.CreateInstance<BasicRenderLoop>();
UnityEditor.AssetDatabase.CreateAsset(instance, "Assets/basicrenderloop.asset");
#endif
public void OnDisable ()
private ShaderPassName shaderPassBasic;
public override void Initialize()
RenderLoop.renderLoopDelegate -= Render;
shaderPassBasic = new ShaderPassName("BasicPass");
bool Render (Camera[] cameras, RenderLoop loop)
public override void Render(Camera[] cameras, RenderLoop loop)
{
foreach (var camera in cameras)
{

loop.Submit ();
}
return true;
}

23
Assets/BasicRenderLoopTutorial/BasicRenderLoopScene.unity


m_ReflectionIntensity: 0.5
m_CustomReflection: {fileID: 0}
m_Sun: {fileID: 0}
m_IndirectSpecularColor: {r: 0.090675384, g: 0.11147798, b: 0.14205901, a: 0.5}
m_IndirectSpecularColor: {r: 0.09067501, g: 0.11147752, b: 0.14205909, a: 0.5}
--- !u!157 &3
LightmapSettings:
m_ObjectHideFlags: 0

m_AutoUVMaxAngle: 89
m_LightmapParameters: {fileID: 0}
m_SortingLayerID: 0
m_SortingLayer: 0
m_SortingOrder: 0
--- !u!135 &261580744
SphereCollider:

m_AutoUVMaxAngle: 89
m_LightmapParameters: {fileID: 0}
m_SortingLayerID: 0
m_SortingLayer: 0
m_SortingOrder: 0
--- !u!136 &531853422
CapsuleCollider:

m_AutoUVMaxAngle: 89
m_LightmapParameters: {fileID: 0}
m_SortingLayerID: 0
m_SortingLayer: 0
m_SortingOrder: 0
--- !u!64 &1280249097
MeshCollider:

m_AutoUVMaxAngle: 89
m_LightmapParameters: {fileID: 0}
m_SortingLayerID: 0
m_SortingLayer: 0
m_SortingOrder: 0
--- !u!135 &1405931299
SphereCollider:

- component: {fileID: 1447851828}
- component: {fileID: 1447851827}
- component: {fileID: 1447851826}
- component: {fileID: 1447851831}
m_Layer: 0
m_Name: Main Camera
m_TagString: MainCamera

m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &1447851831
MonoBehaviour:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1447851825}
m_Enabled: 0
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 22228a1bd982b864ea6c84db2fc11dd1, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!1 &1485985477
GameObject:
m_ObjectHideFlags: 0

m_AutoUVMaxAngle: 89
m_LightmapParameters: {fileID: 0}
m_SortingLayerID: 0
m_SortingLayer: 0
m_SortingOrder: 0
--- !u!136 &1485985479
CapsuleCollider:

m_AutoUVMaxAngle: 89
m_LightmapParameters: {fileID: 0}
m_SortingLayerID: 0
m_SortingLayer: 0
m_SortingOrder: 0
--- !u!135 &1596459101
SphereCollider:

m_AutoUVMaxAngle: 89
m_LightmapParameters: {fileID: 0}
m_SortingLayerID: 0
m_SortingLayer: 0
m_SortingOrder: 0
--- !u!136 &1714697414
CapsuleCollider:

m_AutoUVMaxAngle: 89
m_LightmapParameters: {fileID: 0}
m_SortingLayerID: 0
m_SortingLayer: 0
m_SortingOrder: 0
--- !u!135 &1749252041
SphereCollider:

m_AutoUVMaxAngle: 89
m_LightmapParameters: {fileID: 0}
m_SortingLayerID: 0
m_SortingLayer: 0
m_SortingOrder: 0
--- !u!135 &2031315347
SphereCollider:

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


public void TestReflectionProbes()
{
UnityEditor.SceneManagement.EditorSceneManager.OpenScene("Assets/Editor/Tests/TestScene.unity");
// Asserts.ExpectLogError("Boing");
RenderLoopTestFixture.Run(InspectCullResults);
}
}

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


using UnityEditor;
using UnityEngine.Experimental.Rendering;
using NUnit.Framework;
using UnityEngine.Experimental.ScriptableRenderLoop;
using UnityEngine.Rendering;
public class RenderLoopTestFixture : MonoBehaviour
public class RenderLoopTestFixture : ScriptableRenderLoop
public static void Render(RenderLoopWrapper wrapper, Camera[] cameras, RenderLoop renderLoop)
private static RenderLoopTestFixture m_Instance;
public override void Render(Camera[] cameras, RenderLoop renderLoop)
{
foreach (var camera in cameras)
{

CullResults cullResults = CullResults.Cull(ref cullingParams, renderLoop);
s_Callback(camera, cullResults, renderLoop);
if (s_Callback != null)
s_Callback(camera, cullResults, renderLoop);
}
renderLoop.Submit();

{
if (m_Instance == null)
{
m_Instance = ScriptableObject.CreateInstance<RenderLoopTestFixture>();
}
var instance = camObject.AddComponent<RenderLoopWrapper>();
instance.callback = Render;
GraphicsSettings.SetScriptableRenderLoop(m_Instance);
instance.enabled = true;
Transform t = camObject.transform;
// Can't use AlignViewToObject because it animates over time, and we want the first frame

SceneView.lastActiveSceneView.LookAtDirect(t.position + t.forward * camDist, t.rotation, size);
// Invoke renderer
try
{
sceneCamera.Render();
}
finally
{
Object.DestroyImmediate(instance);
}
sceneCamera.Render();
GraphicsSettings.SetScriptableRenderLoop(null);
}
}

35
Assets/ScriptableRenderLoop/HDRenderLoop/HDRenderLoop.cs


TextureCache2D m_CookieTexArray;
TextureCacheCubemap m_CubeCookieTexArray;
void OnEnable()
{
Rebuild();
}
void OnValidate()
{
m_Dirty = true;

m_Dirty = false;
}
void OnDisable()
public override void Initialize()
{
#if UNITY_EDITOR
UnityEditor.SupportedRenderingFeatures.active = new UnityEditor.SupportedRenderingFeatures
{
reflectionProbe = UnityEditor.SupportedRenderingFeatures.ReflectionProbe.Rotation
};
#endif
Rebuild();
}
public override void CleanUp()
{
m_LitRenderLoop.OnDisable();
m_SinglePassLightLoop.OnDisable();

m_CubeCookieTexArray.Release();
m_SkyRenderer.OnDisable();
#if UNITY_EDITOR
UnityEditor.SupportedRenderingFeatures.active = UnityEditor.SupportedRenderingFeatures.Default;
#endif
}
void NewFrame()

// Post effects
}
#if UNITY_EDITOR
public override UnityEditor.SupportedRenderingFeatures GetSupportedRenderingFeatures()
{
var features = new UnityEditor.SupportedRenderingFeatures
{
reflectionProbe = UnityEditor.SupportedRenderingFeatures.ReflectionProbe.Rotation
};
return features;
}
#endif
}
}

63
Assets/ScriptableRenderLoop/fptl/FptlLighting.cs


private Texture2D m_LightAttentuationTexture;
private int m_shadowBufferID;
void OnEnable()
public override void Initialize()
}
private void OnDisable()
{
CleanUp();
}
public override void CleanUp()
{
// RenderLoop.renderLoopDelegate -= ExecuteRenderLoop;
if (m_DeferredMaterial) DestroyImmediate(m_DeferredMaterial);
if (m_DeferredReflectionMaterial) DestroyImmediate(m_DeferredReflectionMaterial);
if (m_BlitMaterial) DestroyImmediate(m_BlitMaterial);
if (m_DebugLightBoundsMaterial) DestroyImmediate(m_DebugLightBoundsMaterial);
if (m_NHxRoughnessTexture) DestroyImmediate(m_NHxRoughnessTexture);
if (m_LightAttentuationTexture) DestroyImmediate(m_LightAttentuationTexture);
m_CookieTexArray.Release();
m_CubeCookieTexArray.Release();
m_CubeReflTexArray.Release();
s_AABBBoundsBuffer.Release();
s_ConvexBoundsBuffer.Release();
s_LightDataBuffer.Release();
ReleaseResolutionDependentBuffers();
s_DirLightList.Release();
if (enableClustered)
{
s_GlobalLightListAtomic.Release();
}
ClearComputeBuffers();
}
void OnValidate()

s_BigTileLightList = null;
m_shadowBufferID = Shader.PropertyToID("g_tShadowBuffer");
}
void OnDisable()
{
// RenderLoop.renderLoopDelegate -= ExecuteRenderLoop;
if (m_DeferredMaterial) DestroyImmediate(m_DeferredMaterial);
if (m_DeferredReflectionMaterial) DestroyImmediate(m_DeferredReflectionMaterial);
if (m_BlitMaterial) DestroyImmediate(m_BlitMaterial);
if (m_DebugLightBoundsMaterial) DestroyImmediate(m_DebugLightBoundsMaterial);
if (m_NHxRoughnessTexture) DestroyImmediate(m_NHxRoughnessTexture);
if (m_LightAttentuationTexture) DestroyImmediate(m_LightAttentuationTexture);
m_CookieTexArray.Release();
m_CubeCookieTexArray.Release();
m_CubeReflTexArray.Release();
s_AABBBoundsBuffer.Release();
s_ConvexBoundsBuffer.Release();
s_LightDataBuffer.Release();
ReleaseResolutionDependentBuffers();
s_DirLightList.Release();
if (enableClustered)
{
s_GlobalLightListAtomic.Release();
}
}
static void SetupGBuffer(int width, int height, CommandBuffer cmd)

38
ProjectSettings/GraphicsSettings.asset


m_PreloadedShaders: []
m_SpritesDefaultMaterial: {fileID: 10754, guid: 0000000000000000f000000000000000,
type: 0}
m_TierSettings_Tier1:
renderingPath: 1
useCascadedShadowMaps: 1
useHDR: 0
hdrMode: 0
m_TierSettings_Tier2:
renderingPath: 1
useCascadedShadowMaps: 1
useHDR: 0
hdrMode: 0
m_TierSettings_Tier3:
renderingPath: 1
useCascadedShadowMaps: 1
useHDR: 0
hdrMode: 0
m_ScriptableRenderLoop: {fileID: 11400000, guid: 9654ae26e66cbee45b8d2a4f8cac0ceb,
type: 2}
m_TransparencySortMode: 0
m_TransparencySortAxis: {x: 0, y: 0, z: 1}
- serializedVersion: 2
- serializedVersion: 3
hdrMode: 0
hdrMode: 1
useHDR: 0
useHDR: 1
- serializedVersion: 2
- serializedVersion: 3
hdrMode: 0
hdrMode: 1
useHDR: 0
useHDR: 1
- serializedVersion: 2
- serializedVersion: 3
hdrMode: 0
hdrMode: 1
useHDR: 0
useHDR: 1
useDetailNormalMap: 1
useCascadedShadowMaps: 1
useDitherMaskForAlphaBlendedShadows: 1

m_FogKeepLinear: 1
m_FogKeepExp: 1
m_FogKeepExp2: 1
m_AlbedoSwatchInfos: []

13
Assets/basicrenderloop.asset


%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 22228a1bd982b864ea6c84db2fc11dd1, type: 3}
m_Name: basicrenderloop
m_EditorClassIdentifier:

8
Assets/basicrenderloop.asset.meta


fileFormatVersion: 2
guid: f77fc78803cb35147ab3c0811feb562d
timeCreated: 1480085360
licenseType: Pro
NativeFormatImporter:
userData:
assetBundleName:
assetBundleVariant:

14
Assets/ScriptableRenderLoop/ScriptableRenderLoop.cs


using UnityEngine.Experimental.Rendering;
namespace UnityEngine.Experimental.ScriptableRenderLoop
{
public abstract class ScriptableRenderLoop : ScriptableObject
{
public abstract void Render(Camera[] cameras, RenderLoop renderLoop);
public virtual void Rebuild() {}
#if UNITY_EDITOR
public virtual UnityEditor.SupportedRenderingFeatures GetSupportedRenderingFeatures() { return new UnityEditor.SupportedRenderingFeatures(); }
#endif
}
}

12
Assets/ScriptableRenderLoop/ScriptableRenderLoop.cs.meta


fileFormatVersion: 2
guid: 4a2689a80c91a4fb8bec214a015b9cdc
timeCreated: 1466769781
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

93
Assets/ScriptableRenderLoop/ScriptableRenderLoopPicker.cs


using UnityEngine.Experimental.Rendering;
namespace UnityEngine.Experimental.ScriptableRenderLoop
{
//@TODO: This should be moved into GraphicsSettings
[ExecuteInEditMode]
public class ScriptableRenderLoopPicker : MonoBehaviour
{
public ScriptableRenderLoop renderloop
{
get { return m_RenderLoop; }
set { m_RenderLoop = value; }
}
[SerializeField]
private ScriptableRenderLoop m_RenderLoop;
// TEMPORARY
public int legacyRenderLoopMaxShaderLOD = int.MaxValue;
void OnEnable()
{
RenderLoop.renderLoopDelegate += Render;
SyncRenderingFeatures();
}
void OnValidate()
{
SyncRenderingFeatures();
}
void SyncRenderingFeatures()
{
if (m_RenderLoop != null && isActiveAndEnabled)
Shader.globalMaximumLOD = int.MaxValue;
#if UNITY_EDITOR
if (m_RenderLoop != null && isActiveAndEnabled)
UnityEditor.SupportedRenderingFeatures.active = m_RenderLoop.GetSupportedRenderingFeatures();
else
UnityEditor.SupportedRenderingFeatures.active = UnityEditor.SupportedRenderingFeatures.Default;
#endif
}
void OnDisable()
{
RenderLoop.renderLoopDelegate -= Render;
Shader.globalMaximumLOD = legacyRenderLoopMaxShaderLOD;
#if UNITY_EDITOR
UnityEditor.SupportedRenderingFeatures.active = UnityEditor.SupportedRenderingFeatures.Default;
#endif
}
bool Render(Camera[] cameras, RenderLoop loop)
{
if (m_RenderLoop == null)
return false;
#if UNITY_EDITOR
if (m_AssetVersion != s_GlobalAssetVersion)
{
m_AssetVersion = s_GlobalAssetVersion;
m_RenderLoop.Rebuild();
}
#endif
m_RenderLoop.Render(cameras, loop);
return true;
}
#if UNITY_EDITOR
// Temporary hack to allow compute shader reloading
internal class AssetReloader : UnityEditor.AssetPostprocessor
{
static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths)
{
foreach (var str in importedAssets)
{
if (str.EndsWith(".compute"))
{
s_GlobalAssetVersion++;
break;
}
}
}
}
static int s_GlobalAssetVersion = 0;
int m_AssetVersion = 0;
#endif
}
}

12
Assets/ScriptableRenderLoop/ScriptableRenderLoopPicker.cs.meta


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