filter

package
v0.2.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 24, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ChainPadding

func ChainPadding(filters []Filter) int

ChainPadding returns the cumulative padding required by a slice of filters.

func InitShaders

func InitShaders()

InitShaders eagerly compiles all built-in filter shaders so that any compilation failure panics at startup rather than at an unpredictable frame.

Types

type BlurFilter

type BlurFilter struct {
	Radius int
	// contains filtered or unexported fields
}

BlurFilter applies a Kawase iterative blur using downscale/upscale passes. No Kage shader needed — bilinear filtering during DrawImage does the work.

func NewBlurFilter

func NewBlurFilter(radius int) *BlurFilter

NewBlurFilter creates a blur filter with the given radius (in pixels).

func (*BlurFilter) Apply

func (f *BlurFilter) Apply(src, dst *ebiten.Image)

Apply renders a Kawase blur from src into dst using iterative downscale/upscale.

func (*BlurFilter) Padding

func (f *BlurFilter) Padding() int

Padding returns the blur radius; the offscreen buffer is expanded to avoid clipping.

type ColorMatrixFilter

type ColorMatrixFilter struct {
	Matrix [20]float64
	// contains filtered or unexported fields
}

ColorMatrixFilter applies a 4x5 color matrix transformation using a Kage shader. The matrix is stored in row-major order: [R_r, R_g, R_b, R_a, R_offset, G_r, ...].

func NewColorMatrixFilter

func NewColorMatrixFilter() *ColorMatrixFilter

NewColorMatrixFilter creates a color matrix filter initialized to the identity.

func (*ColorMatrixFilter) Apply

func (f *ColorMatrixFilter) Apply(src, dst *ebiten.Image)

Apply renders the color matrix transformation from src into dst.

func (*ColorMatrixFilter) Padding

func (f *ColorMatrixFilter) Padding() int

Padding returns 0; color matrix transforms don't expand the image bounds.

func (*ColorMatrixFilter) SetBrightness

func (f *ColorMatrixFilter) SetBrightness(b float64) *ColorMatrixFilter

SetBrightness sets the matrix to adjust brightness by the given offset [-1, 1].

func (*ColorMatrixFilter) SetContrast

func (f *ColorMatrixFilter) SetContrast(c float64) *ColorMatrixFilter

SetContrast sets the matrix to adjust contrast. c=1 is normal, 0=gray, >1 is higher.

func (*ColorMatrixFilter) SetGrayscale

func (f *ColorMatrixFilter) SetGrayscale() *ColorMatrixFilter

SetGrayscale sets the matrix to full grayscale (equivalent to SetSaturation(0)).

func (*ColorMatrixFilter) SetHueRotation

func (f *ColorMatrixFilter) SetHueRotation(radians float64) *ColorMatrixFilter

SetHueRotation sets the matrix to rotate hue by the given angle in radians.

func (*ColorMatrixFilter) SetInvert

func (f *ColorMatrixFilter) SetInvert() *ColorMatrixFilter

SetInvert sets the matrix to invert RGB channels (negate and offset).

func (*ColorMatrixFilter) SetSaturation

func (f *ColorMatrixFilter) SetSaturation(s float64) *ColorMatrixFilter

SetSaturation sets the matrix to adjust saturation. s=1 is normal, 0=grayscale.

type CustomShaderFilter

type CustomShaderFilter struct {
	Shader   *ebiten.Shader
	Uniforms map[string]any
	Images   [3]*ebiten.Image
	// contains filtered or unexported fields
}

CustomShaderFilter wraps a user-provided Kage shader, exposing Ebitengine's shader system directly. Images[0] is auto-filled with the source texture; the user may set Images[1] and Images[2] for additional textures.

func NewCustomShaderFilter

func NewCustomShaderFilter(shader *ebiten.Shader, padding int) *CustomShaderFilter

NewCustomShaderFilter creates a custom shader filter with the given shader and padding.

func (*CustomShaderFilter) Apply

func (f *CustomShaderFilter) Apply(src, dst *ebiten.Image)

