shader

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2026 License: GPL-3.0 Imports: 8 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var AvailableShaders = []ShaderInfo{
	{
		ID:          "xbr",
		Name:        "Pixel Smoothing (xBR)",
		Description: "Smooth edges while preserving pixel art details",
		Preprocess:  true,
		Context:     ContextGame,
	},
	{
		ID:          "ghosting",
		Name:        "Phosphor Persistence",
		Description: "Ghost trails from slow CRT phosphor decay",
		Preprocess:  true,
		Context:     ContextGame,
	},
	{
		ID:          "overscan",
		Name:        "Overscan Crop",
		Description: "Crop the simulated overscan border",
		Preprocess:  true,
		Context:     ContextGame,
	},
	{
		ID:          "crt",
		Name:        "CRT",
		Description: "Curved screen with RGB separation and vignette",
		Weight:      25,
		Context:     ContextAll,
	},
	{
		ID:          "scanlines",
		Name:        "Scanlines",
		Description: "Horizontal scanline effect",
		Weight:      400,
		Context:     ContextAll,
	},
	{
		ID:          "bloom",
		Name:        "Phosphor Glow",
		Description: "Bright pixels glow into neighbors like CRT phosphors",
		Weight:      550,
		Context:     ContextAll,
	},
	{
		ID:          "lcd",
		Name:        "LCD Grid",
		Description: "Visible pixel grid with RGB subpixels like handhelds",
		Weight:      300,
		Context:     ContextAll,
	},
	{
		ID:          "colorbleed",
		Name:        "Color Bleed",
		Description: "Horizontal color bleeding from composite video",
		Weight:      800,
		Context:     ContextAll,
	},
	{
		ID:          "dotmatrix",
		Name:        "Dot Matrix",
		Description: "Circular pixels like CRT phosphor dots",
		Weight:      350,
		Context:     ContextAll,
	},
	{
		ID:          "ntsc",
		Name:        "NTSC Artifacts",
		Description: "Color fringing at edges from NTSC encoding",
		Weight:      850,
		Context:     ContextAll,
	},
	{
		ID:          "rainbow",
		Name:        "NTSC Rainbow",
		Description: "Rainbow artifacts from dithering on composite video",
		Weight:      845,
		Context:     ContextAll,
	},
	{
		ID:          "gamma",
		Name:        "CRT Gamma",
		Description: "Non-linear brightness curve of CRT displays",
		Weight:      900,
		Context:     ContextAll,
	},
	{
		ID:          "halation",
		Name:        "Halation",
		Description: "Light bleeding behind CRT glass",
		Weight:      500,
		Context:     ContextAll,
	},
	{
		ID:          "rfnoise",
		Name:        "RF Noise",
		Description: "Subtle static grain from RF connection",
		Weight:      50,
		Context:     ContextAll,
	},
	{
		ID:          "rollingband",
		Name:        "Rolling Band",
		Description: "Scrolling dark band for bad reception look",
		Weight:      80,
		Context:     ContextAll,
	},
	{
		ID:          "vhs",
		Name:        "VHS Distortion",
		Description: "Wobble and tracking artifacts like VHS tape",
		Weight:      100,
		Context:     ContextAll,
	},
	{
		ID:          "interlace",
		Name:        "Interlace",
		Description: "Alternating scanline fields for 480i look",
		Weight:      380,
		Context:     ContextAll,
	},
	{
		ID:          "hsoft",
		Name:        "Horizontal Softness",
		Description: "Bandwidth-limited horizontal blur like analog video",
		Weight:      770,
		Context:     ContextAll,
	},
	{
		ID:          "vblur",
		Name:        "Vertical Blur",
		Description: "Electron beam softness causing scanline bleed",
		Weight:      760,
		Context:     ContextAll,
	},
	{
		ID:          "monochrome",
		Name:        "Monochrome",
		Description: "Black and white conversion",
		Weight:      700,
		Context:     ContextAll,
	},
	{
		ID:          "sepia",
		Name:        "Sepia",
		Description: "Warm brownish tint like old photographs",
		Weight:      650,
		Context:     ContextAll,
	},
}

AvailableShaders lists all shaders that can be enabled

Functions

func GetShaderWeight

func GetShaderWeight(id string) int

GetShaderWeight returns the weight for a shader ID (0 if unknown)

func HasXBR

func HasXBR(shaderIDs []string) bool

HasXBR returns true if "xbr" is in the shader list (exported for app.go)

func IsPreprocess

func IsPreprocess(id string) bool

IsPreprocess returns true if the shader ID is a preprocessing effect

Types

type EffectContext

type EffectContext int

EffectContext describes where an effect can be applied

const (
	ContextGame EffectContext = 1 << iota
	ContextUI
	ContextAll = ContextGame | ContextUI
)

func GetShaderContext

func GetShaderContext(id string) EffectContext

GetShaderContext returns the context for a shader ID (0 if unknown)

type Manager

type Manager struct {
	// contains filtered or unexported fields
}

Manager handles shader compilation, caching, and application

func NewManager

