|
|
|
|
|
|
|
|
|
|
static List<CustomDepthBuffer> s_Instances = new List<CustomDepthBuffer>(); |
|
|
|
|
|
|
|
public static RenderTexture GetTarget(string name) |
|
|
|
static CustomDepthBuffer GetInstance(string name) |
|
|
|
// we expect very few instances, optimize if it were to change
|
|
|
|
// we expect a very limited number of instances, optimize otherwise
|
|
|
|
return instance.target; |
|
|
|
return instance; |
|
|
|
|
|
|
|
public static RenderTexture GetTarget(string name) |
|
|
|
{ |
|
|
|
var instance = GetInstance(name); |
|
|
|
if (instance == null) |
|
|
|
return null; |
|
|
|
return instance.target; |
|
|
|
} |
|
|
|
// 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; |
|
|
|
var instance = GetInstance(name); |
|
|
|
if (instance == null) |
|
|
|
return Vector4.zero; |
|
|
|
return instance.zBufferParams; |
|
|
|
} |
|
|
|
|
|
|
|
class InstancingDataGenerationVisitor |
|
|
|
|
|
|
m_CmdBuffer.ClearRenderTarget(true, true, Color.black); |
|
|
|
|
|
|
|
var projectionMatrix = GL.GetGPUProjectionMatrix(camera.projectionMatrix, true); |
|
|
|
|
|
|
|
m_ZBufferParams = GetZBufferParams(camera, projectionMatrix); |
|
|
|
|
|
|
|
var viewMatrix = camera.worldToCameraMatrix; |
|
|
|
var viewProjectionMatrix = projectionMatrix * viewMatrix; |
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
static Vector4 GetZBufferParams(Camera camera) |
|
|
|
static Vector4 GetZBufferParams(Camera camera, Matrix4x4 projectionMatrix) |
|
|
|
bool reverseZ = false; |
|
|
|
// http://www.humus.name/temp/Linearize%20depth.txt
|
|
|
|
if (true) |
|
|
|
{ |
|
|
|
float scale = projectionMatrix[2, 3] / (f * n) * (f - n); |
|
|
|
bool reverseZ = scale > 0; |
|
|
|
|
|
|
|
if (reverseZ) |
|
|
|
} |
|
|
|
{ |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
void Update() |
|
|
|
|
|
|
{ |
|
|
|
m_ZBufferParams = GetZBufferParams(camera); |
|
|
|
UpdateCommandBuffer(camera); |
|
|
|
Graphics.ExecuteCommandBuffer(m_CmdBuffer); |
|
|
|
} |
|
|
|