@thi.ng/webgl 5.0.14 → 6.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +112 -213
- package/README.md +15 -5
- package/api/buffers.d.ts +1 -1
- package/api/canvas.d.ts +1 -1
- package/api/material.d.ts +1 -1
- package/api/model.d.ts +3 -3
- package/api/multipass.d.ts +4 -4
- package/api/shader.d.ts +12 -6
- package/api/texture.d.ts +1 -1
- package/buffer.d.ts +3 -3
- package/buffer.js +4 -4
- package/canvas.d.ts +2 -2
- package/canvas.js +6 -3
- package/checks.d.ts +1 -1
- package/checks.js +1 -1
- package/draw.d.ts +1 -1
- package/draw.js +4 -4
- package/error.d.ts +11 -3
- package/error.js +2 -5
- package/fbo.d.ts +1 -1
- package/fbo.js +5 -5
- package/geo/cube.d.ts +1 -1
- package/geo/cube.js +2 -2
- package/geo/quad.d.ts +1 -1
- package/geo/quad.js +14 -11
- package/index.d.ts +32 -32
- package/index.js +32 -32
- package/{api/logger.d.ts → logger.d.ts} +1 -1
- package/{api/logger.js → logger.js} +1 -1
- package/material.d.ts +2 -2
- package/matrices.d.ts +2 -2
- package/matrices.js +5 -2
- package/multipass.d.ts +1 -1
- package/multipass.js +33 -15
- package/package.json +151 -40
- package/rbo.d.ts +1 -1
- package/rbo.js +1 -1
- package/readpixels.d.ts +1 -1
- package/readpixels.js +1 -1
- package/shader.d.ts +6 -6
- package/shader.js +33 -23
- package/shaders/lambert.d.ts +3 -3
- package/shaders/lambert.js +43 -11
- package/shaders/phong.d.ts +3 -3
- package/shaders/phong.js +38 -10
- package/shaders/pipeline.d.ts +1 -1
- package/shaders/pipeline.js +5 -1
- package/syntax.d.ts +2 -2
- package/syntax.js +2 -2
- package/texture.d.ts +1 -1
- package/texture.js +10 -6
- package/textures/checkerboard.js +9 -2
- package/textures/stripes.js +8 -2
- package/uniforms.d.ts +2 -2
- package/uniforms.js +2 -2
- package/utils.d.ts +4 -4
- package/utils.js +1 -1
- package/lib/index.js +0 -1820
- package/lib/index.js.map +0 -1
- package/lib/index.umd.js +0 -1
- package/lib/index.umd.js.map +0 -1
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thi.ng/webgl",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "6.0.4",
|
|
4
4
|
"description": "WebGL & GLSL abstraction layer",
|
|
5
|
+
"type": "module",
|
|
5
6
|
"module": "./index.js",
|
|
6
|
-
"main": "./lib/index.js",
|
|
7
|
-
"umd:main": "./lib/index.umd.js",
|
|
8
7
|
"typings": "./index.d.ts",
|
|
8
|
+
"sideEffects": false,
|
|
9
9
|
"repository": {
|
|
10
10
|
"type": "git",
|
|
11
11
|
"url": "https://github.com/thi-ng/umbrella.git"
|
|
@@ -24,45 +24,36 @@
|
|
|
24
24
|
"author": "Karsten Schmidt <k+npm@thi.ng>",
|
|
25
25
|
"license": "Apache-2.0",
|
|
26
26
|
"scripts": {
|
|
27
|
-
"build": "yarn clean &&
|
|
28
|
-
"
|
|
29
|
-
"
|
|
30
|
-
"build:test": "rimraf build && tsc -p test/tsconfig.json",
|
|
31
|
-
"build:check": "tsc --isolatedModules --noEmit",
|
|
32
|
-
"test": "mocha test",
|
|
33
|
-
"cover": "nyc mocha test && nyc report --reporter=lcov",
|
|
34
|
-
"clean": "rimraf *.js *.d.ts *.map .nyc_output build coverage doc lib api geo shaders textures",
|
|
35
|
-
"doc:readme": "ts-node -P ../../tools/tsconfig.json ../../tools/src/readme.ts",
|
|
36
|
-
"doc": "typedoc --excludePrivate --out doc --theme ../../tools/doc/typedoc-theme src/index.ts",
|
|
27
|
+
"build": "yarn clean && tsc --declaration",
|
|
28
|
+
"clean": "rimraf *.js *.d.ts *.map doc api geo shaders textures",
|
|
29
|
+
"doc": "typedoc --excludePrivate --excludeInternal --out doc src/index.ts",
|
|
37
30
|
"doc:ae": "mkdir -p .ae/doc .ae/temp && node_modules/.bin/api-extractor run --local --verbose",
|
|
38
|
-
"
|
|
31
|
+
"doc:readme": "yarn doc:stats && ../../scripts/node-esm ../../tools/src/readme.ts",
|
|
32
|
+
"doc:stats": "../../scripts/node-esm ../../tools/src/module-stats.ts",
|
|
33
|
+
"pub": "yarn build && yarn publish --access public",
|
|
34
|
+
"test": "testament test"
|
|
39
35
|
},
|
|
40
36
|
"dependencies": {
|
|
41
|
-
"@thi.ng/adapt-dpi": "^
|
|
42
|
-
"@thi.ng/api": "^
|
|
43
|
-
"@thi.ng/associative": "^
|
|
44
|
-
"@thi.ng/checks": "^
|
|
45
|
-
"@thi.ng/equiv": "^
|
|
46
|
-
"@thi.ng/errors": "^
|
|
47
|
-
"@thi.ng/
|
|
48
|
-
"@thi.ng/
|
|
49
|
-
"@thi.ng/
|
|
50
|
-
"@thi.ng/
|
|
51
|
-
"@thi.ng/shader-ast
|
|
52
|
-
"@thi.ng/shader-ast-
|
|
53
|
-
"@thi.ng/
|
|
54
|
-
"@thi.ng/
|
|
55
|
-
"@thi.ng/
|
|
37
|
+
"@thi.ng/adapt-dpi": "^2.0.3",
|
|
38
|
+
"@thi.ng/api": "^8.0.3",
|
|
39
|
+
"@thi.ng/associative": "^6.0.3",
|
|
40
|
+
"@thi.ng/checks": "^3.0.3",
|
|
41
|
+
"@thi.ng/equiv": "^2.0.3",
|
|
42
|
+
"@thi.ng/errors": "^2.0.3",
|
|
43
|
+
"@thi.ng/logger": "^1.0.3",
|
|
44
|
+
"@thi.ng/matrices": "^2.0.3",
|
|
45
|
+
"@thi.ng/memoize": "^3.0.3",
|
|
46
|
+
"@thi.ng/pixel": "^2.1.2",
|
|
47
|
+
"@thi.ng/shader-ast": "^0.11.3",
|
|
48
|
+
"@thi.ng/shader-ast-glsl": "^0.3.3",
|
|
49
|
+
"@thi.ng/shader-ast-stdlib": "^0.10.3",
|
|
50
|
+
"@thi.ng/transducers": "^8.0.3",
|
|
51
|
+
"@thi.ng/vector-pools": "^3.0.3",
|
|
52
|
+
"@thi.ng/vectors": "^7.0.3"
|
|
53
|
+
},
|
|
54
|
+
"devDependencies": {
|
|
55
|
+
"@thi.ng/testament": "^0.1.3"
|
|
56
56
|
},
|
|
57
|
-
"files": [
|
|
58
|
-
"*.js",
|
|
59
|
-
"*.d.ts",
|
|
60
|
-
"lib",
|
|
61
|
-
"api",
|
|
62
|
-
"geo",
|
|
63
|
-
"shaders",
|
|
64
|
-
"textures"
|
|
65
|
-
],
|
|
66
57
|
"keywords": [
|
|
67
58
|
"2d",
|
|
68
59
|
"3d",
|
|
@@ -85,7 +76,127 @@
|
|
|
85
76
|
"publishConfig": {
|
|
86
77
|
"access": "public"
|
|
87
78
|
},
|
|
88
|
-
"
|
|
79
|
+
"engines": {
|
|
80
|
+
"node": ">=12.7"
|
|
81
|
+
},
|
|
82
|
+
"files": [
|
|
83
|
+
"*.js",
|
|
84
|
+
"*.d.ts",
|
|
85
|
+
"api",
|
|
86
|
+
"geo",
|
|
87
|
+
"shaders",
|
|
88
|
+
"textures"
|
|
89
|
+
],
|
|
90
|
+
"exports": {
|
|
91
|
+
".": {
|
|
92
|
+
"import": "./index.js"
|
|
93
|
+
},
|
|
94
|
+
"./api/blend": {
|
|
95
|
+
"import": "./api/blend.js"
|
|
96
|
+
},
|
|
97
|
+
"./api/buffers": {
|
|
98
|
+
"import": "./api/buffers.js"
|
|
99
|
+
},
|
|
100
|
+
"./api/canvas": {
|
|
101
|
+
"import": "./api/canvas.js"
|
|
102
|
+
},
|
|
103
|
+
"./api/ext": {
|
|
104
|
+
"import": "./api/ext.js"
|
|
105
|
+
},
|
|
106
|
+
"./api/glsl": {
|
|
107
|
+
"import": "./api/glsl.js"
|
|
108
|
+
},
|
|
109
|
+
"./api/material": {
|
|
110
|
+
"import": "./api/material.js"
|
|
111
|
+
},
|
|
112
|
+
"./api/model": {
|
|
113
|
+
"import": "./api/model.js"
|
|
114
|
+
},
|
|
115
|
+
"./api/multipass": {
|
|
116
|
+
"import": "./api/multipass.js"
|
|
117
|
+
},
|
|
118
|
+
"./api/shader": {
|
|
119
|
+
"import": "./api/shader.js"
|
|
120
|
+
},
|
|
121
|
+
"./api/stencil": {
|
|
122
|
+
"import": "./api/stencil.js"
|
|
123
|
+
},
|
|
124
|
+
"./api/texture": {
|
|
125
|
+
"import": "./api/texture.js"
|
|
126
|
+
},
|
|
127
|
+
"./buffer": {
|
|
128
|
+
"import": "./buffer.js"
|
|
129
|
+
},
|
|
130
|
+
"./canvas": {
|
|
131
|
+
"import": "./canvas.js"
|
|
132
|
+
},
|
|
133
|
+
"./checks": {
|
|
134
|
+
"import": "./checks.js"
|
|
135
|
+
},
|
|
136
|
+
"./draw": {
|
|
137
|
+
"import": "./draw.js"
|
|
138
|
+
},
|
|
139
|
+
"./error": {
|
|
140
|
+
"import": "./error.js"
|
|
141
|
+
},
|
|
142
|
+
"./fbo": {
|
|
143
|
+
"import": "./fbo.js"
|
|
144
|
+
},
|
|
145
|
+
"./geo/cube": {
|
|
146
|
+
"import": "./geo/cube.js"
|
|
147
|
+
},
|
|
148
|
+
"./geo/quad": {
|
|
149
|
+
"import": "./geo/quad.js"
|
|
150
|
+
},
|
|
151
|
+
"./logger": {
|
|
152
|
+
"import": "./logger.js"
|
|
153
|
+
},
|
|
154
|
+
"./material": {
|
|
155
|
+
"import": "./material.js"
|
|
156
|
+
},
|
|
157
|
+
"./matrices": {
|
|
158
|
+
"import": "./matrices.js"
|
|
159
|
+
},
|
|
160
|
+
"./multipass": {
|
|
161
|
+
"import": "./multipass.js"
|
|
162
|
+
},
|
|
163
|
+
"./rbo": {
|
|
164
|
+
"import": "./rbo.js"
|
|
165
|
+
},
|
|
166
|
+
"./readpixels": {
|
|
167
|
+
"import": "./readpixels.js"
|
|
168
|
+
},
|
|
169
|
+
"./shader": {
|
|
170
|
+
"import": "./shader.js"
|
|
171
|
+
},
|
|
172
|
+
"./shaders/lambert": {
|
|
173
|
+
"import": "./shaders/lambert.js"
|
|
174
|
+
},
|
|
175
|
+
"./shaders/phong": {
|
|
176
|
+
"import": "./shaders/phong.js"
|
|
177
|
+
},
|
|
178
|
+
"./shaders/pipeline": {
|
|
179
|
+
"import": "./shaders/pipeline.js"
|
|
180
|
+
},
|
|
181
|
+
"./syntax": {
|
|
182
|
+
"import": "./syntax.js"
|
|
183
|
+
},
|
|
184
|
+
"./texture": {
|
|
185
|
+
"import": "./texture.js"
|
|
186
|
+
},
|
|
187
|
+
"./textures/checkerboard": {
|
|
188
|
+
"import": "./textures/checkerboard.js"
|
|
189
|
+
},
|
|
190
|
+
"./textures/stripes": {
|
|
191
|
+
"import": "./textures/stripes.js"
|
|
192
|
+
},
|
|
193
|
+
"./uniforms": {
|
|
194
|
+
"import": "./uniforms.js"
|
|
195
|
+
},
|
|
196
|
+
"./utils": {
|
|
197
|
+
"import": "./utils.js"
|
|
198
|
+
}
|
|
199
|
+
},
|
|
89
200
|
"thi.ng": {
|
|
90
201
|
"related": [
|
|
91
202
|
"ecs",
|
|
@@ -99,5 +210,5 @@
|
|
|
99
210
|
],
|
|
100
211
|
"year": 2014
|
|
101
212
|
},
|
|
102
|
-
"gitHead": "
|
|
213
|
+
"gitHead": "1fb38cac74d6c009d96855c28784a267a81badf1"
|
|
103
214
|
}
|
package/rbo.d.ts
CHANGED
package/rbo.js
CHANGED
package/readpixels.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ITexture, ReadableTextureFormat, TextureType } from "./api/texture";
|
|
1
|
+
import type { ITexture, ReadableTextureFormat, TextureType } from "./api/texture.js";
|
|
2
2
|
export declare const readPixels: <T extends Uint8Array | Uint16Array | Uint32Array | Float32Array>(gl: WebGLRenderingContext, x: number, y: number, w: number, h: number, format: ReadableTextureFormat, type: TextureType, out: T) => T;
|
|
3
3
|
export declare const readTexture: <T extends Uint8Array | Uint16Array | Uint32Array | Float32Array>(gl: WebGLRenderingContext, tex: ITexture, format: ReadableTextureFormat, type: TextureType, out: T) => T;
|
|
4
4
|
//# sourceMappingURL=readpixels.d.ts.map
|
package/readpixels.js
CHANGED
package/shader.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { IObjectOf } from "@thi.ng/api";
|
|
2
|
-
import { GLSLVersion } from "@thi.ng/shader-ast-glsl";
|
|
3
|
-
import type { ModelAttributeSpecs, ModelSpec } from "./api/model";
|
|
4
|
-
import { IShader, ShaderAttrib, ShaderSpec, ShaderState, ShaderType, ShaderUniforms, UniformValues } from "./api/shader";
|
|
1
|
+
import type { IObjectOf } from "@thi.ng/api";
|
|
2
|
+
import { GLSLVersion } from "@thi.ng/shader-ast-glsl/api";
|
|
3
|
+
import type { ModelAttributeSpecs, ModelSpec } from "./api/model.js";
|
|
4
|
+
import { DefShaderOpts, IShader, ShaderAttrib, ShaderSpec, ShaderState, ShaderType, ShaderUniforms, UniformValues } from "./api/shader.js";
|
|
5
5
|
export declare class Shader implements IShader {
|
|
6
6
|
gl: WebGLRenderingContext;
|
|
7
7
|
program: WebGLProgram;
|
|
@@ -19,8 +19,8 @@ export declare class Shader implements IShader {
|
|
|
19
19
|
prepareState(state?: Partial<ShaderState>): void;
|
|
20
20
|
protected setState(id: number, val: GLenum | boolean): void;
|
|
21
21
|
}
|
|
22
|
-
export declare const defShader: (gl: WebGLRenderingContext, spec: ShaderSpec) => Shader;
|
|
23
|
-
export declare const shaderSourceFromAST: (spec: ShaderSpec, type: ShaderType, version: GLSLVersion) => string;
|
|
22
|
+
export declare const defShader: (gl: WebGLRenderingContext, spec: ShaderSpec, opts?: Partial<DefShaderOpts> | undefined) => Shader;
|
|
23
|
+
export declare const shaderSourceFromAST: (spec: ShaderSpec, type: ShaderType, version: GLSLVersion, opts?: Partial<DefShaderOpts>) => string;
|
|
24
24
|
export declare const prepareShaderSource: (spec: ShaderSpec, type: ShaderType, version: GLSLVersion) => string;
|
|
25
25
|
export declare const compileShader: (gl: WebGLRenderingContext, type: GLenum, src: string) => WebGLShader;
|
|
26
26
|
//# sourceMappingURL=shader.d.ts.map
|
package/shader.js
CHANGED
|
@@ -1,23 +1,29 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
1
|
+
import { deref } from "@thi.ng/api/deref";
|
|
2
|
+
import { asGLType } from "@thi.ng/api/typedarray";
|
|
3
|
+
import { existsAndNotNull } from "@thi.ng/checks/exists-not-null";
|
|
4
|
+
import { isArray } from "@thi.ng/checks/is-array";
|
|
5
|
+
import { isBoolean } from "@thi.ng/checks/is-boolean";
|
|
6
|
+
import { isFunction } from "@thi.ng/checks/is-function";
|
|
7
|
+
import { unsupported } from "@thi.ng/errors/unsupported";
|
|
8
|
+
import { doOnce } from "@thi.ng/memoize/do-once";
|
|
9
|
+
import { GLSLVersion } from "@thi.ng/shader-ast-glsl/api";
|
|
10
|
+
import { targetGLSL } from "@thi.ng/shader-ast-glsl/target";
|
|
11
|
+
import { program } from "@thi.ng/shader-ast/ast/scope";
|
|
12
|
+
import { input, output, sym, uniform } from "@thi.ng/shader-ast/ast/sym";
|
|
13
|
+
import { vals } from "@thi.ng/transducers/vals";
|
|
14
|
+
import { GL_EXT_INFO, } from "./api/ext.js";
|
|
15
|
+
import { DEFAULT_OUTPUT, } from "./api/shader.js";
|
|
16
|
+
import { getExtensions } from "./canvas.js";
|
|
17
|
+
import { isGL2Context } from "./checks.js";
|
|
18
|
+
import { error } from "./error.js";
|
|
19
|
+
import { LOGGER } from "./logger.js";
|
|
20
|
+
import { GLSL_HEADER, NO_PREFIXES, SYNTAX } from "./syntax.js";
|
|
21
|
+
import { UNIFORM_SETTERS } from "./uniforms.js";
|
|
16
22
|
const ERROR_REGEXP = /ERROR: \d+:(\d+): (.*)/;
|
|
17
23
|
export class Shader {
|
|
18
24
|
constructor(gl, program, attribs, uniforms, state) {
|
|
19
|
-
this.warnAttrib = doOnce((id) => LOGGER.warn(`unknown attrib: ${id}`));
|
|
20
|
-
this.warnUni = doOnce((id) => LOGGER.warn(`unknown uniform: ${id}`));
|
|
25
|
+
this.warnAttrib = doOnce((id) => LOGGER.warn(`unknown attrib: ${id} (no further warnings will be shown...)`));
|
|
26
|
+
this.warnUni = doOnce((id) => LOGGER.warn(`unknown uniform: ${id} (no further warnings will be shown...)`));
|
|
21
27
|
this.gl = gl;
|
|
22
28
|
this.program = program;
|
|
23
29
|
this.attribs = attribs;
|
|
@@ -124,15 +130,15 @@ export class Shader {
|
|
|
124
130
|
}
|
|
125
131
|
}
|
|
126
132
|
}
|
|
127
|
-
export const defShader = (gl, spec) => {
|
|
133
|
+
export const defShader = (gl, spec, opts) => {
|
|
128
134
|
const version = isGL2Context(gl)
|
|
129
135
|
? GLSLVersion.GLES_300
|
|
130
136
|
: GLSLVersion.GLES_100;
|
|
131
137
|
const srcVS = isFunction(spec.vs)
|
|
132
|
-
? shaderSourceFromAST(spec, "vs", version)
|
|
138
|
+
? shaderSourceFromAST(spec, "vs", version, opts)
|
|
133
139
|
: prepareShaderSource(spec, "vs", version);
|
|
134
140
|
const srcFS = isFunction(spec.fs)
|
|
135
|
-
? shaderSourceFromAST(spec, "fs", version)
|
|
141
|
+
? shaderSourceFromAST(spec, "fs", version, opts)
|
|
136
142
|
: prepareShaderSource(spec, "fs", version);
|
|
137
143
|
LOGGER.debug(srcVS);
|
|
138
144
|
LOGGER.debug(srcFS);
|
|
@@ -221,7 +227,7 @@ const compileUniformDecls = (spec, acc) => {
|
|
|
221
227
|
: uniform(u, id);
|
|
222
228
|
}
|
|
223
229
|
};
|
|
224
|
-
export const shaderSourceFromAST = (spec, type, version) => {
|
|
230
|
+
export const shaderSourceFromAST = (spec, type, version, opts = {}) => {
|
|
225
231
|
let prelude = compilePrelude(spec, version);
|
|
226
232
|
const inputs = {};
|
|
227
233
|
const outputs = {};
|
|
@@ -255,17 +261,21 @@ export const shaderSourceFromAST = (spec, type, version) => {
|
|
|
255
261
|
type,
|
|
256
262
|
version,
|
|
257
263
|
prelude,
|
|
264
|
+
prec: opts.prec,
|
|
258
265
|
});
|
|
259
266
|
return (target(program([
|
|
260
267
|
...vals(unis),
|
|
261
268
|
...vals(inputs),
|
|
262
269
|
...vals(outputs),
|
|
263
|
-
...spec[type](target, unis, inputs,
|
|
270
|
+
...spec[type](target, unis, inputs, {
|
|
271
|
+
...outputs,
|
|
272
|
+
...outputAliases,
|
|
273
|
+
}),
|
|
264
274
|
])) + (spec.post ? "\n" + spec.post : ""));
|
|
265
275
|
};
|
|
266
276
|
export const prepareShaderSource = (spec, type, version) => {
|
|
267
277
|
const syntax = SYNTAX[version];
|
|
268
|
-
const prefixes =
|
|
278
|
+
const prefixes = { ...NO_PREFIXES, ...spec.declPrefixes };
|
|
269
279
|
const isVS = type === "vs";
|
|
270
280
|
let src = "";
|
|
271
281
|
src += `#version ${version}\n`;
|
package/shaders/lambert.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { Material } from "../api/material";
|
|
2
|
-
import type {
|
|
3
|
-
export interface LambertOpts extends
|
|
1
|
+
import type { Material } from "../api/material.js";
|
|
2
|
+
import type { ShaderPresetOpts, ShaderSpec } from "../api/shader.js";
|
|
3
|
+
export interface LambertOpts extends ShaderPresetOpts<Pick<Material, "ambientCol" | "diffuseCol">> {
|
|
4
4
|
bidir: boolean;
|
|
5
5
|
}
|
|
6
6
|
export declare const LAMBERT: (opts?: Partial<LambertOpts>) => ShaderSpec;
|
package/shaders/lambert.js
CHANGED
|
@@ -1,8 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
1
|
+
import { diffuseLighting, halfLambert, lambert, } from "@thi.ng/shader-ast-stdlib/light/lambert";
|
|
2
|
+
import { transformMVP } from "@thi.ng/shader-ast-stdlib/matrix/mvp";
|
|
3
|
+
import { surfaceNormal } from "@thi.ng/shader-ast-stdlib/matrix/normal";
|
|
4
|
+
import { assign } from "@thi.ng/shader-ast/ast/assign";
|
|
5
|
+
import { defMain } from "@thi.ng/shader-ast/ast/function";
|
|
6
|
+
import { vec4 } from "@thi.ng/shader-ast/ast/lit";
|
|
7
|
+
import { mul } from "@thi.ng/shader-ast/ast/ops";
|
|
8
|
+
import { $ } from "@thi.ng/shader-ast/ast/swizzle";
|
|
9
|
+
import { normalize } from "@thi.ng/shader-ast/builtin/math";
|
|
10
|
+
import { texture } from "@thi.ng/shader-ast/builtin/texture";
|
|
11
|
+
import { defMaterial } from "../material.js";
|
|
12
|
+
import { autoNormalMatrix2 } from "../matrices.js";
|
|
13
|
+
import { colorAttrib, positionAttrib } from "../utils.js";
|
|
6
14
|
export const LAMBERT = (opts = {}) => ({
|
|
7
15
|
vs: (gl, unis, ins, outs) => [
|
|
8
16
|
defMain(() => [
|
|
@@ -20,10 +28,34 @@ export const LAMBERT = (opts = {}) => ({
|
|
|
20
28
|
]),
|
|
21
29
|
],
|
|
22
30
|
// pre: ALIAS_TEXTURE,
|
|
23
|
-
attribs:
|
|
24
|
-
|
|
25
|
-
:
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
31
|
+
attribs: {
|
|
32
|
+
position: "vec3",
|
|
33
|
+
normal: "vec3",
|
|
34
|
+
...(opts.uv ? { [opts.uv]: "vec2" } : null),
|
|
35
|
+
...(opts.color && !opts.instanceColor
|
|
36
|
+
? { [opts.color]: "vec3" }
|
|
37
|
+
: null),
|
|
38
|
+
...(opts.instancePos ? { [opts.instancePos]: "vec3" } : null),
|
|
39
|
+
...(opts.instanceColor ? { [opts.instanceColor]: "vec3" } : null),
|
|
40
|
+
},
|
|
41
|
+
varying: {
|
|
42
|
+
vcolor: "vec3",
|
|
43
|
+
vnormal: "vec3",
|
|
44
|
+
...(opts.uv ? { vuv: "vec2" } : null),
|
|
45
|
+
},
|
|
46
|
+
uniforms: {
|
|
47
|
+
model: "mat4",
|
|
48
|
+
view: "mat4",
|
|
49
|
+
proj: "mat4",
|
|
50
|
+
normalMat: ["mat4", autoNormalMatrix2()],
|
|
51
|
+
lightDir: ["vec3", [0, 1, 0]],
|
|
52
|
+
lightCol: ["vec3", [1, 1, 1]],
|
|
53
|
+
...defMaterial({ diffuseCol: [1, 1, 1], ...opts.material }, { specularCol: false }),
|
|
54
|
+
...(opts.uv ? { tex: "sampler2D" } : null),
|
|
55
|
+
},
|
|
56
|
+
state: {
|
|
57
|
+
depth: true,
|
|
58
|
+
cull: true,
|
|
59
|
+
...opts.state,
|
|
60
|
+
},
|
|
29
61
|
});
|
package/shaders/phong.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { Material } from "../api/material";
|
|
2
|
-
import type {
|
|
3
|
-
export declare type PhongOpts =
|
|
1
|
+
import type { Material } from "../api/material.js";
|
|
2
|
+
import type { ShaderPresetOpts, ShaderSpec } from "../api/shader.js";
|
|
3
|
+
export declare type PhongOpts = ShaderPresetOpts<Pick<Material, "ambientCol" | "diffuseCol" | "specularCol">>;
|
|
4
4
|
export declare const PHONG: (opts?: Partial<PhongOpts>) => ShaderSpec;
|
|
5
5
|
//# sourceMappingURL=phong.d.ts.map
|
package/shaders/phong.js
CHANGED
|
@@ -1,8 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
1
|
+
import { diffuseLighting } from "@thi.ng/shader-ast-stdlib/light/lambert";
|
|
2
|
+
import { surfaceNormal } from "@thi.ng/shader-ast-stdlib/matrix/normal";
|
|
3
|
+
import { assign } from "@thi.ng/shader-ast/ast/assign";
|
|
4
|
+
import { ternary } from "@thi.ng/shader-ast/ast/controlflow";
|
|
5
|
+
import { defMain } from "@thi.ng/shader-ast/ast/function";
|
|
6
|
+
import { FLOAT0, vec4 } from "@thi.ng/shader-ast/ast/lit";
|
|
7
|
+
import { add, gt, mul, sub } from "@thi.ng/shader-ast/ast/ops";
|
|
8
|
+
import { $ } from "@thi.ng/shader-ast/ast/swizzle";
|
|
9
|
+
import { sym } from "@thi.ng/shader-ast/ast/sym";
|
|
10
|
+
import { dot, max, normalize, pow } from "@thi.ng/shader-ast/builtin/math";
|
|
11
|
+
import { defMaterial } from "../material.js";
|
|
12
|
+
import { autoNormalMatrix1 } from "../matrices.js";
|
|
13
|
+
import { colorAttrib, positionAttrib } from "../utils.js";
|
|
6
14
|
export const PHONG = (opts = {}) => ({
|
|
7
15
|
vs: (gl, unis, ins, outs) => [
|
|
8
16
|
defMain(() => {
|
|
@@ -32,15 +40,35 @@ export const PHONG = (opts = {}) => ({
|
|
|
32
40
|
];
|
|
33
41
|
}),
|
|
34
42
|
],
|
|
35
|
-
attribs:
|
|
36
|
-
|
|
37
|
-
:
|
|
43
|
+
attribs: {
|
|
44
|
+
position: "vec3",
|
|
45
|
+
normal: "vec3",
|
|
46
|
+
...(opts.color && !opts.instanceColor
|
|
47
|
+
? { [opts.color]: "vec3" }
|
|
48
|
+
: null),
|
|
49
|
+
...(opts.instancePos ? { [opts.instancePos]: "vec3" } : null),
|
|
50
|
+
...(opts.instanceColor ? { [opts.instanceColor]: "vec3" } : null),
|
|
51
|
+
},
|
|
38
52
|
varying: {
|
|
39
53
|
vnormal: "vec3",
|
|
40
54
|
veye: "vec3",
|
|
41
55
|
vlight: "vec3",
|
|
42
56
|
vcolor: "vec3",
|
|
43
57
|
},
|
|
44
|
-
uniforms:
|
|
45
|
-
|
|
58
|
+
uniforms: {
|
|
59
|
+
model: "mat4",
|
|
60
|
+
normalMat: ["mat4", autoNormalMatrix1()],
|
|
61
|
+
view: "mat4",
|
|
62
|
+
proj: "mat4",
|
|
63
|
+
shininess: ["float", 32],
|
|
64
|
+
eyePos: "vec3",
|
|
65
|
+
lightPos: ["vec3", [0, 0, 2]],
|
|
66
|
+
lightCol: ["vec3", [1, 1, 1]],
|
|
67
|
+
...defMaterial(opts.material),
|
|
68
|
+
},
|
|
69
|
+
state: {
|
|
70
|
+
depth: true,
|
|
71
|
+
cull: true,
|
|
72
|
+
...opts.state,
|
|
73
|
+
},
|
|
46
74
|
});
|
package/shaders/pipeline.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ShaderFn, ShaderSpec } from "../api/shader";
|
|
1
|
+
import type { ShaderFn, ShaderSpec } from "../api/shader.js";
|
|
2
2
|
export declare const PASSTHROUGH_VS: ShaderFn;
|
|
3
3
|
export declare const PASSTHROUGH_VS_UV: ShaderFn;
|
|
4
4
|
export declare const PASSTHROUGH_FS: ShaderFn;
|
package/shaders/pipeline.js
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { assign } from "@thi.ng/shader-ast/ast/assign";
|
|
2
|
+
import { defMain } from "@thi.ng/shader-ast/ast/function";
|
|
3
|
+
import { FLOAT0, FLOAT1, vec4 } from "@thi.ng/shader-ast/ast/lit";
|
|
4
|
+
import { $xy } from "@thi.ng/shader-ast/ast/swizzle";
|
|
5
|
+
import { texture } from "@thi.ng/shader-ast/builtin/texture";
|
|
2
6
|
export const PASSTHROUGH_VS = (gl, _, ins) => [
|
|
3
7
|
defMain(() => [assign(gl.gl_Position, vec4(ins.position, FLOAT0, FLOAT1))]),
|
|
4
8
|
];
|
package/syntax.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { GLSLVersion } from "@thi.ng/shader-ast-glsl";
|
|
2
|
-
import type { GLSLDeclPrefixes, GLSLSyntax } from "./api/shader";
|
|
1
|
+
import { GLSLVersion } from "@thi.ng/shader-ast-glsl/api";
|
|
2
|
+
import type { GLSLDeclPrefixes, GLSLSyntax } from "./api/shader.js";
|
|
3
3
|
export declare const PREFIXES: GLSLDeclPrefixes;
|
|
4
4
|
export declare const NO_PREFIXES: GLSLDeclPrefixes;
|
|
5
5
|
/**
|
package/syntax.js
CHANGED
package/texture.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ITexture, TextureFilter, TextureFormat, TextureOpts, TextureRepeat, TextureTarget, TextureType } from "./api/texture";
|
|
1
|
+
import { ITexture, TextureFilter, TextureFormat, TextureOpts, TextureRepeat, TextureTarget, TextureType } from "./api/texture.js";
|
|
2
2
|
export declare const bindTextures: (textures?: ITexture[] | undefined) => void;
|
|
3
3
|
export declare const unbindTextures: (textures?: ITexture[] | undefined) => void;
|
|
4
4
|
export declare class Texture implements ITexture {
|
package/texture.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { withoutKeysObj } from "@thi.ng/associative";
|
|
2
|
-
import { isArray } from "@thi.ng/checks";
|
|
3
|
-
import { TextureFilter, TextureFormat, TextureRepeat, TextureTarget, TEX_FORMATS, } from "./api/texture";
|
|
4
|
-
import { isGL2Context } from "./checks";
|
|
5
|
-
import { error } from "./error";
|
|
1
|
+
import { withoutKeysObj } from "@thi.ng/associative/without-keys";
|
|
2
|
+
import { isArray } from "@thi.ng/checks/is-array";
|
|
3
|
+
import { TextureFilter, TextureFormat, TextureRepeat, TextureTarget, TEX_FORMATS, } from "./api/texture.js";
|
|
4
|
+
import { isGL2Context } from "./checks.js";
|
|
5
|
+
import { error } from "./error.js";
|
|
6
6
|
const $bind = (op) => (textures) => {
|
|
7
7
|
if (!textures)
|
|
8
8
|
return;
|
|
@@ -16,7 +16,11 @@ export class Texture {
|
|
|
16
16
|
constructor(gl, opts = {}) {
|
|
17
17
|
this.gl = gl;
|
|
18
18
|
this.tex = gl.createTexture() || error("error creating WebGL texture");
|
|
19
|
-
this.configure(
|
|
19
|
+
this.configure({
|
|
20
|
+
filter: TextureFilter.NEAREST,
|
|
21
|
+
wrap: TextureRepeat.CLAMP,
|
|
22
|
+
...opts,
|
|
23
|
+
});
|
|
20
24
|
}
|
|
21
25
|
configure(opts = {}, unbind = true) {
|
|
22
26
|
const gl = this.gl;
|
package/textures/checkerboard.js
CHANGED
|
@@ -1,6 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { canvasPixels } from "@thi.ng/pixel/canvas";
|
|
2
|
+
import { ARGB8888 } from "@thi.ng/pixel/format/argb8888";
|
|
2
3
|
export const checkerboard = (opts) => {
|
|
3
|
-
opts =
|
|
4
|
+
opts = {
|
|
5
|
+
size: 16,
|
|
6
|
+
col1: 0xffffffff,
|
|
7
|
+
col2: 0xff000000,
|
|
8
|
+
cornerCols: [0xffff0000, 0xff00ff00, 0xff0000ff, 0xffffff00],
|
|
9
|
+
...opts,
|
|
10
|
+
};
|
|
4
11
|
const size = opts.size;
|
|
5
12
|
const col1 = ARGB8888.toABGR(opts.col1);
|
|
6
13
|
const col2 = ARGB8888.toABGR(opts.col2);
|
package/textures/stripes.js
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { canvasPixels } from "@thi.ng/pixel/canvas";
|
|
2
|
+
import { ARGB8888 } from "@thi.ng/pixel/format/argb8888";
|
|
2
3
|
export const stripes = (opts) => {
|
|
3
|
-
opts =
|
|
4
|
+
opts = {
|
|
5
|
+
size: 16,
|
|
6
|
+
col1: 0xffffffff,
|
|
7
|
+
col2: 0xff000000,
|
|
8
|
+
...opts,
|
|
9
|
+
};
|
|
4
10
|
const size = opts.size;
|
|
5
11
|
const col1 = ARGB8888.toABGR(opts.col1);
|
|
6
12
|
const col2 = ARGB8888.toABGR(opts.col2);
|
package/uniforms.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Fn, Fn3, IObjectOf } from "@thi.ng/api";
|
|
2
|
-
import { ReadonlyVec } from "@thi.ng/vectors";
|
|
3
|
-
import type { UniformValue } from "./api/shader";
|
|
2
|
+
import { ReadonlyVec } from "@thi.ng/vectors/api";
|
|
3
|
+
import type { UniformValue } from "./api/shader.js";
|
|
4
4
|
export declare const UNIFORM_SETTERS: IObjectOf<Fn3<WebGLRenderingContext, WebGLUniformLocation, number | ReadonlyVec | undefined, Fn<UniformValue | undefined | null, void>>>;
|
|
5
5
|
//# sourceMappingURL=uniforms.d.ts.map
|