shader

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2026 License: GPL-3.0 Imports: 6 Imported by: 0

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:          "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 added in v0.2.0

func IsPreprocess(id string) bool

IsPreprocess returns true if the shader ID is a preprocessing effect

Types

type EffectContext added in v0.2.0

type EffectContext int

EffectContext describes where an effect can be applied

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

func GetShaderContext added in v0.2.0

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, shaderIDs []string, screenW, screenH int) *ebiten.Image

ApplyPreprocessEffects applies xBR and ghosting effects (not Kage shaders). If xBR is in shaderIDs, src should be native resolution and will be scaled to screen size. Otherwise, src should already be screen resolution. Returns the processed image (screen-sized).

func (*Manager) ApplyShaders

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

ApplyShaders draws src to dst with the specified shader chain applied. If shaderIDs is empty, src is drawn directly to dst. sourceHeight is the native vertical resolution of the emulated system (used by scanline shader to align with original pixel rows). 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) ResetBuffers

func (m *Manager) ResetBuffers()

ResetBuffers clears all effect buffers. Call when switching games.

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. Buffers are pooled and reused to avoid per-frame GPU allocations.

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, 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.

Jump to

Keyboard shortcuts

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