浏览代码

- First version of sky renderer

- Added an Utilities class for re-usable methods in the renderloop (SetRenderTarget, Material creation, etc...)
/main
Julien Ignace 8 年前
当前提交
fd04e67f
共有 8 个文件被更改,包括 326 次插入138 次删除
  1. 2
      Assets/ScriptableRenderLoop/HDRenderLoop/Editor/HDRenderLoopInspector.cs
  2. 167
      Assets/ScriptableRenderLoop/HDRenderLoop/HDRenderLoop.cs
  3. 16
      Assets/ScriptableRenderLoop/HDRenderLoop/Sky/Resources/SkyHDRI.shader
  4. 10
      Assets/ScriptableRenderLoop/ShaderLibrary/Common.hlsl
  5. 135
      Assets/ScriptableRenderLoop/HDRenderLoop/Sky/SkyRenderer.cs
  6. 12
      Assets/ScriptableRenderLoop/HDRenderLoop/Sky/SkyRenderer.cs.meta
  7. 110
      Assets/ScriptableRenderLoop/HDRenderLoop/Utilities.cs
  8. 12
      Assets/ScriptableRenderLoop/HDRenderLoop/Utilities.cs.meta

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


skyParameters.skyHDRI = (Cubemap)EditorGUILayout.ObjectField("Cubemap", skyParameters.skyHDRI, typeof(Cubemap), false);
skyParameters.exposure = Mathf.Max(Mathf.Min(EditorGUILayout.FloatField(styles.skyExposure, skyParameters.exposure), 32), -32);
skyParameters.multiplier = Mathf.Max(EditorGUILayout.FloatField(styles.skyMultiplier, skyParameters.multiplier), 0);
skyParameters.rotation = Mathf.Max(Mathf.Min(EditorGUILayout.FloatField(styles.skyRotation, skyParameters.rotation), 360), 0);
skyParameters.rotation = Mathf.Max(Mathf.Min(EditorGUILayout.FloatField(styles.skyRotation, skyParameters.rotation), 360), -360);
if (EditorGUI.EndChangeCheck())
{

167
Assets/ScriptableRenderLoop/HDRenderLoop/HDRenderLoop.cs


#endif
public class SkyParameters
{
public Cubemap skyHDRI;
public float rotation;
public float exposure;
public float multiplier;
}
SkyRenderer m_SkyRenderer = null;
[SerializeField]
SkyParameters m_SkyParameters = new SkyParameters();

}
}
public RenderTargetIdentifier[] GetGBuffers(CommandBuffer cmd)
public RenderTargetIdentifier[] GetGBuffers()
{
var colorMRTs = new RenderTargetIdentifier[gbufferCount];
for (int index = 0; index < gbufferCount; index++)

TextureSettings m_TextureSettings = TextureSettings.Default;
// Various set of material use in render loop
Material m_SkyboxMaterial;
Material m_SkyHDRIMaterial;
Material m_DeferredMaterial;
Material m_FinalPassMaterial;
Material m_DebugViewMaterialGBuffer;

int s_CameraDepthBuffer;
int s_VelocityBuffer;
int s_DistortionBuffer;
RenderTargetIdentifier s_CameraColorBufferRT;
RenderTargetIdentifier s_CameraDepthBufferRT;
RenderTargetIdentifier s_VelocityBufferRT;
RenderTargetIdentifier s_DistortionBufferRT;
public class LightList
{

Rebuild();
}
Material CreateEngineMaterial(string shaderPath)
{
var mat = new Material(Shader.Find(shaderPath) as Shader)
{
hideFlags = HideFlags.HideAndDontSave
};
return mat;
}
// TODO: We need to have an API to send our sky information to Enlighten. For now use a workaround through skybox/cubemap material...
m_SkyboxMaterial = CreateEngineMaterial("Skybox/Cubemap");
RenderSettings.skybox = m_SkyboxMaterial; // Setup this material as the default to be use in RenderSettings
RenderSettings.ambientIntensity = 1.0f; // fix this to 1, this parameter should not exist!
RenderSettings.ambientMode = UnityEngine.Rendering.AmbientMode.Skybox; // Force skybox for our HDRI
RenderSettings.reflectionIntensity = 1.0f;
s_CameraColorBufferRT = new RenderTargetIdentifier(s_CameraColorBuffer);
s_CameraDepthBufferRT = new RenderTargetIdentifier(s_CameraDepthBuffer);
m_SkyRenderer = new SkyRenderer();
m_SkyRenderer.Rebuild();
m_SkyHDRIMaterial = CreateEngineMaterial("Hidden/HDRenderLoop/SkyHDRI");
m_DeferredMaterial = CreateEngineMaterial("Hidden/HDRenderLoop/Deferred");
m_FinalPassMaterial = CreateEngineMaterial("Hidden/HDRenderLoop/FinalPass");
m_DebugViewMaterialGBuffer = CreateEngineMaterial("Hidden/HDRenderLoop/DebugViewMaterialGBuffer");
m_DeferredMaterial = Utilities.CreateEngineMaterial("Hidden/HDRenderLoop/Deferred");
m_FinalPassMaterial = Utilities.CreateEngineMaterial("Hidden/HDRenderLoop/FinalPass");
m_DebugViewMaterialGBuffer = Utilities.CreateEngineMaterial("Hidden/HDRenderLoop/DebugViewMaterialGBuffer");
m_ShadowPass = new ShadowRenderPass(m_ShadowSettings);

m_gbufferManager.SetBufferDescription(m_gbufferManager.gbufferCount, "_VelocityTexture", Builtin.RenderLoop.GetVelocityBufferFormat(), Builtin.RenderLoop.GetVelocityBufferReadWrite());
m_gbufferManager.gbufferCount++;
}
s_VelocityBufferRT = new RenderTargetIdentifier(s_VelocityBuffer);
s_DistortionBufferRT = new RenderTargetIdentifier(s_DistortionBuffer);
m_LitRenderLoop.Rebuild();

