0.1.3 • Published 9 days ago

pex-shaders v0.1.3

Weekly downloads
-
License
MIT
Repository
github
Last release
9 days ago

pex-shaders

npm version stability-stable npm minzipped size dependencies types Conventional Commits styled with prettier linted with eslint license

Shader library and manipulation for PEX.

npm.io

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 and parser.build(ctx, src).
  • PBR material fragment shader specifies 3 named outputs for gl_FragData: outColor, outEmissiveColor and outNormal.
  • 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

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

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

ParamTypeDefault
extensionsobject{}

parser.formatDefines(defines) ⇒ string

Format an array of define keys

Kind: static method of parser

ParamTypeDefault
definesArray.<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

ParamTypeDefault
ctxctx
srcstring
definesArray.<string>[]
extensionsobject{}

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

ParamType
srcstring
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

ParamType
srcstring
optionsobject

parser.getFormattedError(error, options) ⇒ string

Get a formatted error pointing at the issue line

Kind: static method of parser

ParamType
errorError
optionsObject

License

MIT. See license file.

1.0.0-alpha.27

9 days ago

1.0.0-alpha.26

9 days ago

1.0.0-alpha.25

1 month ago

1.0.0-alpha.24

1 month ago

1.0.0-alpha.23

2 months ago

1.0.0-alpha.22

3 months ago

1.0.0-alpha.21

3 months ago

1.0.0-alpha.19

7 months ago

1.0.0-alpha.16

7 months ago

1.0.0-alpha.15

7 months ago

1.0.0-alpha.18

7 months ago

1.0.0-alpha.17

7 months ago

1.0.0-alpha.14

7 months ago

1.0.0-alpha.13

7 months ago

1.0.0-alpha.20

7 months ago

1.0.0-alpha.9

8 months ago

1.0.0-alpha.8

8 months ago

1.0.0-alpha.7

8 months ago

1.0.0-alpha.6

8 months ago

1.0.0-alpha.10

8 months ago

1.0.0-alpha.5

8 months ago

1.0.0-alpha.12

8 months ago

1.0.0-alpha.11

8 months ago

1.0.0-alpha.4

8 months ago

1.0.0-alpha.3

8 months ago

1.0.0-alpha.2

9 months ago

1.0.0-alpha.1

9 months ago

1.0.0-alpha.0

9 months ago

0.1.2

2 years ago

0.1.3

2 years ago

0.1.1

2 years ago