|
|
|
|
|
|
using System; |
|
|
|
using System.Collections.Generic; |
|
|
|
using System.Security.AccessControl; |
|
|
|
using System.Text.RegularExpressions; |
|
|
|
using Unity.ClusterRendering.Toolkit; |
|
|
|
using UnityEngine; |
|
|
|
using UnityEngine.Rendering; |
|
|
|
|
|
|
|
|
|
|
[SerializeField] |
|
|
|
Vector2Int m_RenderTargetSize; |
|
|
|
|
|
|
|
[SerializeField] |
|
|
|
Material m_Material; |
|
|
|
|
|
|
|
[SerializeField] |
|
|
|
|
|
|
RenderTexture m_DepthBuffer; |
|
|
|
CommandBuffer m_CmdBuffer; |
|
|
|
|
|
|
|
|
|
|
|
public RenderTexture target { get { return m_DepthBuffer; } } |
|
|
|
|
|
|
|
struct InstancedDrawArgs |
|
|
|
|
|
|
|
|
|
|
void OnEnable() |
|
|
|
{ |
|
|
|
var shader = Shader.Find("HDRP/Lit"); |
|
|
|
//m_Material = new Material(shader);
|
|
|
|
//m_Material.enableInstancing = true;
|
|
|
|
var shader = Shader.Find("HDRP/Unlit"); |
|
|
|
m_Material = new Material(shader); |
|
|
|
m_Material.enableInstancing = true; |
|
|
|
m_CmdBuffer = new CommandBuffer(); |
|
|
|
|
|
|
|
s_Instances.Add(this); |
|
|
|
|
|
|
{ |
|
|
|
s_Instances.Remove(this); |
|
|
|
|
|
|
|
//DestroyImmediate(m_Material);
|
|
|
|
DestroyImmediate(m_Material); |
|
|
|
m_CmdBuffer.Release(); |
|
|
|
if (m_DepthBuffer != null) |
|
|
|
m_DepthBuffer.Release(); |
|
|
|
|
|
|
|
|
|
|
void OnGUI() |
|
|
|
{ |
|
|
|
if (m_ShowDebugUI && m_DepthBuffer != null) |
|
|
|
GUI.DrawTexture(new Rect(0, Screen.height, Screen.width, -Screen.height), m_DepthBuffer); |
|
|
|
if (m_ShowDebugUI && m_DepthBuffer != null) |
|
|
|
{ |
|
|
|
//GUI.DrawTexture(new Rect(0, 0, 256, 256), m_DepthBuffer);
|
|
|
|
GUI.DrawTexture(new Rect(0, 0, Screen.width, Screen.height), m_DepthBuffer); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// TODO optim only render if camera moved
|
|
|
|
|
|
|
|
|
|
|
var projectionMatrix = GL.GetGPUProjectionMatrix(camera.projectionMatrix, true); |
|
|
|
var viewMatrix = camera.worldToCameraMatrix; |
|
|
|
var viewProjectionMatrix = camera.projectionMatrix * camera.worldToCameraMatrix; |
|
|
|
|
|
|
|
var viewProjectionMatrix = projectionMatrix * viewMatrix; |
|
|
|
|
|
|
|
m_CmdBuffer.SetGlobalMatrix("_InvViewMatrix", viewMatrix.inverse); |
|
|
|
m_CmdBuffer.SetGlobalMatrix("_ProjMatrix", projectionMatrix); |
|
|
|
m_CmdBuffer.SetGlobalMatrix("_InvProjMatrix", projectionMatrix.inverse); |
|
|
|
m_CmdBuffer.SetGlobalMatrix("_ViewProjMatrix", viewProjectionMatrix); |
|
|
|
|
|
|
m_CmdBuffer.SetGlobalVector("_ShadowClipPlanes", Vector3.zero); |
|
|
|
|
|
|
|
|
|
|
|
m_CmdBuffer.SetGlobalVector("_ZBufferParams", zBufferParams); |
|
|
|
//m_CmdBuffer.SetGlobalVector("_ZBufferParams", zBufferParams);
|
|
|
|
|
|
|
|
//m_CmdBuffer.SetGlobalDepthBias(0, 0);
|
|
|
|
|
|
|
|
foreach (var args in m_RenderingData) |
|
|
|
{ |
|
|
|