shader

package
v0.3.3 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2026 License: Apache-2.0, Apache-2.0, MIT 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 platform's GPU API.

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, as MyGo (github.com/egoist/mygo, v0.6.3, MIT License) forked it to compile fragment shaders as libraries. Files that came from Ebitengine keep its copyright notice and say where MyGo changed them. NSGo's bridge (bridge.go) declares only the view's size and scale: shaders read no images yet.

Index

Constants

View Source
const (
	RectSizeUniform   = "__rectSize"
	ScaleUniform      = "__scale"
	ImageSizesUniform = "__imageSizes"
)

The uniform variables the bridge declares, which platforms set, before the shader's own: the size of the view the shader fills in points, and the pixels a point.

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 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 shader's view, in its pixels from the top left corner, and pos the same point in points. It may take dst alone, or nothing.

View Source
const MaxImages = 4

MaxImages is how many images a shader reads at most: image0 to image3.

Variables

This section is empty.

Functions

func BridgeLanes

func BridgeLanes(p *shaderir.Program) int

BridgeLanes is how many lanes the bridge's uniforms of p take, before the shader's own: the view's size and scale, then each image's size in pixels.

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 an NSGo 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.

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.

Directories

Path Synopsis
Package wgsl compiles the shaders TSX apps write in WGSL, as NSH's are, into package shaderir's programs, which every backend draws as it draws a Kage program (package shader).
Package wgsl compiles the shaders TSX apps write in WGSL, as NSH's are, into package shaderir's programs, which every backend draws as it draws a Kage program (package shader).

Jump to

Keyboard shortcuts

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