Apply runs the user-provided Kage shader with src as Images[0].

func (*CustomShaderFilter) Padding

func (f *CustomShaderFilter) Padding() int

Padding returns the padding value set at construction time.

type Filter

type Filter interface {
	// Apply renders src into dst with the filter effect.
	Apply(src, dst *ebiten.Image)
	// Padding returns the extra pixels needed around the source to accommodate
	// the effect (e.g. blur radius, outline thickness). Zero means no padding.
	Padding() int
}

Filter is the interface for visual effects applied to a node's rendered output.

type OutlineFilter

type OutlineFilter struct {
	Thickness int
	Color     types.Color
	// contains filtered or unexported fields
}

OutlineFilter draws the source in 8 cardinal/diagonal offsets with the outline color, then draws the original on top. Works at any thickness.

func NewOutlineFilter

func NewOutlineFilter(thickness int, c types.Color) *OutlineFilter

NewOutlineFilter creates an outline filter.

func (*OutlineFilter) Apply

func (f *OutlineFilter) Apply(src, dst *ebiten.Image)

Apply draws an 8-direction offset outline behind the source image.

func (*OutlineFilter) Padding

func (f *OutlineFilter) Padding() int

Padding returns the outline thickness; the offscreen buffer is expanded by this amount.

type PaletteFilter

type PaletteFilter struct {
	Palette     [256]types.Color
	CycleOffset float64
	// contains filtered or unexported fields
}

PaletteFilter remaps pixel colors through a 256-entry color palette based on luminance. Supports a cycle offset for palette animation.

func NewPaletteFilter

func NewPaletteFilter() *PaletteFilter

NewPaletteFilter creates a palette filter with a default grayscale palette.

func (*PaletteFilter) Apply

func (f *PaletteFilter) Apply(src, dst *ebiten.Image)

Apply remaps pixel colors through the palette based on luminance.

func (*PaletteFilter) Padding

func (f *PaletteFilter) Padding() int

Padding returns 0; palette remapping doesn't expand the image bounds.

func (*PaletteFilter) SetPalette

func (f *PaletteFilter) SetPalette(palette [256]types.Color)

SetPalette sets the palette colors and marks the texture for rebuild.

type PixelPerfectInlineFilter

type PixelPerfectInlineFilter struct {
	Color types.Color
	// contains filtered or unexported fields
}

PixelPerfectInlineFilter uses a Kage shader to recolor edge pixels that border transparent areas.

func NewPixelPerfectInlineFilter

func NewPixelPerfectInlineFilter(c types.Color) *PixelPerfectInlineFilter

NewPixelPerfectInlineFilter creates a pixel-perfect inline filter.

func (*PixelPerfectInlineFilter) Apply

func (f *PixelPerfectInlineFilter) Apply(src, dst *ebiten.Image)

Apply recolors edge pixels that border transparent areas via a Kage shader.

func (*PixelPerfectInlineFilter) Padding

func (f *PixelPerfectInlineFilter) Padding() int

Padding returns 0; inlines only affect existing opaque pixels.

type PixelPerfectOutlineFilter

type PixelPerfectOutlineFilter struct {
	Color types.Color
	// contains filtered or unexported fields
}

PixelPerfectOutlineFilter uses a Kage shader to draw a 1-pixel outline around non-transparent pixels by testing cardinal neighbors.

func NewPixelPerfectOutlineFilter

func NewPixelPerfectOutlineFilter(c types.Color) *PixelPerfectOutlineFilter

NewPixelPerfectOutlineFilter creates a pixel-perfect outline filter.

func (*PixelPerfectOutlineFilter) Apply

func (f *PixelPerfectOutlineFilter) Apply(src, dst *ebiten.Image)

Apply renders a 1-pixel outline via a Kage shader testing cardinal neighbors.

func (*PixelPerfectOutlineFilter) Padding

func (f *PixelPerfectOutlineFilter) Padding() int

Padding returns 1; the outline extends 1 pixel beyond the source bounds.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL