Garry's Mod Wiki

render.GetResolvedFullFrameDepth

  ITexture render.GetResolvedFullFrameDepth()

Description

Returns the _rt_ResolvedFullFrameDepth texture for SSAO depth. It will only be updated if GM:NeedsDepthPass returns true.

Returns

1 ITexture
The depth texture.

Example

Render the depth pass to the screen.

local function MyNeedsDepthPass() return true end -- Add hook so that the _rt_ResolvedFullFrameDepth texture is updated hook.Add( "NeedsDepthPass", "MyNeedsDepthPass", MyNeedsDepthPass ) local function RenderSSAOdepth() -- call render.GetResolvedFullFrameDepth() and draw the resulting itexture to the screen local texture = render.GetResolvedFullFrameDepth() render.DrawTextureToScreen( texture ) end -- Add hook to render pass to screen hook.Add( "RenderScreenspaceEffects", "RenderSSAOdepth", RenderSSAOdepth )
Output:
depth_example.png

Example: Depth buffer upgrade

This method allows you to increase the bit depth of the depth buffer. IMAGE_FORMAT_R32F does not work on Linux (dx 92). Also, 32-bit image formats do not work on Windows without D3D9EX.

D3D9EX = !GetConVar("mat_disable_d3d9ex"):GetBool() cvars.AddChangeCallback("mat_disable_d3d9ex", function(convar_name, value_old, value_new) D3D9EX = !tobool(value_new) end) IMAGE_FORMAT_R32F = 27 // Single-channel 32-bit floating point IMAGE_FORMAT_RGBA32323232F = 29 GetRenderTargetEx("_rt_resolvedfullframedepth", ScrW(), ScrH(), RT_SIZE_FULL_FRAME_BUFFER, MATERIAL_RT_DEPTH_SHARED, bit.bor(4, 8, 256, 512, 65536), 0, render.GetDXLevel() == 92 and IMAGE_FORMAT_RGBA32323232F or (D3D9EX and IMAGE_FORMAT_R32F or IMAGE_FORMAT_RGBA16161616F) ) hook.Add("NeedsDepthPass", "32BitDepth", function() return true end)