shifttab
I’m trying to show the depth. Am I doing this correctly?
SharedPtr<Viewport> viewport(new Viewport(context_, m_scene, camera));
viewport->SetRenderPath(cache->GetResource<XMLFile>("RenderPaths/DeferredHWDepth.xml"));
viewport->GetRenderPath()->Append(cache->GetResource<XMLFile>("Post/ShowDepth.xml"));
auto renderer = context_->GetSubsystem<Renderer>();
renderer->SetViewport(0, viewport);
ShowDepth.xml
<renderpath>
<command type="quad" vs="MyDepthTexture" ps="MyDepthTexture" output="viewport">
<texture unit="depth" name="depth" />
</command>
</renderpath>
// MyDepthTexture.glsl
void VS()
{
mat4 modelMatrix = iModelMatrix;
vec3 worldPos = GetWorldPos(modelMatrix);
gl_Position = GetClipPos(worldPos);
vScreenPos = GetScreenPosPreDiv(gl_Position);
}
void PS()
{
float depth = ReconstructDepth(texture2D(sDepthBuffer, vScreenPos).r);
vec3 color = vec3(depth, depth, depth);
gl_FragColor = vec4(color, 1.0);
}
Result: