浏览代码

infer zbuffer parameters from projection

/main
etienne cella 5 年前
当前提交
df378a0b
共有 1 个文件被更改,包括 23 次插入19 次删除
  1. 42
      Assets/ClusterDisplay/Scripts/CustomDepthBuffer.cs

42
Assets/ClusterDisplay/Scripts/CustomDepthBuffer.cs


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);
}

正在加载...
取消
保存