|
|
|
|
|
|
|
|
|
|
[SerializeField] |
|
|
|
bool m_ShowDebugUI; |
|
|
|
|
|
|
|
|
|
|
|
RenderTexture m_DepthBuffer; |
|
|
|
public RenderTexture target { get { return m_DepthBuffer; } } |
|
|
|
|
|
|
|
Vector4 m_ZBufferParams; |
|
|
|
public Vector4 zBufferParams { get { return m_ZBufferParams; } } |
|
|
|
|
|
|
|
RenderTexture m_DepthBuffer; |
|
|
|
|
|
|
|
public RenderTexture target { get { return m_DepthBuffer; } } |
|
|
|
|
|
|
|
struct InstancedDrawArgs |
|
|
|
{ |
|
|
|
|
|
|
return instance.target; |
|
|
|
} |
|
|
|
return null; |
|
|
|
} |
|
|
|
|
|
|
|
public static Vector4 GetZBufferParams(string name) |
|
|
|
{ |
|
|
|
// we expect very few instances, optimize if it were to change
|
|
|
|
foreach (var instance in s_Instances) |
|
|
|
{ |
|
|
|
if (instance.id == name) |
|
|
|
return instance.zBufferParams; |
|
|
|
} |
|
|
|
return Vector4.zero; |
|
|
|
} |
|
|
|
|
|
|
|
class InstancingDataGenerationVisitor |
|
|
|
|
|
|
m_CmdBuffer.SetGlobalMatrix("_CameraViewProjMatrix", viewProjectionMatrix); |
|
|
|
m_CmdBuffer.SetGlobalVector("_WorldSpaceCameraPos", Vector3.zero); |
|
|
|
|
|
|
|
// TODO fix saturated depth
|
|
|
|
var f = camera.farClipPlane; |
|
|
|
var n = camera.nearClipPlane; |
|
|
|
var zBufferParams = new Vector4(1 - f / n, f / n, 1 / f - 1 / n, 1 / n); |
|
|
|
//var zBufferParams = new Vector4(-1 + f / n, 1, -1 / f + 1 / n, 1 / f);
|
|
|
|
//m_CmdBuffer.SetGlobalVector("_ZBufferParams", zBufferParams);
|
|
|
|
|
|
|
|
//m_CmdBuffer.SetGlobalDepthBias(0, 0);
|
|
|
|
|
|
|
|
foreach (var args in m_RenderingData) |
|
|
|
{ |
|
|
|
for (var i = 0; i != args.mesh.subMeshCount; ++i) |
|
|
|
|
|
|
|
|
|
|
static Vector4 GetZBufferParams(Camera camera) |
|
|
|
{ |
|
|
|
float n = camera.nearClipPlane; |
|
|
|
float f = camera.farClipPlane; |
|
|
|
bool reverseZ = false; |
|
|
|
// http://www.humus.name/temp/Linearize%20depth.txt
|
|
|
|
if (true) |
|
|
|
{ |
|
|
|
return new Vector4(-1 + f / n, 1, -1 / f + 1 / n, 1 / f); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
return new Vector4(1 - f / n, f / n, 1 / f - 1 / n, 1 / n); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
m_ZBufferParams = GetZBufferParams(camera); |
|
|
|
UpdateCommandBuffer(camera); |
|
|
|
Graphics.ExecuteCommandBuffer(m_CmdBuffer); |
|
|
|
} |
|
|
|