Is this an incorrect way to create a depth buffer for a render target?

Hi! I’m messing with the render pipeline and some post processing. I’m attempting to add a simple depth fog.

This is my .render_scripts init function.

function init(self)
    local color_params = {
        format = render.FORMAT_RGBA,
        width = 128,
        height = 128,
    }
    local depth_params = {
        format = render.FORMAT_RGBA,
        width = 128,
        height = 128,
    }
    local target_params = { [render.BUFFER_COLOR_BIT] = color_params, [render.BUFFER_DEPTH_BIT] = depth_params }
    self.lowrez = render.render_target("lowrez", target_params)

    render.enable_texture("render_target", self.lowrez, render.BUFFER_DEPTH_BIT)
end

I’m getting an error Render target '(asset 262146 type=ASSET_TYPE_RENDER_TARGET)' does not have a texture for the specified buffer type (type=BUFFER_TYPE_DEPTH_BIT).

The error persists when moving the render.enable_texture to the update function.

This doesn’t feel right. Am I doing something wrong?

Found this PR. I just needed one more line of code.

For future reference:

    local depth_params = {
        format = render.FORMAT_DEPTH,
        width = 128,
        height = 128,
        flags = render.TEXTURE_BIT,
    }
1 Like