v0.4.0
What's Changed
- feat: visit API by @CodyJasonBennett in #26
This release follows up v0.3.0 with a visitor API to recurse AST. Useful for reflecting or modifying a shader program.
import { type Program, parse, visit, generate } from 'shaderkit'
// https://github.com/CodyJasonBennett/shaderkit#ast
const program: Program = parse(glsl)
// optionally reflect program here (e.g. collect all global uniforms)
const uniforms: string[] = []
visit(program, {
VariableDeclarator(node) {
if (node.qualifiers.includes('uniform')) {
uniforms.push(node.id.name)
}
},
})
// optionally modify program here (e.g. remove version header)
visit(program, {
PreprocessorStatement(node, ancestors) {
const parent = ancestors.at(-1)
if (node.name === 'version' && parent?.type === 'Program') {
parent.body.splice(parent.body.indexOf(node), 1)
}
},
})
// Compile back into GLSL
const output: string = generate(program, { target: 'GLSL' })Full Changelog: v0.3.1...v0.4.0