Shader library and manipulation for PEX.
npm install pex-shadersimport { pipeline, parser } from "pex-shaders";
import createContext from "pex-context";
const ctx = createContext();
const defines = [
"USE_BASE_COLOR_TEXTURE",
// ...
];
const program = {
vert: parser.build(ctx, pipeline.material.vert, defines),
frag: parser.replaceStrings(
parser.build(ctx, pipeline.material.frag, defines),
{ directionalLights: 3 }
),
};- All GLSL shaders are by default written using GLSL 1. They also provide support for GLSL 3 where possible using the
__VERSION__standard macro,#definefor built-ins keywords andparser.build(ctx, src). - PBR material fragment shader specifies 3 named outputs for
gl_FragData:outColor,outEmissiveColorandoutNormal. - 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
- pex-shaders
- .chunks :
chunks - .pipeline :
pipeline - .postProcessing :
postProcessing - .reflectionProbe :
reflectionProbe - .skybox :
skybox - .parser :
parser - .toneMap :
object
- .chunks :
pex-shaders.chunks : chunks
Various shader chunks to be inserted in main shaders
Kind: static property of pex-shaders
pex-shaders.pipeline : pipeline
Main shaders
Kind: static property of pex-shaders
pex-shaders.postProcessing : postProcessing
Post-processing shaders that operate on fullscreen
Kind: static property of pex-shaders
pex-shaders.reflectionProbe : reflectionProbe
Reflection probes specific shaders
Kind: static property of pex-shaders
pex-shaders.skybox : skybox
Skybox specific shaders
Kind: static property of pex-shaders
pex-shaders.parser : parser
Shader string manipulation helpers
Kind: static property of pex-shaders
Re-export tone mapping functions
Kind: static property of pex-shaders
See: https://github.com/dmnsgn/glsl-tone-map
- 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
GLSL 3 preprocessor version string
Kind: static constant of parser
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 |
{} |
Format an array of define keys
Kind: static method of parser
| Param | Type | Default |
|---|---|---|
| [defines] | Array.<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 |
{} |
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" |
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 |
Get a formatted error pointing at the issue line
Kind: static method of parser
| Param | Type |
|---|---|
| error | Error |
| options | Object |
- chunks
- .output :
object - .math :
object - .encodeDecode :
string - .luma :
string - .luminance :
string - .average :
string - .lightAmbient :
string - .lightDirectional :
string - .lightPoint :
string - .lightSpot :
string - .lightArea :
string - .shadowing :
string - .pcf :
object - .pcss :
object - .brdf :
string - .direct :
string - .indirect :
string - .envMapEquirect :
string - .octMap :
string - .octMapUvToDir :
string - .irradiance :
string - .textureCoordinates :
string - .baseColor :
string - .emissiveColor :
string - .normal :
string - .normalPerturb :
string - .metallicRoughness :
string - .specular :
string - .specularGlossiness :
string - .clearCoat :
string - .sheenColor :
string - .transmission :
string - .alpha :
string - .ambientOcclusion :
string - .depthRead :
string - .depthPosition :
string - .depthUnpack :
string - .depthPack :
string - .fog :
string - .fxaa :
string - .filmGrain :
string - .lut :
string - .vignette :
string - .colorCorrection :
string - .filmGrain :
string - .fog :
string - .fxaa :
string - .noise :
object
- .output :
Kind: static property of chunks
Kind: static property of chunks
Kind: static property of chunks
Kind: static property of chunks
Kind: static property of chunks
Kind: static property of chunks
Kind: static property of chunks
Kind: static property of chunks
Kind: static property of chunks
Kind: static property of chunks
Kind: static property of chunks
Kind: static property of chunks
Kind: static property of chunks
Kind: static property of chunks
Kind: static property of chunks
Kind: static property of chunks
Kind: static property of chunks
Kind: static property of chunks
Kind: static property of chunks
Kind: static property of chunks
Kind: static property of chunks
Kind: static property of chunks
Kind: static property of chunks
Kind: static property of chunks
Kind: static property of chunks
Kind: static property of chunks
Kind: static property of chunks
Kind: static property of chunks
Kind: static property of chunks
Kind: static property of chunks
Kind: static property of chunks
Kind: static property of chunks
Kind: static property of chunks
Kind: static property of chunks
Kind: static property of chunks
Kind: static property of chunks
Kind: static property of chunks
Kind: static property of chunks
Kind: static property of chunks
Kind: static property of chunks
Kind: static property of chunks
Kind: static property of chunks
Kind: static property of chunks
Color Correction
https://github.com/CesiumGS/cesium/blob/master/Source/Shaders/Builtin/Functions
Kind: static property of chunks
Film Grain
Reference Implementations:
- https://devlog-martinsh.blogspot.com/2013/05/image-imperfections-and-film-grain-post.html
- https://www.shadertoy.com/view/4sSXDW
Kind: static property of chunks
Fog
Adapted from from Iñigo Quilez article: https://iquilezles.org/articles/fog/
Kind: static property of chunks
FXAA
Paper:
Reference Implementations:
- https://blog.simonrodriguez.fr/articles/2016/07/implementing_fxaa.html
- https://gist.github.com/kosua20/0c506b81b3812ac900048059d2383126
Updates: Damien Seguin (2023-10)
Kind: static property of chunks
Reference Implementation: https://github.com/stegu/webgl-noise
Copyright (C) 2011 by Ashima Arts (Simplex noise) Copyright (C) 2011-2016 by Stefan Gustavson (Classic noise and others)
Kind: static constant of chunks
- pipeline
- .blit :
object - .depthPass :
object - .depthPrePass :
object- .frag :
string
- .frag :
- .standard :
object - .basic :
object - .line :
object - .overlay :
object - .helper :
object - .error :
object
- .blit :
Kind: static constant of pipeline
Kind: static property of blit
Kind: static property of blit
Kind: static constant of pipeline
- .depthPass :
object
Kind: static property of depthPass
Kind: static property of depthPass
Kind: static constant of pipeline
Kind: static property of depthPrePass
Kind: static constant of pipeline
Kind: static property of standard
Kind: static property of standard
Kind: static constant of pipeline
Kind: static property of basic
Kind: static property of basic
Kind: static constant of pipeline
Kind: static property of line
Kind: static property of line
Kind: static constant of pipeline
Kind: static property of overlay
Kind: static property of overlay
Kind: static constant of pipeline
Kind: static property of helper
Kind: static property of helper
Kind: static constant of pipeline
Kind: static property of error
Kind: static property of error
- postProcessing
- .bilateralBlur :
object- .frag :
string
- .frag :
- .dof :
object- .frag :
string
- .frag :
- .downsample :
object- .frag :
string
- .frag :
- .postProcessing :
object - .sao :
object- .frag :
string
- .frag :
- .gtao :
object- .frag :
string
- .frag :
- .ssaoMix :
object- .frag :
string
- .frag :
- .threshold :
object- .frag :
string
- .frag :
- .upsample :
object- .frag :
string
- .frag :
- .bilateralBlur :
Kind: static constant of postProcessing
Kind: static property of bilateralBlur
Kind: static constant of postProcessing
DoF (Depth of Field)
Based on:
- "Bokeh depth of field in a single pass", Dennis Gustafsson: https://blog.voxagon.se/2018/05/04/bokeh-depth-of-field-in-single-pass.html
- "GLSL depth of field with bokeh v2.4", Martins Upitis: https://devlog-martinsh.blogspot.com/2011/12/glsl-depth-of-field-with-bokeh-v24.html
Kind: static property of dof
Kind: static constant of postProcessing
Downsample
Reference Implementation: https://github.com/keijiro/KinoBloom
Kind: static property of downsample
Kind: static constant of postProcessing
- .postProcessing :
object
Kind: static property of postProcessing
Kind: static property of postProcessing
Kind: static constant of postProcessing
SAO (Scalable Ambient Obscurance)
Paper: https://research.nvidia.com/sites/default/files/pubs/2012-06_Scalable-Ambient-Obscurance/McGuire12SAO.pdf (https://casual-effects.com/research/McGuire2012SAO/index.html)
Reference Implementation: https://gist.github.com/transitive-bullshit/6770311
Updates: Marcin Ignac (2017-05-08) and Damien Seguin (2023-10)
Kind: static property of sao
Kind: static constant of postProcessing
GTAO (Ground Truth)
Reference Implementation: https://github.com/GameTechDev/XeGTAO/blob/master/Source/Rendering/Shaders/XeGTAO.hlsli
Updates: Damien Seguin (2023-10)
Kind: static property of gtao
Kind: static constant of postProcessing
SSAO mix
Kind: static property of ssaoMix
Kind: static constant of postProcessing
Kind: static property of threshold
Kind: static constant of postProcessing
Upsample
Reference Implementation: https://github.com/keijiro/KinoBloom
Kind: static property of upsample
- reflectionProbe
- .blitToOctMapAtlas :
object- .frag :
string
- .frag :
- .convolveOctMapAtlasToOctMap :
object- .frag :
string
- .frag :
- .cubemapToOctMap :
object- .frag :
string
- .frag :
- .downsampleFromOctMapAtlas :
object- .frag :
string
- .frag :
- .prefilterFromOctMapAtlas :
object- .frag :
string
- .frag :
- .blitToOctMapAtlas :
Kind: static constant of reflectionProbe
Kind: static property of blitToOctMapAtlas
Kind: static constant of reflectionProbe
Kind: static property of convolveOctMapAtlasToOctMap
Kind: static constant of reflectionProbe
Kind: static property of cubemapToOctMap
Kind: static constant of reflectionProbe
Kind: static property of downsampleFromOctMapAtlas
Kind: static constant of reflectionProbe
Kind: static property of prefilterFromOctMapAtlas
Kind: static constant of skybox
Kind: static property of skybox
Skybox
Based on http://gamedev.stackexchange.com/questions/60313/implementing-a-skybox-with-glsl-version-330
Kind: static property of skybox
Kind: static constant of skybox
- .skyEnvMap :
object
Sky
Based on "A Practical Analytic Model for Daylight" aka The Preetham Model, the de facto standard analytic skydome model
Paper: https://www.researchgate.net/publication/220720443_A_Practical_Analytic_Model_for_Daylight
Reference Implementation:
- First implemented by Simon Wallner http://www.simonwallner.at/projects/atmospheric-scattering
- Improved by Martins Upitis http://blenderartists.org/forum/showthread.php?245954-preethams-sky-impementation-HDR
- Three.js integration by zz85 http://twitter.com/blurspline
Updates: Marcin Ignac http://twitter.com/marcinignac (2015-09) and Damien Seguin (2023-10)
Kind: static property of skyEnvMap
Kind: static property of skyEnvMap
MIT. See license file.
