Log inGet started
Package

denoiser.interface

Newest version

This package holds more than this page lists. See all of its files in its world.

README.md

denoiser

Filters a noisy image a render pass wrote into a quieter image of the same size. A type that lists denoiser under interfaces: in its type.yaml guarantees that denoise adds the passes that filter signal to the frame being drawn and answers the guid of the filtered image, and that each owner's filtering keeps its own state. A render feature that shades from a few stochastic samples (a probe field read per pixel, a traced reflection or occlusion term) takes a denoiser as a setting (Field.interfaceRef("denoiser", ...)) and calls whatever asset the setting names through the interface, so a different denoiser is a different asset named in that setting.

-- inside a render feature's render(ctx)
local denoiser = ctx.settings.denoiser
local clean = denoiser:as("denoiser"):denoise("myFeature", ctx, noisy.guid, {
    phase = "afterLighting", order = 20,
})
local next = 20 + denoiser:as("denoiser"):orders("myFeature")

Implementing it

# myFilter.assetType/type.yaml
interfaces: [denoiser]
-- myFilter.assetType/behavior.luau
local M = {}
M.ref = {
    denoise = function(self, owner, ctx, signal, opts) ... return filtered.guid end,
    orders = function(self, owner, values) return 2 end,
    restart = function(self, owner) ... end,
    free = function(self, owner) ... end,
}
return M

The base inputs

  • owner names the filtering. Two features filtering in one frame pass two owners and share nothing.
  • signal is linear colour in rgb, at the frame's resolution or a whole fraction of it (a signal read at half resolution), which opts.scale states (frame pixels on a side per texel, 1 by default). Each of its texels stands for the frame pixel at its centre, the pixel whose depth, normal and motion describe it.
  • opts.phase and opts.order place the passes: they take orders consecutive orders from opts.order.
  • opts.values are values for the parameters the asset declares (asset.schema).
  • opts.guides names the channels the surfaces are read from. The scene's own are the default.

A type's own extras travel in opts beside these, are always optional, and never change a base input's meaning.

Optional inputs

A source that knows more about its signal states it in opts; a denoiser that reads none of them filters the signal alone.

  • opts.confidence = true says the signal's alpha holds, per texel, how much of that texel's light has held still since the frame before: 1 where all of it has, less as the source moved more of it. The texels where it is below 1 carry a shorter history.
  • opts.openness is the guid of a texture of the signal's size whose blue channel holds how open each texel's surface is: 1 in the open, less against geometry the source cannot see through (a crease, a contact). The texels where it is below 1 take a narrower spatial filter.

Required behaviour

  1. denoise answers a guid that holds, by the order after its last pass, the filtered image at the size of signal, in rgb.
  2. A signal that holds the same value everywhere on a surface comes back as that value there.
  3. Where the surface under a pixel changed since the frame before (a newly uncovered background, a cut), what the earlier frames held there is not carried onto it.
  4. orders states how many orders denoise takes with the same values.
  5. restart makes the next denoise start from that frame's own image; free frees what the owner held, and a later denoise starts again.