m_LitRenderLoop.OnDisable();
m_SinglePassLightLoop.OnDisable();
//m_TilePassLightLoop.OnDisable();
if (m_SkyboxMaterial) DestroyImmediate(m_SkyboxMaterial);
if (m_SkyHDRIMaterial) DestroyImmediate(m_SkyHDRIMaterial);
if (m_DeferredMaterial) DestroyImmediate(m_DeferredMaterial);
if (m_FinalPassMaterial) DestroyImmediate(m_FinalPassMaterial);
if (m_DebugViewMaterialGBuffer) DestroyImmediate(m_DebugViewMaterialGBuffer);
Utilities.Destroy(m_DeferredMaterial);
Utilities.Destroy(m_FinalPassMaterial);
Utilities.Destroy(m_DebugViewMaterialGBuffer);
m_SkyRenderer.OnDisable();
}
void NewFrame()

var cmd = new CommandBuffer();
cmd.name = "Clear GBuffer";
// Write into the Camera Depth buffer
cmd.SetRenderTarget(m_gbufferManager.GetGBuffers(cmd), new RenderTargetIdentifier(s_CameraDepthBuffer));
cmd.SetRenderTarget(m_gbufferManager.GetGBuffers(), new RenderTargetIdentifier(s_CameraDepthBuffer));
// Clear everything
// TODO: Clear is not required for color as we rewrite everything, will save performance.
cmd.ClearRenderTarget(false, true, new Color(0, 0, 0, 0));

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

rendererConfiguration = 0,
sorting = { sortOptions = SortOptions.SortByMaterialThenMesh }
};
settings.inputFilter.SetQueuesOpaque();
renderLoop.DrawRenderers(ref settings);
}
void RenderOpaqueRenderList(CullResults cull, Camera camera, RenderLoop renderLoop, string passName)
{
if (!debugParameters.displayOpaqueObjects)
return;
var settings = new DrawRendererSettings(cull, camera, new ShaderPassName(passName))
{
rendererConfiguration = RendererConfiguration.PerObjectLightProbe | RendererConfiguration.PerObjectReflectionProbes | RendererConfiguration.PerObjectLightmaps | RendererConfiguration.PerObjectLightProbeProxyVolume,
rendererConfiguration = rendererConfiguration,
sorting = { sortOptions = SortOptions.SortByMaterialThenMesh }
};
settings.inputFilter.SetQueuesOpaque();

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

rendererConfiguration = 0,
sorting = { sortOptions = SortOptions.BackToFront }
};
settings.inputFilter.SetQueuesTransparent();
renderLoop.DrawRenderers(ref settings);
}
void RenderTransparentRenderList(CullResults cull, Camera camera, RenderLoop renderLoop, string passName)
{
if (!debugParameters.displayTransparentObjects)
return;
var settings = new DrawRendererSettings(cull, camera, new ShaderPassName(passName))
{
rendererConfiguration = RendererConfiguration.PerObjectLightProbe | RendererConfiguration.PerObjectReflectionProbes | RendererConfiguration.PerObjectLightmaps | RendererConfiguration.PerObjectLightProbeProxyVolume,
rendererConfiguration = rendererConfiguration,
sorting = { sortOptions = SortOptions.BackToFront }
};
settings.inputFilter.SetQueuesTransparent();

renderLoop.ExecuteCommandBuffer(cmd);
cmd.Dispose();
RenderOpaqueNoLightingRenderList(cull, camera, renderLoop, "DepthOnly");
RenderOpaqueRenderList(cull, camera, renderLoop, "DepthOnly");
}
void RenderGBuffer(CullResults cull, Camera camera, RenderLoop renderLoop)

// setup GBuffer for rendering
var cmd = new CommandBuffer { name = "GBuffer Pass" };
cmd.SetRenderTarget(m_gbufferManager.GetGBuffers(cmd), new RenderTargetIdentifier(s_CameraDepthBuffer));
cmd.SetRenderTarget(m_gbufferManager.GetGBuffers(), new RenderTargetIdentifier(s_CameraDepthBuffer));
RenderOpaqueRenderList(cull, camera, renderLoop, "GBuffer");
RenderOpaqueRenderList(cull, camera, renderLoop, "GBuffer", Utilities.kRendererConfigurationBakedLighting);
}
// This pass is use in case of forward opaque and deferred rendering. We need to render forward objects before tile lighting pass

return;
// TODO: Use the render queue index to only send the forward opaque!
var cmd = new CommandBuffer { name = "Depth Prepass" };
var cmd = new CommandBuffer { name = "Depth Prepass" };
RenderOpaqueNoLightingRenderList(cull, camera, renderLoop, "DepthOnly");
RenderOpaqueRenderList(cull, camera, renderLoop, "DepthOnly");
}
void RenderDebugViewMaterial(CullResults cull, Camera camera, RenderLoop renderLoop)

void RenderSky(Camera camera, RenderLoop renderLoop)
{
/*
// Render sky into a cubemap - doesn't happen every frame, can be control
// TODO: do a render to texture here
// Downsample the cubemap and provide it to Enlighten
// TODO: currently workaround is to set the cubemap in a Skybox/cubemap material
//m_SkyboxMaterial.SetTexture(cubemap);
// Render the sky itself
Vector3[] vertData = new Vector3[4];
vertData[0] = new Vector3(-1.0f, -1.0f, 0.0f);
vertData[1] = new Vector3(1.0f, -1.0f, 0.0f);
vertData[2] = new Vector3(1.0f, 1.0f, 0.0f);
vertData[3] = new Vector3(-1.0f, 1.0f, 0.0f);
Vector3[] eyeVectorData = new Vector3[4];
// camera.worldToCameraMatrix, camera.projectionMatrix
// Get view vector vased on the frustrum, i.e (invert transform frustrum get position etc...)
eyeVectorData[0] =
eyeVectorData[1] =
eyeVectorData[2] =
eyeVectorData[3] =
// Write out the mesh
var triangles = new int[4];
for (int i = 0; i < 4; i++)
{
triangles[i] = i;
}
Mesh mesh = new Mesh
{
vertices = vertData,
normals = eyeVectorData,
triangles = triangles
};
m_SkyHDRIMaterial.SetTexture("_Cubemap", skyParameters.skyHDRI);
m_SkyHDRIMaterial.SetVector("_SkyParam", new Vector4(skyParameters.exposure, skyParameters.multiplier, skyParameters.rotation, 0.0f));
var cmd = new CommandBuffer { name = "Skybox" };
cmd.DrawMesh(mesh, Matrix4x4.identity, m_SkyHDRIMaterial);
renderloop.ExecuteCommandBuffer(cmd);
cmd.Dispose();
*/
m_SkyRenderer.RenderSky(camera, m_SkyParameters, s_CameraColorBufferRT, s_CameraDepthBufferRT, renderLoop);
}
void RenderForward(CullResults cullResults, Camera camera, RenderLoop renderLoop)

RenderOpaqueRenderList(cullResults, camera, renderLoop, "Forward");
}
RenderTransparentRenderList(cullResults, camera, renderLoop, "Forward");
RenderTransparentRenderList(cullResults, camera, renderLoop, "Forward", Utilities.kRendererConfigurationBakedLighting);
}
void RenderForwardUnlit(CullResults cullResults, Camera camera, RenderLoop renderLoop)

renderLoop.ExecuteCommandBuffer(cmd);
cmd.Dispose();
RenderOpaqueNoLightingRenderList(cullResults, camera, renderLoop, "ForwardUnlit");
RenderTransparentNoLightingRenderList(cullResults, camera, renderLoop, "ForwardUnlit");
RenderOpaqueRenderList(cullResults, camera, renderLoop, "ForwardUnlit");
RenderTransparentRenderList(cullResults, camera, renderLoop, "ForwardUnlit");
}
void RenderVelocity(CullResults cullResults, Camera camera, RenderLoop renderLoop)

renderLoop.ExecuteCommandBuffer(cmd);
cmd.Dispose();
RenderOpaqueNoLightingRenderList(cullResults, camera, renderLoop, "MotionVectors");
RenderOpaqueRenderList(cullResults, camera, renderLoop, "MotionVectors");
#pragma warning restore 162, 429
}

cmd.Dispose();
// Only transparent object can render distortion vectors
RenderTransparentNoLightingRenderList(cullResults, camera, renderLoop, "DistortionVectors");
RenderTransparentRenderList(cullResults, camera, renderLoop, "DistortionVectors");
}

16
Assets/ScriptableRenderLoop/HDRenderLoop/Sky/Resources/SkyHDRI.shader


Pass
{
ZWrite Off
Blend SrcAlpha OneMinusSrcAlpha // We will lerp only the values that are valid
ZTest LEqual
Blend One Zero
HLSLPROGRAM
#pragma target 5.0

// TODO: implement SV_vertexID full screen quad
Varyings output;
output.positionCS = float4(input.positionCS.xy, UNITY_RAW_FAR_CLIP_VALUE
#if UNITY_REVERSED_Z
+ 0.000001
#else
- 0.000001
#endif
, 1.0);
output.eyeVector = input.eyeVector;

float3 dir = normalize(input.eyeVector);
// Rotate direction
float phi = _SkyParam.z * PI / 180.0; // Convert to radiant
float phi = DegToRad(_SkyParam.z);
sincos(phi, cosPhi, sinPhi);
float3 rotDirX = float3(cosPhi, 0, sinPhi);
float3 rotDirY = float3(sinPhi, 0, -cosPhi);
sincos(phi, sinPhi, cosPhi);
float3 rotDirX = float3(cosPhi, 0, -sinPhi);
float3 rotDirY = float3(sinPhi, 0, cosPhi);
dir = float3(dot(rotDirX, dir), dir.y, dot(rotDirY, dir));
return ClampToFloat16Max(SAMPLE_TEXTURECUBE_LOD(_Cubemap, sampler_Cubemap, dir, 0) * exp2(_SkyParam.x) * _SkyParam.y);

10
Assets/ScriptableRenderLoop/ShaderLibrary/Common.hlsl


#define MERGE_NAME(X, Y) X##Y
float DegToRad(float deg)
{
return deg * PI / 180.0;
}
float RadToDeg(float rad)
{
return rad * 180.0 / PI;
}
// Acos in 14 cycles.
// Ref: https://seblagarde.wordpress.com/2014/12/01/inverse-trigonometric-functions-gpu-optimization-for-amd-gcn-architecture/
float FastACos(float inX)

135
Assets/ScriptableRenderLoop/HDRenderLoop/Sky/SkyRenderer.cs


using UnityEngine.Rendering;
using UnityEngine.Experimental.Rendering;
using System.Collections.Generic;
using System;
namespace UnityEngine.Experimental.ScriptableRenderLoop
{
[Serializable]
public class SkyParameters
{
public Cubemap skyHDRI;
public float rotation = 0.0f;
public float exposure = 0.0f;
public float multiplier = 1.0f;
}
public class SkyRenderer
{
const int kSkyCubemapSize = 128;
RenderTexture m_SkyboxCubemap = null;
Material m_SkyboxMaterial = null;
Material m_SkyHDRIMaterial = null;
Mesh BuildSkyMesh(Camera camera)
{
Vector4 vertData0 = new Vector4(-1.0f, -1.0f, 1.0f, 1.0f);
Vector4 vertData1 = new Vector4(1.0f, -1.0f, 1.0f, 1.0f);
Vector4 vertData2 = new Vector4(1.0f, 1.0f, 1.0f, 1.0f);
Vector4 vertData3 = new Vector4(-1.0f, 1.0f, 1.0f, 1.0f);
Vector3[] vertData = new Vector3[4];
vertData[0] = new Vector3(vertData0.x, vertData0.y, vertData0.z);
vertData[1] = new Vector3(vertData1.x, vertData1.y, vertData1.z);
vertData[2] = new Vector3(vertData2.x, vertData2.y, vertData2.z);
vertData[3] = new Vector3(vertData3.x, vertData3.y, vertData3.z);
// Get view vector vased on the frustrum, i.e (invert transform frustrum get position etc...)
Vector3[] eyeVectorData = new Vector3[4];
Matrix4x4 transformMatrix = camera.cameraToWorldMatrix * camera.projectionMatrix.inverse;
Vector4 posWorldSpace0 = transformMatrix * vertData0;
Vector4 posWorldSpace1 = transformMatrix * vertData1;
Vector4 posWorldSpace2 = transformMatrix * vertData2;
Vector4 posWorldSpace3 = transformMatrix * vertData3;
Vector3 temp = camera.GetComponent<Transform>().position;
Vector4 cameraPosition = new Vector4(temp.x, temp.y, temp.z, 0.0f);
Vector4 direction0 = (posWorldSpace0 / posWorldSpace0.w - cameraPosition);
Vector4 direction1 = (posWorldSpace1 / posWorldSpace1.w - cameraPosition);
Vector4 direction2 = (posWorldSpace2 / posWorldSpace2.w - cameraPosition);
Vector4 direction3 = (posWorldSpace3 / posWorldSpace3.w - cameraPosition);
if (SystemInfo.graphicsUVStartsAtTop)
{
eyeVectorData[3] = new Vector3(direction0.x, direction0.y, direction0.z).normalized;
eyeVectorData[2] = new Vector3(direction1.x, direction1.y, direction1.z).normalized;
eyeVectorData[1] = new Vector3(direction2.x, direction2.y, direction2.z).normalized;
eyeVectorData[0] = new Vector3(direction3.x, direction3.y, direction3.z).normalized;
}
else
{
eyeVectorData[0] = new Vector3(direction0.x, direction0.y, direction0.z).normalized;
eyeVectorData[1] = new Vector3(direction1.x, direction1.y, direction1.z).normalized;
eyeVectorData[2] = new Vector3(direction2.x, direction2.y, direction2.z).normalized;
eyeVectorData[3] = new Vector3(direction3.x, direction3.y, direction3.z).normalized;
}
// Write out the mesh
var triangles = new int[6] { 0, 1, 2, 2, 3, 0 };
return new Mesh
{
vertices = vertData,
normals = eyeVectorData,
triangles = triangles
};
}
public void Rebuild()
{
// TODO: We need to have an API to send our sky information to Enlighten. For now use a workaround through skybox/cubemap material...
m_SkyboxMaterial = Utilities.CreateEngineMaterial("Skybox/Cubemap");
RenderSettings.skybox = m_SkyboxMaterial; // Setup this material as the default to be use in RenderSettings
RenderSettings.ambientIntensity = 1.0f; // fix this to 1, this parameter should not exist!
RenderSettings.ambientMode = UnityEngine.Rendering.AmbientMode.Skybox; // Force skybox for our HDRI
RenderSettings.reflectionIntensity = 1.0f;
m_SkyHDRIMaterial = Utilities.CreateEngineMaterial("Hidden/HDRenderLoop/SkyHDRI");
m_SkyboxCubemap = new RenderTexture(kSkyCubemapSize, kSkyCubemapSize, 1, RenderTextureFormat.ARGBHalf);
m_SkyboxCubemap.dimension = TextureDimension.Cube;
m_SkyboxCubemap.Create();
}
public void OnDisable()
{
Utilities.Destroy(m_SkyboxMaterial);
Utilities.Destroy(m_SkyHDRIMaterial);
//m_SkyboxCubemap.Release();
Utilities.Destroy(m_SkyboxCubemap);
}
public void RenderSky(Camera camera, SkyParameters skyParameters, RenderTargetIdentifier colorBuffer, RenderTargetIdentifier depthBuffer, RenderLoop renderLoop)
{
// Render sky into a cubemap - doesn't happen every frame, can be control
// TODO: do a render to texture here
// Downsample the cubemap and provide it to Enlighten
// TODO: currently workaround is to set the cubemap in a Skybox/cubemap material
//m_SkyboxMaterial.SetTexture(cubemap);
// Render the sky itself
Utilities.SetRenderTarget(renderLoop, colorBuffer, depthBuffer, "Sky Pass");
Mesh skyMesh = BuildSkyMesh(camera);
m_SkyHDRIMaterial.SetTexture("_Cubemap", skyParameters.skyHDRI);
m_SkyHDRIMaterial.SetVector("_SkyParam", new Vector4(skyParameters.exposure, skyParameters.multiplier, skyParameters.rotation, 0.0f));
var cmd = new CommandBuffer { name = "Skybox" };
cmd.DrawMesh(skyMesh, Matrix4x4.identity, m_SkyHDRIMaterial);
renderLoop.ExecuteCommandBuffer(cmd);
cmd.Dispose();
}
}
}

12
Assets/ScriptableRenderLoop/HDRenderLoop/Sky/SkyRenderer.cs.meta


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

110
Assets/ScriptableRenderLoop/HDRenderLoop/Utilities.cs


using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.Experimental.Rendering;
using UnityObject = UnityEngine.Object;
namespace UnityEngine.Experimental.ScriptableRenderLoop
{
[Flags]
public enum ClearFlag
{
ClearNone = 0,
ClearColor = 1,
ClearDepth = 2
}
public class Utilities
{
public const RendererConfiguration kRendererConfigurationBakedLighting = RendererConfiguration.PerObjectLightProbe | RendererConfiguration.PerObjectReflectionProbes | RendererConfiguration.PerObjectLightmaps | RendererConfiguration.PerObjectLightProbeProxyVolume;
// Render Target Management.
public const ClearFlag kClearAll = ClearFlag.ClearDepth | ClearFlag.ClearColor;
public static void SetRenderTarget(RenderLoop renderLoop, RenderTargetIdentifier depthBuffer, string name = "")
{
var cmd = new CommandBuffer();
cmd.name = name;
cmd.SetRenderTarget(depthBuffer);
renderLoop.ExecuteCommandBuffer(cmd);
cmd.Dispose();
}
public static void SetRenderTarget(RenderLoop renderLoop, RenderTargetIdentifier colorBuffer, RenderTargetIdentifier depthBuffer, string name = "")
{
//RenderTargetIdentifier[] colorBuffers = { colorBuffer };
SetRenderTarget(renderLoop, colorBuffer, depthBuffer, ClearFlag.ClearNone, new Color(0.0f, 0.0f, 0.0f, 0.0f), name);
}
public static void SetRenderTarget(RenderLoop renderLoop, RenderTargetIdentifier colorBuffer, RenderTargetIdentifier depthBuffer, ClearFlag clearFlag, string name = "")
{
//RenderTargetIdentifier[] colorBuffers = { colorBuffer };
SetRenderTarget(renderLoop, colorBuffer, depthBuffer, clearFlag, new Color(0.0f, 0.0f, 0.0f, 0.0f), name);
}
public static void SetRenderTarget(RenderLoop renderLoop, RenderTargetIdentifier colorBuffer, RenderTargetIdentifier depthBuffer, ClearFlag clearFlag, Color clearColor, string name = "")
{
var cmd = new CommandBuffer();
cmd.name = name;
cmd.SetRenderTarget(colorBuffer, depthBuffer);
if (clearFlag != ClearFlag.ClearNone)
cmd.ClearRenderTarget((clearFlag & ClearFlag.ClearDepth) != 0, (clearFlag & ClearFlag.ClearColor) != 0, clearColor);
renderLoop.ExecuteCommandBuffer(cmd);
cmd.Dispose();
//RenderTargetIdentifier[] colorBuffers = { colorBuffer };
//SetRenderTarget(renderLoop, colorBuffers, depthBuffer, clearFlag, clearColor, name);
}
public static void SetRenderTarget(RenderLoop renderLoop, RenderTargetIdentifier[] colorBuffers, RenderTargetIdentifier depthBuffer, string name = "")
{
SetRenderTarget(renderLoop, colorBuffers, depthBuffer, ClearFlag.ClearNone, Color.black, name);
}
public static void SetRenderTarget(RenderLoop renderLoop, RenderTargetIdentifier[] colorBuffers, RenderTargetIdentifier depthBuffer, ClearFlag clearFlag = ClearFlag.ClearNone, string name = "")
{
SetRenderTarget(renderLoop, colorBuffers, depthBuffer, clearFlag, Color.black, name);
}
public static void SetRenderTarget(RenderLoop renderLoop, RenderTargetIdentifier[] colorBuffers, RenderTargetIdentifier depthBuffer, ClearFlag clearFlag, Color clearColor, string name = "" )
{
var cmd = new CommandBuffer();
cmd.name = name;
cmd.SetRenderTarget(colorBuffers, depthBuffer);
if (clearFlag != ClearFlag.ClearNone)
cmd.ClearRenderTarget((clearFlag & ClearFlag.ClearDepth) != 0, (clearFlag & ClearFlag.ClearColor) != 0, clearColor);
renderLoop.ExecuteCommandBuffer(cmd);
cmd.Dispose();
}
// Miscellanous
public static Material CreateEngineMaterial(string shaderPath)
{
var mat = new Material(Shader.Find(shaderPath))
{
hideFlags = HideFlags.HideAndDontSave
};
return mat;
}
public static void Destroy(UnityObject obj)
{
if (obj != null)
{
#if UNITY_EDITOR
if (Application.isPlaying)
UnityObject.Destroy(obj);
else
UnityObject.DestroyImmediate(obj);
#else
UnityObject.Destroy(obj);
#endif
}
}
}
}

12
Assets/ScriptableRenderLoop/HDRenderLoop/Utilities.cs.meta


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