pex-shaders v0.1.3
pex-shaders
Shader library and manipulation for PEX.
Installation
npm install pex-shaders
Usage
import { pipeline, parser } from "pex-shaders";
import createContext from "pex-context";
const ctx = createContext();
const defines = [
"USE_BASE_COLOR_MAP",
// ...
];
const program = {
vert: parser.build(ctx, pipeline.material.vert, defines),
frag: parser.replaceStrings(
parser.build(ctx, pipeline.material.frag, defines),
{ directionalLights: 3 }
),
};
API
- All GLSL shaders are by default written using GLSL 1. They also provide support for GLSL 3 where possible using the
__VERSION__
standard macro,#define
for built-ins keywords andparser.build(ctx, src)
. - PBR material fragment shader specifies 3 named outputs for
gl_FragData
:outColor
,outEmissiveColor
andoutNormal
. - Defines and extensions can also be prepended with
parser.build(ctx, src, defines, extensions)
- Pipeline shaders have hooks for easy string replace:
#define HOOK_VERT_DECLARATIONS_END
#define HOOK_VERT_END
#define HOOK_FRAG_DECLARATIONS_END
#define HOOK_FRAG_END
- PBR material has additional hooks:
#define HOOK_VERT_BEFORE_TRANSFORM
#define HOOK_FRAG_BEFORE_TEXTURES
#define HOOK_FRAG_BEFORE_LIGHTING
#define HOOK_FRAG_AFTER_LIGHTING
Modules
pex-shaders
- pex-shaders
- .chunks : object
- .pipeline : object
- .postProcessing : object
- .reflectionProbe : object
- .skybox : object
- .parser : parser
pex-shaders.chunks : object
Various shader chunks to be inserted in main shaders
Kind: static property of pex-shaders
pex-shaders.pipeline : object
Main shaders
Kind: static property of pex-shaders
pex-shaders.postProcessing : object
Post-processing shaders that operate on fullscreen
Kind: static property of pex-shaders
pex-shaders.reflectionProbe : object
Reflection probes specific shaders
Kind: static property of pex-shaders
pex-shaders.skybox : object
Skybox specific shaders
Kind: static property of pex-shaders
pex-shaders.parser : parser
Shader string manipulation helpers
Kind: static property of pex-shaders
parser
- parser
- .GLSL3
- .formatExtensions([extensions]) ⇒ string
- .formatDefines([defines]) ⇒ string
- .build(ctx, src, [defines], [extensions]) ⇒ string
- .patchES300(src, stage) ⇒ string
- .replaceStrings(src, options) ⇒ string
- .getFormattedError(error, options) ⇒ string
parser.GLSL3
GLSL 3 preprocessor version string
Kind: static constant of parser
parser.formatExtensions(extensions) ⇒ string
Format an object of extension names as key and extension behaviosr (enable/require/warn/disable) as value
Kind: static method of parser
Param | Type | Default |
---|---|---|
extensions | object | {} |
parser.formatDefines(defines) ⇒ string
Format an array of define keys
Kind: static method of parser
Param | Type | Default |
---|---|---|
defines | Array.<string> | [] |
parser.build(ctx, src, defines, extensions) ⇒ string
Add version string and format a list of defines for a shader source
Kind: static method of parser
Param | Type | Default |
---|---|---|
ctx | ctx | |
src | string | |
defines | Array.<string> | [] |
extensions | object | {} |
parser.patchES300(src, stage) ⇒ string
Monkey patch a shader string for ES300 by replacing builtin keywords and un-necessary extensions, and adding the version preprocessor string
Kind: static method of parser
Param | Type |
---|---|
src | string |
stage | "vertex" | "fragment" |
parser.replaceStrings(src, options) ⇒ string
Unroll loops (looped preceded by "#pragma unroll_loop") for lights and replace their constant iterators
Kind: static method of parser
Param | Type |
---|---|
src | string |
options | object |
parser.getFormattedError(error, options) ⇒ string
Get a formatted error pointing at the issue line
Kind: static method of parser
Param | Type |
---|---|
error | Error |
options | Object |
License
MIT. See license file.
9 days ago
9 days ago
1 month ago
1 month ago
2 months ago
3 months ago
3 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
9 months ago
9 months ago
9 months ago
2 years ago
2 years ago
2 years ago