Skip to content

Make _rt_ResolvedFullFrameDepth use IMAGE_FORMAT_R32F #2585

@artemking4

Description

@artemking4

Details

Since _rt_ResolvedFullFrameDepth is IMAGE_FORMAT_RGBA8888 and only using red channel, it has very little precision. Custom shaders were allowed recently, but they still suffer from imprecision because of this limitation. Upgrading the depth buffer will allow for better screenspace shader effects, such as SSAO. For now, it's not possible because of a crappy 8 bit depth buffer.
This removes large artifacts from using depth buffer in custom shaders (Normal reconstruction is an example of that)
But it might not work with default DOF with gmod shaders.

Proposed solution

Make a separate _rt_ResolvedFullFrameDepth32 rendertarget with the IMAGE_FORMAT_R32F image format, which will be copied to the good old rt_ResolvedFullFrameDepth rendertarget with IMAGE_FORMAT_RGBA8888 image format. This preserves backwards compatibility, whilst improving precision.

Activity

artemking4

artemking4 commented on Jan 12, 2025

@artemking4
Author

An example of some artifacts caused by the current depth buffer.

Image

goodusername123

goodusername123 commented on Jan 12, 2025

@goodusername123

If a separate render target where to be added as purposed in this request the name should a bit more verbose imo "_rt_ResolvedFullFrameDepth32" I feel is slightly too ambiguous, something more upfront like "_rt_ResolvedFullFrameDepth_R32F" or "_rt_ResolvedFullFrameDepthR32F" might be better.

Akabenko

Akabenko commented on Jun 24, 2025

@Akabenko

32 bit depth buffer fix:

IMAGE_FORMAT_R32F =    27 // Single-channel 32-bit floating point

GetRenderTargetEx("_rt_resolvedfullframedepth", ScrW(), ScrH(),
    RT_SIZE_FULL_FRAME_BUFFER,
    MATERIAL_RT_DEPTH_SHARED,
    bit.bor(4, 8, 256, 512, 65536),
    0,
    IMAGE_FORMAT_R32F
)

hook.Add("NeedsDepthPass", "32BitDepth", function()
    return true
end)

Image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @artemking4@goodusername123@Akabenko

        Issue actions