wgsl

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2026 License: Apache-2.0, Apache-2.0, MIT Imports: 10 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 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).

An app writes fn shade(uv: vec2f) -> vec4f, the straight sRGB color of the point uv of the view's box (0 to 1 from its top left corner), with helpers and consts of its own. It reads nsh.size (the box in points), nsh.time (seconds since the shader appeared), nsh.scale (pixels a point), nsh.progress (an effect's progress or a transition's, 0 to 1) and nsh.overflow (the points the shader draws beyond each side of its box), its own values through uniforms when it declares struct Uniforms, and pictures of other views with sample_content, sample_backdrop, sample_from and sample_to.

The program's uniforms are the bridge's (package shader: the surface's size in points, its scale, and the pictures' sizes when it reads any), then __nsh, a vec3 of the time, the progress and the overflow (BuiltinLanes), then the members of struct Uniforms in turn. Its textures are the pictures, content, backdrop, from and to, up to the last it reads. The surface a platform draws covers the box and the overflow on each side.

Index

Constants

View Source
const (
	MaxSourceBytes  = 64 << 10
	MaxUniformBytes = 4096
)

Limits on what a shader may be, as NSH's.

View Source
const BuiltinLanes = 3

BuiltinLanes is how many lanes __nsh takes after the bridge's: the time, the progress and the overflow.

View Source
const Crossfade = `fn shade(uv: vec2f) -> vec4f {
	return mix(sample_from(uv), sample_to(uv), nsh.progress);
}
`

Crossfade is the transitions' default program: from sample_from to sample_to as nsh.progress goes from 0 to 1.

Variables

This section is empty.

Functions

This section is empty.

Types

type Error

type Error struct {
	Line, Column int
	Message      string
	// contains filtered or unexported fields
}

Error is why a shader did not compile, at a line and a column (in bytes) from 1 of the app's source, or 0 where it has no place there.

func (*Error) Error

func (e *Error) Error() string

type Inputs

type Inputs uint8

Inputs is a set of pictures.

const (
	Content Inputs = 1 << iota
	Backdrop
	From
	To
)

The pictures a program reads, a bit each and in the order of its textures.

type Program

type Program struct {
	IR *shaderir.Program
	// Uniforms are struct Uniforms' members, in their order.
	Uniforms []Uniform
	// Animated is whether shade reads nsh.time, so the shader draws every
	// frame.
	Animated bool
	// Inputs are the pictures shade reads, through the functions it
	// calls.
	Inputs Inputs
}

Program is a compiled shader.

func Compile

func Compile(src string) (*Program, error)

Compile checks src and writes it as a program.

type Uniform

type Uniform struct {
	Name string
	// Type is its WGSL type (vec4<f32>).
	Type string
	// Lanes is how many lanes it takes; Vec3 is whether it is a vec3f,
	// which a color fills without its alpha.
	Lanes int
	Vec3  bool
}

Uniform is a member of struct Uniforms.

Jump to

Keyboard shortcuts

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