func NewManager(par float64) *Manager

NewManager creates a new shader manager with the given pixel aspect ratio (used by xBR scaling to compute display aspect ratio per frame).

func (*Manager) ApplyPreprocessEffects

func (m *Manager) ApplyPreprocessEffects(src *ebiten.Image, par float64, shaderIDs []string, screenW, screenH int) (*ebiten.Image, Picture)

ApplyPreprocessEffects runs the native-frame effects pipeline and returns a screen-sized image with the picture's placement in it. src must be the native-resolution game frame and par the pixel aspect ratio delivered with it. The frame is cropped (overscan), promoted to screen size (xBR when enabled, otherwise a plain scale), then ghosted. None of these are Kage shaders.

func (*Manager) ApplyShaders

func (m *Manager) ApplyShaders(dst, src *ebiten.Image, shaderIDs []string, picture Picture) bool

ApplyShaders draws src to dst with the specified shader chain applied. If shaderIDs is empty, src is drawn directly to dst. picture is the placement of the game picture within src, which the scanline shaders lay their lines over. Note: Preprocessing effects (xBR, ghosting) should be applied via ApplyPreprocessEffects before calling this function. Returns true if shaders were applied, false if direct draw was used.

func (*Manager) Frame

func (m *Manager) Frame() int

Frame returns the current frame count

func (*Manager) IncrementFrame

func (m *Manager) IncrementFrame()

IncrementFrame advances the frame counter for animated shaders

func (*Manager) LoadShader

func (m *Manager) LoadShader(id string) error

LoadShader compiles and caches a shader by ID

func (*Manager) PreloadShaders

func (m *Manager) PreloadShaders(ids []string)

PreloadShaders loads all shaders in the given list

func (*Manager) ReleaseGameBuffers added in v0.7.0

func (m *Manager) ReleaseGameBuffers()

ReleaseGameBuffers frees the buffers only gameplay uses: the ghosting and scale buffers and the xBR buffers. The shader chain buffers are kept since the UI uses them too. Call when gameplay ends.

func (*Manager) ResetBuffers

func (m *Manager) ResetBuffers()

ResetBuffers clears all effect buffers. Call when switching games.

func (*Manager) SetAspectRatioMode

func (m *Manager) SetAspectRatioMode(mode string)

SetAspectRatioMode sets the aspect ratio mode used for scaling, forwarding it to the xBR scaler.

type Picture added in v0.6.0

type Picture struct {
	Left   float64
	Top    float64
	Width  float64
	Height float64
}

Picture is the placement of the game picture within a screen-sized image, in pixels, with any letterbox or pillarbox bars outside it. Shaders that draw a line structure place it over the picture's rows.

func FullPicture added in v0.6.0

func FullPicture(screenW, screenH int) Picture

FullPicture is the placement of a picture covering the whole of a screen-sized image of the size.

func (Picture) Rect added in v0.7.0

func (p Picture) Rect() image.Rectangle

Rect returns the whole pixels the picture covers, each edge rounded to the nearest pixel boundary.

type ShaderInfo

type ShaderInfo struct {
	ID          string        // Unique identifier used in config
	Name        string        // Display name for UI
	Description string        // Brief description of the effect
	Weight      int           // Higher weight = applied earlier in chain
	Preprocess  bool          // True for preprocessing effects (xBR, ghosting)
	Context     EffectContext // Where this effect can be applied
}

ShaderInfo describes an available shader effect

type XBRScaler

type XBRScaler struct {
	// contains filtered or unexported fields
}

XBRScaler handles xBR pixel art scaling with cascaded 2x passes. Supports 2x (1 pass), 4x (2 passes), and 8x (3 passes) scaling, with fewer passes when a pass's output would exceed the maximum image size. Buffers are pooled and reused to avoid per-frame GPU allocations, and only the buffers of the passes run are kept.

func NewXBRScaler

func NewXBRScaler(par float64) *XBRScaler

NewXBRScaler creates a new xBR scaler instance with the given pixel aspect ratio.

func (*XBRScaler) Apply

func (x *XBRScaler) Apply(src *ebiten.Image, par float64, screenW, screenH int) *ebiten.Image

Apply runs xBR scaling on the source and returns a screen-sized image. Automatically selects 2x, 4x, or 8x scaling based on screen size, then drops passes whose output would exceed the maximum image size; with no pass left the source is scaled to the screen directly. par is the pixel aspect ratio delivered with this frame, used for the final scale.

func (*XBRScaler) Picture added in v0.6.0

func (x *XBRScaler) Picture() Picture

Picture returns the placement of the picture Apply last drew.

func (*XBRScaler) Release added in v0.7.0

func (x *XBRScaler) Release()

Release frees every buffer. Call when gameplay ends; the next Apply creates the buffers again.

func (*XBRScaler) SetAspectRatioMode

func (x *XBRScaler) SetAspectRatioMode(mode string)

SetAspectRatioMode sets the aspect ratio scaling mode ("dar", "4:3", "1:1", "stretch").

Jump to

Keyboard shortcuts

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