diff options
author | chai <chaifix@163.com> | 2021-10-01 10:04:00 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2021-10-01 10:04:00 +0800 |
commit | f0ae9393da021fe16af32f7ae1a3245f27050f92 (patch) | |
tree | eb3618a8661c6771098cdfe796bdff50b4e75328 /Assets/Scripts/Rendering | |
parent | 5b19af7f51ad4504fc426b8387442f6b868b5f61 (diff) |
*misc
Diffstat (limited to 'Assets/Scripts/Rendering')
-rw-r--r-- | Assets/Scripts/Rendering/CustomLight.cs | 46 | ||||
-rw-r--r-- | Assets/Scripts/Rendering/CustomLight.cs.meta | 11 | ||||
-rw-r--r-- | Assets/Scripts/Rendering/CustomRenderingPipeline.cs | 19 |
3 files changed, 64 insertions, 12 deletions
diff --git a/Assets/Scripts/Rendering/CustomLight.cs b/Assets/Scripts/Rendering/CustomLight.cs new file mode 100644 index 00000000..404dee12 --- /dev/null +++ b/Assets/Scripts/Rendering/CustomLight.cs @@ -0,0 +1,46 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class CustomLight : MonoBehaviour +{ + // Start is called before the first frame update + void OnEnable() + { + CustomLightRegistry.Instance.Register(this); + } + + // Update is called once per frame + void OnDisable() + { + CustomLightRegistry.Instance.Unregister(this); + } +} + +public class CustomLightRegistry : Singleton<CustomLightRegistry> +{ + private List<CustomLight> m_Lights; + public List<CustomLight> lights + { + get + { + if (m_Lights == null) + m_Lights = new List<CustomLight>(); + return m_Lights; + } + } + + public void Register(CustomLight renderer) + { + if (!lights.Contains(renderer)) + { + lights.Add(renderer); + } + } + + public void Unregister(CustomLight renderer) + { + lights.Remove(renderer); + } + +}
\ No newline at end of file diff --git a/Assets/Scripts/Rendering/CustomLight.cs.meta b/Assets/Scripts/Rendering/CustomLight.cs.meta new file mode 100644 index 00000000..51106c9d --- /dev/null +++ b/Assets/Scripts/Rendering/CustomLight.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: d07937a2b7582554e9ec6ba1fcf41504 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Rendering/CustomRenderingPipeline.cs b/Assets/Scripts/Rendering/CustomRenderingPipeline.cs index 9387cf52..befeed87 100644 --- a/Assets/Scripts/Rendering/CustomRenderingPipeline.cs +++ b/Assets/Scripts/Rendering/CustomRenderingPipeline.cs @@ -5,6 +5,7 @@ using UnityEngine; using UnityEngine.Rendering; // 相机的自定义管线 +// 混合延迟渲染和前向渲染 [RequireComponent(typeof(MainCamera))] public class CustomRenderingPipeline : MonoBehaviour {
@@ -22,12 +23,10 @@ public class CustomRenderingPipeline : MonoBehaviour // command buffers
CommandBuffer m_CommandBufferAfterDepth;
- RenderTargetIdentifier[] m_GBuffer = new RenderTargetIdentifier[4];
+ RenderTargetIdentifier[] m_GBuffer = new RenderTargetIdentifier[2];
RenderTargetIdentifier m_DepthBuffer;
- RenderTexture m_GBufferTextureDiffuse;
RenderTexture m_GBufferTextureNormal;
RenderTexture m_GBufferTexturePosition;
- RenderTexture m_GBufferTextureTexCoord;
void OnEnable()
{
@@ -35,20 +34,16 @@ public class CustomRenderingPipeline : MonoBehaviour // command buffers
m_CommandBufferAfterDepth = new CommandBuffer();
- m_Camera.AddCommandBuffer(CameraEvent.AfterDepthTexture, m_CommandBufferAfterDepth);
+ m_CommandBufferAfterDepth.name = "Custom RenderPipeline GBuffer";
+ m_Camera.AddCommandBuffer(CameraEvent.AfterDepthTexture, m_CommandBufferAfterDepth);
// render targets
int width = m_Camera.pixelWidth, height = m_Camera.pixelHeight;
- m_GBufferTextureDiffuse = RenderTexture.GetTemporary(width, height, 24, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Linear);
m_GBufferTextureNormal = RenderTexture.GetTemporary(width, height, 24, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Linear);
m_GBufferTexturePosition = RenderTexture.GetTemporary(width, height, 24, RenderTextureFormat.ARGBHalf, RenderTextureReadWrite.Linear);
- m_GBufferTextureTexCoord = RenderTexture.GetTemporary(width, height, 24, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Linear);
- m_GBuffer[0] = m_GBufferTextureDiffuse.colorBuffer;
- m_GBuffer[1] = m_GBufferTextureNormal.colorBuffer;
- m_GBuffer[2] = m_GBufferTexturePosition.colorBuffer;
- m_GBuffer[3] = m_GBufferTextureTexCoord.colorBuffer;
- m_DepthBuffer = m_GBufferTextureDiffuse.depthBuffer;
-
+ m_GBuffer[0] = m_GBufferTextureNormal.colorBuffer;
+ m_GBuffer[1] = m_GBufferTexturePosition.colorBuffer;
+ m_DepthBuffer = m_GBufferTextureNormal.depthBuffer;
} void OnDisable()
|