Package github.com/matjam/bunyip/gfx/shaders
gfx/shaders
Package shaders holds the gfx package's WGSL sources and committed SPIR-V, and the preludes that game shaders are compiled against. Compose builds WGSL without compiling; Compiler and bunyip-shader use the native Go compiler. Mesh bundles contain regular and order-independent fragment programs and optionally static/skinned vertex programs for lit and shadow passes. Embedded byte slices are shared and must not be modified.
Index
- Variables
func Bundle(stages map[Stage][]byte) []bytefunc Compose(kind Kind, stage Stage, source string) (string, int, error)func HasVertexHook(source string) boolfunc Unbundle(data []byte) (map[Stage][]byte, error)- type Compiler
- type Kind
- type Stage
Variables
var (
//go:embed sprite.vert.spv
SpriteVert []byte
//go:embed sprite.frag.spv
SpriteFrag []byte
//go:embed colormatrix.frag.spv
MatrixFrag []byte
//go:embed lit.frag.spv
LitFrag []byte
//go:embed sdf.frag.spv
SDFFrag []byte
//go:embed text_outline.frag.spv
TextOutlineFrag []byte
)
var (
//go:embed sky.frag.spv
SkyFrag []byte
//go:embed skyparam.frag.spv
SkyParamFrag []byte
//go:embed line.vert.spv
LineVert []byte
//go:embed line.frag.spv
LineFrag []byte
//go:embed particle.vert.spv
ParticleVert []byte
//go:embed particle.frag.spv
ParticleFrag []byte
//go:embed particle3d.vert.spv
Particle3DVert []byte
//go:embed particle3d.frag.spv
Particle3DFrag []byte
//go:embed outline.vert.spv
OutlineVert []byte
//go:embed solid.frag.spv
SolidFrag []byte
//go:embed decal.vert.spv
DecalVert []byte
//go:embed decal.frag.spv
DecalFrag []byte
//go:embed pbr.frag.spv
PBRFrag []byte
//go:embed pbr_oit.frag.spv
PBROITFrag []byte
// TerrainFrag blends four tiling layers by a splat map, for gfx.Terrain.
//go:embed terrain.frag.spv
TerrainFrag []byte
//go:embed pbr.vert.spv
PBRVert []byte
//go:embed pbr_skin.vert.spv
PBRSkinVert []byte
//go:embed shadow.vert.spv
ShadowVert []byte
//go:embed shadow_skin.vert.spv
ShadowSkinVert []byte
//go:embed shadow.frag.spv
ShadowFrag []byte
//go:embed post.vert.spv
PostVert []byte
//go:embed post.frag.spv
PostFrag []byte
//go:embed bright.frag.spv
BrightFrag []byte
//go:embed blur.frag.spv
BlurFrag []byte
//go:embed fxaa.frag.spv
FXAAFrag []byte
//go:embed ssao.frag.spv
SSAOFrag []byte
//go:embed ssr.frag.spv
SSRFrag []byte
//go:embed ssrapply.frag.spv
SSRApplyFrag []byte
//go:embed ssrblend.frag.spv
SSRBlendFrag []byte
//go:embed depthhalf.frag.spv
DepthHalfFrag []byte
//go:embed aoblur.frag.spv
AOBlurFrag []byte
//go:embed velocity.vert.spv
VelocityVert []byte
//go:embed velocity_skin.vert.spv
VelocitySkinVert []byte
//go:embed velocity.frag.spv
VelocityFrag []byte
//go:embed taa.frag.spv
TAAFrag []byte
//go:embed dof.frag.spv
DOFFrag []byte
//go:embed dofcombine.frag.spv
DOFCombineFrag []byte
//go:embed motionblur.frag.spv
MotionBlurFrag []byte
//go:embed godrays.frag.spv
GodRaysFrag []byte
//go:embed oit.frag.spv
OITFrag []byte
)
Functions
Bundle source
func Bundle(stages map[Stage][]byte) []byte
Bundle copies stage programs into a new blob in stage-number order. Supply only defined Stage values and include StageFrag for Unbundle. It does not validate SPIR-V program bytes.
Compose source
func Compose(kind Kind, stage Stage, source string) (string, int, error)
Compose adds Bunyip's WGSL declarations and entry point around game source. Kind defaults to Sprite. The second result is the number of prefix lines before the source body, useful when reading compiler diagnostics.
HasVertexHook source
func HasVertexHook(source string) bool
HasVertexHook reports whether the source declares the optional vertex hook. Comments are ignored, including nested block comments.
Unbundle source
func Unbundle(data []byte) (map[Stage][]byte, error)
Unbundle splits a bundle into its stages; plain SPIR-V comes back as the fragment stage alone. Returned slices alias data. It validates bundle record bounds and stage numbers, but not the SPIR-V bytes themselves; NewMeshShader validates those when loading the programs.
Types
type Compiler source
type Compiler struct{}
Compiler translates WGSL to SPIR-V in Go, without external tools or cgo. Its zero value is ready to use and may be used concurrently. Compilation is synchronous. Context cancellation is checked between compiler phases; it cannot interrupt a phase already executing.
Compile source
func (c Compiler) Compile(ctx context.Context, kind Kind, source string) ([]byte, error)
Compile composes game source with Bunyip's bindings and entry points. Kind defaults to Sprite. Sprite returns fragment SPIR-V; Mesh returns a bundle containing both fragment variants and, when source defines vertex, all four vertex variants. Returned bytes can be stored and loaded later.
CompileRaw source
func (Compiler) CompileRaw(ctx context.Context, source string) ([]byte, error)
CompileRaw compiles a complete WGSL module with explicit entry points and bindings. It does not add Bunyip helpers. Output uses SPIR-V 1.3 and Vulkan coordinates without an automatic Y flip. The caller must match the renderer's pipeline and descriptor interface. This method creates no GPU resources. Module-level private initializers are currently rejected because Naga can drop them; use constants or assign in the entry point or hook instead.
CompileStage source
func (c Compiler) CompileStage(ctx context.Context, kind Kind, stage Stage, source string) ([]byte, error)
CompileStage composes and compiles one Bunyip shader stage. Use Compile for complete game shaders. Diagnostics refer to the composed source; errors include the prefix line count for locating the original body.
type Stage source
type Stage uint32
Stage is one program of a mesh shader.
const (
StageFrag Stage = iota // the lit fragment program
StageVert // static meshes, lit pass
StageSkinVert // skinned meshes, lit pass
StageShadowVert // static meshes, shadow pass
StageShadowSkinVert // skinned meshes, shadow pass
StageOITFrag // the fragment program of the order-independent transparency pass
)
Source files
compiler.go compiler_backend.go compiler_test.go mesh_compose.go mesh_wgsl_test.go private_initializer_test.go shaders.go sprite_compose.go zero_initializer_test.go