shader

package
v0.1.13 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2026 License: MIT, Apache-2.0 Imports: 12 Imported by: 0 modules, 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

Overview

Package shader compiles shaders written in Go's syntax into the intermediate representation of package shaderir, which its backends translate for each GPU renderer.

It is Ebitengine's Kage compiler (github.com/hajimehoshi/ebiten, internal/shader and internal/shaderir at commit 16f18b0), under the Apache License 2.0 in LICENSE, forked to compile Golet's shaders: files that came from Ebitengine keep its copyright notice, and say so where Golet changed them.

Index

Constants

View Source
const (
	ImageSizesUniform = "__imageSizes"
	RectSizeUniform   = "__rectSize"
	ScaleUniform      = "__scale"
	LayerInsetUniform = "__layerInset"
	// The backdrop of a shader reading it (BackdropImage): the rows of the
	// map from its positions to the frame's pixels, and where its texels
	// start in the frame, with how many pixels each covers across.
	BackdropRow0Uniform = "__backdropRow0"
	BackdropRow1Uniform = "__backdropRow1"
	BackdropAreaUniform = "__backdropArea"
)

The uniform variables the bridge declares, which renderers set, before the shader's own: the images' sizes in pixels, the size of the rectangle the shader fills in DIPs, the pixels a DIP, and, for an effect's shader, where the corner of the element's box lies in its content (LayerImage), in its pixels.

View Source
const (
	// InternalRegionBegin is the line that begins the internal region.
	InternalRegionBegin = internalRegionDirective + " begin"

	// InternalRegionEnd is the line that ends the internal region.
	InternalRegionEnd = internalRegionDirective + " end"
)
View Source
const BackdropImage = MaxImages - 2

BackdropImage is the image a shader reads its backdrop from, through backdropAt and backdropSample: what the window drew behind it, which the renderers capture and blur as for effects reading their backdrop.

View Source
const Entry = "Fragment"

Entry is the name of a shader's entry point, which returns the color of a pixel, premultiplied:

func Fragment(dst vec4, pos vec2) vec4

dst is the pixel's center in the target, in its pixels from its top left corner, and pos the same point in DIPs from the top left corner of the rectangle the shader fills. It may take dst alone, or nothing.

View Source
const LayerImage = MaxImages - 1

LayerImage is the image an effect's shader reads its element's content from, through layerAt and layerSample: the last, which its own images leave free.

View Source
const MaxImages = 4

MaxImages is how many images a shader reads, image0 to image3.

Variables

This section is empty.

Functions

func Compile

func Compile(src []byte, vertexEntry, fragmentEntry string, textureCount int) (*shaderir.Program, error)

Compile compiles a Kage source into an intermediate representation.

A uniform variable whose name starts with __ can be declared only in the internal region, which is the lines between InternalRegionBegin and InternalRegionEnd. A source can have at most one internal region.

func CompileFragment

func CompileFragment(src []byte) (*shaderir.Program, error)

CompileFragment compiles a Golet shader: Go's syntax in package main, with uniform variables (exported, package level) that the app sets and the entry point Fragment, which may call functions of its own and read images through the functions image0At to image3At, image0Sample to image3Sample and image0Size to image3Size.

Types

type ParseError

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

func (*ParseError) Error

func (p *ParseError) Error() string

func (*ParseError) Positions

func (p *ParseError) Positions() []token.Position

Positions returns the source positions of the errors, in the same order as ParseError.Error reports them.

Jump to

Keyboard shortcuts

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