@luma.gl/shadertools 9.1.9 → 9.2.0-alpha.2
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/dist/dist.dev.js +1614 -3716
- package/dist/dist.min.js +278 -484
- package/dist/index.cjs +366 -804
- package/dist/index.cjs.map +4 -4
- package/dist/index.d.ts +0 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -10
- package/dist/index.js.map +1 -1
- package/dist/lib/shader-assembly/assemble-shaders.d.ts +6 -4
- package/dist/lib/shader-assembly/assemble-shaders.d.ts.map +1 -1
- package/dist/lib/shader-assembly/assemble-shaders.js +14 -9
- package/dist/lib/shader-assembly/assemble-shaders.js.map +1 -1
- package/dist/lib/shader-assembly/platform-info.d.ts +1 -1
- package/dist/lib/shader-assembly/platform-info.d.ts.map +1 -1
- package/dist/lib/shader-module/shader-module.d.ts +1 -1
- package/dist/lib/shader-module/shader-module.d.ts.map +1 -1
- package/dist/lib/wgsl/get-shader-layout-wgsl.d.ts.map +1 -1
- package/dist/lib/wgsl/get-shader-layout-wgsl.js +3 -1
- package/dist/lib/wgsl/get-shader-layout-wgsl.js.map +1 -1
- package/dist/modules/engine/project/project.d.ts.map +1 -1
- package/dist/modules/engine/project/project.js +4 -2
- package/dist/modules/engine/project/project.js.map +1 -1
- package/dist/modules/lighting/gouraud-material/gouraud-material.js +1 -1
- package/dist/modules/lighting/gouraud-material/gouraud-material.js.map +1 -1
- package/dist/modules/lighting/lights/{lighting-uniforms-glsl.d.ts → lighting-glsl.d.ts} +1 -1
- package/dist/modules/lighting/lights/lighting-glsl.d.ts.map +1 -0
- package/dist/modules/lighting/lights/{lighting-uniforms-glsl.js → lighting-glsl.js} +1 -1
- package/dist/modules/lighting/lights/lighting-glsl.js.map +1 -0
- package/dist/modules/lighting/lights/{lighting-uniforms-wgsl.d.ts → lighting-wgsl.d.ts} +1 -1
- package/dist/modules/lighting/lights/lighting-wgsl.d.ts.map +1 -0
- package/dist/modules/lighting/lights/{lighting-uniforms-wgsl.js → lighting-wgsl.js} +1 -1
- package/dist/modules/lighting/lights/lighting-wgsl.js.map +1 -0
- package/dist/modules/lighting/lights/lighting.d.ts +1 -3
- package/dist/modules/lighting/lights/lighting.d.ts.map +1 -1
- package/dist/modules/lighting/lights/lighting.js +4 -4
- package/dist/modules/lighting/lights/lighting.js.map +1 -1
- package/dist/modules/lighting/no-material/dirlight.d.ts.map +1 -1
- package/dist/modules/lighting/no-material/dirlight.js +1 -2
- package/dist/modules/lighting/no-material/dirlight.js.map +1 -1
- package/dist/modules/lighting/pbr-material/{pbr-fragment-glsl.d.ts → pbr-material-glsl.d.ts} +2 -1
- package/dist/modules/lighting/pbr-material/pbr-material-glsl.d.ts.map +1 -0
- package/dist/modules/lighting/pbr-material/{pbr-fragment-glsl.js → pbr-material-glsl.js} +36 -1
- package/dist/modules/lighting/pbr-material/pbr-material-glsl.js.map +1 -0
- package/dist/modules/lighting/pbr-material/pbr-material-wgsl.d.ts +3 -0
- package/dist/modules/lighting/pbr-material/pbr-material-wgsl.d.ts.map +1 -0
- package/dist/modules/lighting/pbr-material/pbr-material-wgsl.js +487 -0
- package/dist/modules/lighting/pbr-material/pbr-material-wgsl.js.map +1 -0
- package/dist/modules/lighting/pbr-material/pbr-material.d.ts +11 -4
- package/dist/modules/lighting/pbr-material/pbr-material.d.ts.map +1 -1
- package/dist/modules/lighting/pbr-material/pbr-material.js +12 -12
- package/dist/modules/lighting/pbr-material/pbr-material.js.map +1 -1
- package/dist/modules/lighting/pbr-material/pbr-projection.d.ts.map +1 -1
- package/dist/modules/lighting/pbr-material/pbr-projection.js.map +1 -1
- package/dist/modules/lighting/phong-material/phong-material.js +1 -1
- package/dist/modules/lighting/phong-material/phong-material.js.map +1 -1
- package/dist/modules/lighting/phong-material/phong-shaders-glsl.d.ts +1 -1
- package/dist/modules/lighting/phong-material/phong-shaders-glsl.d.ts.map +1 -1
- package/dist/modules/lighting/phong-material/phong-shaders-glsl.js +2 -0
- package/dist/modules/lighting/phong-material/phong-shaders-glsl.js.map +1 -1
- package/dist/modules/math/random/random.d.ts +1 -0
- package/dist/modules/math/random/random.d.ts.map +1 -1
- package/dist/modules/math/random/random.js +7 -0
- package/dist/modules/math/random/random.js.map +1 -1
- package/package.json +3 -3
- package/src/index.ts +0 -17
- package/src/lib/shader-assembly/assemble-shaders.ts +12 -11
- package/src/lib/shader-assembly/platform-info.ts +1 -1
- package/src/lib/shader-module/shader-module.ts +1 -1
- package/src/lib/wgsl/get-shader-layout-wgsl.ts +7 -5
- package/src/modules/engine/project/project.ts +8 -5
- package/src/modules/lighting/gouraud-material/gouraud-material.ts +1 -1
- package/src/modules/lighting/lights/lighting.ts +4 -4
- package/src/modules/lighting/no-material/dirlight.ts +2 -3
- package/src/modules/lighting/pbr-material/{pbr-fragment-glsl.ts → pbr-material-glsl.ts} +36 -1
- package/src/modules/lighting/pbr-material/pbr-material-wgsl.ts +490 -0
- package/src/modules/lighting/pbr-material/pbr-material.ts +12 -12
- package/src/modules/lighting/pbr-material/pbr-projection.ts +0 -2
- package/src/modules/lighting/phong-material/phong-material.ts +1 -1
- package/src/modules/lighting/phong-material/phong-shaders-glsl.ts +2 -0
- package/src/modules/math/random/random.ts +8 -0
- package/dist/modules/lighting/lights/lighting-uniforms-glsl.d.ts.map +0 -1
- package/dist/modules/lighting/lights/lighting-uniforms-glsl.js.map +0 -1
- package/dist/modules/lighting/lights/lighting-uniforms-wgsl.d.ts.map +0 -1
- package/dist/modules/lighting/lights/lighting-uniforms-wgsl.js.map +0 -1
- package/dist/modules/lighting/pbr-material/pbr-fragment-glsl.d.ts.map +0 -1
- package/dist/modules/lighting/pbr-material/pbr-fragment-glsl.js.map +0 -1
- package/dist/modules/lighting/pbr-material/pbr-uniforms-glsl.d.ts +0 -2
- package/dist/modules/lighting/pbr-material/pbr-uniforms-glsl.d.ts.map +0 -1
- package/dist/modules/lighting/pbr-material/pbr-uniforms-glsl.js +0 -67
- package/dist/modules/lighting/pbr-material/pbr-uniforms-glsl.js.map +0 -1
- package/dist/modules/lighting/pbr-material/pbr-vertex-glsl.d.ts +0 -2
- package/dist/modules/lighting/pbr-material/pbr-vertex-glsl.d.ts.map +0 -1
- package/dist/modules/lighting/pbr-material/pbr-vertex-glsl.js +0 -39
- package/dist/modules/lighting/pbr-material/pbr-vertex-glsl.js.map +0 -1
- package/dist/modules/module-injectors.d.ts +0 -3
- package/dist/modules/module-injectors.d.ts.map +0 -1
- package/dist/modules/module-injectors.js +0 -31
- package/dist/modules/module-injectors.js.map +0 -1
- package/dist/modules-webgl1/geometry/geometry.d.ts +0 -9
- package/dist/modules-webgl1/geometry/geometry.d.ts.map +0 -1
- package/dist/modules-webgl1/geometry/geometry.js +0 -39
- package/dist/modules-webgl1/geometry/geometry.js.map +0 -1
- package/dist/modules-webgl1/lighting/dirlight/dirlight.d.ts +0 -10
- package/dist/modules-webgl1/lighting/dirlight/dirlight.d.ts.map +0 -1
- package/dist/modules-webgl1/lighting/dirlight/dirlight.js +0 -38
- package/dist/modules-webgl1/lighting/dirlight/dirlight.js.map +0 -1
- package/dist/modules-webgl1/lighting/lights/lights-glsl.d.ts +0 -2
- package/dist/modules-webgl1/lighting/lights/lights-glsl.d.ts.map +0 -1
- package/dist/modules-webgl1/lighting/lights/lights-glsl.js +0 -40
- package/dist/modules-webgl1/lighting/lights/lights-glsl.js.map +0 -1
- package/dist/modules-webgl1/lighting/lights/lights.d.ts +0 -38
- package/dist/modules-webgl1/lighting/lights/lights.d.ts.map +0 -1
- package/dist/modules-webgl1/lighting/lights/lights.js +0 -93
- package/dist/modules-webgl1/lighting/lights/lights.js.map +0 -1
- package/dist/modules-webgl1/lighting/pbr/pbr-fragment-glsl.d.ts +0 -2
- package/dist/modules-webgl1/lighting/pbr/pbr-fragment-glsl.d.ts.map +0 -1
- package/dist/modules-webgl1/lighting/pbr/pbr-fragment-glsl.js +0 -393
- package/dist/modules-webgl1/lighting/pbr/pbr-fragment-glsl.js.map +0 -1
- package/dist/modules-webgl1/lighting/pbr/pbr-vertex-glsl.d.ts +0 -2
- package/dist/modules-webgl1/lighting/pbr/pbr-vertex-glsl.d.ts.map +0 -1
- package/dist/modules-webgl1/lighting/pbr/pbr-vertex-glsl.js +0 -43
- package/dist/modules-webgl1/lighting/pbr/pbr-vertex-glsl.js.map +0 -1
- package/dist/modules-webgl1/lighting/pbr/pbr.d.ts +0 -23
- package/dist/modules-webgl1/lighting/pbr/pbr.d.ts.map +0 -1
- package/dist/modules-webgl1/lighting/pbr/pbr.js +0 -21
- package/dist/modules-webgl1/lighting/pbr/pbr.js.map +0 -1
- package/dist/modules-webgl1/lighting/phong-lighting/phong-lighting-glsl.d.ts +0 -2
- package/dist/modules-webgl1/lighting/phong-lighting/phong-lighting-glsl.d.ts.map +0 -1
- package/dist/modules-webgl1/lighting/phong-lighting/phong-lighting-glsl.js +0 -79
- package/dist/modules-webgl1/lighting/phong-lighting/phong-lighting-glsl.js.map +0 -1
- package/dist/modules-webgl1/lighting/phong-lighting/phong-lighting.d.ts +0 -45
- package/dist/modules-webgl1/lighting/phong-lighting/phong-lighting.d.ts.map +0 -1
- package/dist/modules-webgl1/lighting/phong-lighting/phong-lighting.js +0 -44
- package/dist/modules-webgl1/lighting/phong-lighting/phong-lighting.js.map +0 -1
- package/dist/modules-webgl1/math/fp64/fp64-arithmetic-glsl.d.ts +0 -2
- package/dist/modules-webgl1/math/fp64/fp64-arithmetic-glsl.d.ts.map +0 -1
- package/dist/modules-webgl1/math/fp64/fp64-arithmetic-glsl.js +0 -171
- package/dist/modules-webgl1/math/fp64/fp64-arithmetic-glsl.js.map +0 -1
- package/dist/modules-webgl1/math/fp64/fp64-functions-glsl.d.ts +0 -2
- package/dist/modules-webgl1/math/fp64/fp64-functions-glsl.d.ts.map +0 -1
- package/dist/modules-webgl1/math/fp64/fp64-functions-glsl.js +0 -675
- package/dist/modules-webgl1/math/fp64/fp64-functions-glsl.js.map +0 -1
- package/dist/modules-webgl1/math/fp64/fp64.d.ts +0 -35
- package/dist/modules-webgl1/math/fp64/fp64.d.ts.map +0 -1
- package/dist/modules-webgl1/math/fp64/fp64.js +0 -38
- package/dist/modules-webgl1/math/fp64/fp64.js.map +0 -1
- package/dist/modules-webgl1/project/project.d.ts +0 -20
- package/dist/modules-webgl1/project/project.d.ts.map +0 -1
- package/dist/modules-webgl1/project/project.js +0 -114
- package/dist/modules-webgl1/project/project.js.map +0 -1
- package/src/modules/lighting/pbr-material/pbr-uniforms-glsl.ts +0 -67
- package/src/modules/lighting/pbr-material/pbr-vertex-glsl.ts +0 -39
- package/src/modules/module-injectors.ts +0 -32
- package/src/modules-webgl1/geometry/geometry.ts +0 -41
- package/src/modules-webgl1/lighting/dirlight/dirlight.ts +0 -50
- package/src/modules-webgl1/lighting/lights/lights-glsl.ts +0 -40
- package/src/modules-webgl1/lighting/lights/lights.ts +0 -143
- package/src/modules-webgl1/lighting/pbr/README.md +0 -12
- package/src/modules-webgl1/lighting/pbr/pbr-fragment-glsl.ts +0 -396
- package/src/modules-webgl1/lighting/pbr/pbr-vertex-glsl.ts +0 -43
- package/src/modules-webgl1/lighting/pbr/pbr.ts +0 -23
- package/src/modules-webgl1/lighting/phong-lighting/phong-lighting-glsl.ts +0 -79
- package/src/modules-webgl1/lighting/phong-lighting/phong-lighting.ts +0 -64
- package/src/modules-webgl1/math/fp64/fp64-arithmetic-glsl.ts +0 -171
- package/src/modules-webgl1/math/fp64/fp64-functions-glsl.ts +0 -675
- package/src/modules-webgl1/math/fp64/fp64.ts +0 -44
- package/src/modules-webgl1/project/README.md +0 -52
- package/src/modules-webgl1/project/project.ts +0 -135
- /package/src/modules/lighting/lights/{lighting-uniforms-glsl.ts → lighting-glsl.ts} +0 -0
- /package/src/modules/lighting/lights/{lighting-uniforms-wgsl.ts → lighting-wgsl.ts} +0 -0
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
4
|
import { lighting } from "../lights/lighting.js";
|
|
5
|
-
import { vs } from "./pbr-
|
|
6
|
-
import {
|
|
5
|
+
import { vs, fs } from "./pbr-material-glsl.js";
|
|
6
|
+
import { source } from "./pbr-material-wgsl.js";
|
|
7
7
|
import { pbrProjection } from "./pbr-projection.js";
|
|
8
8
|
/**
|
|
9
9
|
* An implementation of PBR (Physically-Based Rendering).
|
|
@@ -14,19 +14,19 @@ export const pbrMaterial = {
|
|
|
14
14
|
uniforms: {},
|
|
15
15
|
name: 'pbrMaterial',
|
|
16
16
|
dependencies: [lighting, pbrProjection],
|
|
17
|
+
source,
|
|
17
18
|
vs,
|
|
18
19
|
fs,
|
|
19
20
|
defines: {
|
|
20
|
-
LIGHTING_FRAGMENT:
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
// PBR_DEBUG: 0
|
|
21
|
+
LIGHTING_FRAGMENT: true,
|
|
22
|
+
HAS_NORMALMAP: false,
|
|
23
|
+
HAS_EMISSIVEMAP: false,
|
|
24
|
+
HAS_OCCLUSIONMAP: false,
|
|
25
|
+
HAS_BASECOLORMAP: false,
|
|
26
|
+
HAS_METALROUGHNESSMAP: false,
|
|
27
|
+
ALPHA_CUTOFF: false,
|
|
28
|
+
USE_IBL: false,
|
|
29
|
+
PBR_DEBUG: false
|
|
30
30
|
},
|
|
31
31
|
getUniforms: props => props,
|
|
32
32
|
uniformTypes: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pbr-material.js","sourceRoot":"","sources":["../../../../src/modules/lighting/pbr-material/pbr-material.ts"],"names":[],"mappings":"AAAA,UAAU;AACV,+BAA+B;AAC/B,oCAAoC;AAepC,OAAO,EAAC,QAAQ,EAAC,8BAA2B;AAE5C,OAAO,EAAC,EAAE,EAAC
|
|
1
|
+
{"version":3,"file":"pbr-material.js","sourceRoot":"","sources":["../../../../src/modules/lighting/pbr-material/pbr-material.ts"],"names":[],"mappings":"AAAA,UAAU;AACV,+BAA+B;AAC/B,oCAAoC;AAepC,OAAO,EAAC,QAAQ,EAAC,8BAA2B;AAE5C,OAAO,EAAC,EAAE,EAAE,EAAE,EAAC,+BAA4B;AAC3C,OAAO,EAAC,MAAM,EAAC,+BAA4B;AAC3C,OAAO,EAAC,aAAa,EAAC,4BAAyB;AAmD/C;;;GAGG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG;IACzB,KAAK,EAAE,EAAsB;IAC7B,QAAQ,EAAE,EAAyB;IAEnC,IAAI,EAAE,aAAa;IACnB,YAAY,EAAE,CAAC,QAAQ,EAAE,aAAa,CAAC;IACvC,MAAM;IACN,EAAE;IACF,EAAE;IAEF,OAAO,EAAE;QACP,iBAAiB,EAAE,IAAI;QACvB,aAAa,EAAE,KAAK;QACpB,eAAe,EAAE,KAAK;QACtB,gBAAgB,EAAE,KAAK;QACvB,gBAAgB,EAAE,KAAK;QACvB,qBAAqB,EAAE,KAAK;QAC5B,YAAY,EAAE,KAAK;QACnB,OAAO,EAAE,KAAK;QACd,SAAS,EAAE,KAAK;KACjB;IACD,WAAW,EAAE,KAAK,CAAC,EAAE,CAAC,KAAK;IAC3B,YAAY,EAAE;QACZ,oBAAoB;QACpB,KAAK,EAAE,KAAK;QAEZ,iBAAiB;QACjB,mBAAmB,EAAE,KAAK;QAC1B,eAAe,EAAE,WAAW;QAE5B,gBAAgB,EAAE,KAAK;QACvB,WAAW,EAAE,KAAK,EAAE,uBAAuB;QAE3C,kBAAkB,EAAE,KAAK;QACzB,cAAc,EAAE,WAAW,EAAE,yBAAyB;QAEtD,uBAAuB,EAAE,WAAW;QACpC,2BAA2B,EAAE,KAAK;QAElC,mBAAmB,EAAE,KAAK;QAC1B,iBAAiB,EAAE,KAAK,EAAE,0BAA0B;QAEpD,kBAAkB,EAAE,KAAK;QACzB,WAAW,EAAE,KAAK,EAAE,sBAAsB;QAE1C,MAAM;QACN,UAAU,EAAE,KAAK;QACjB,eAAe,EAAE,WAAW,EAAE,iBAAiB;QAE/C,uEAAuE;QACvE,mBAAmB;QACnB,eAAe,EAAE,WAAW;QAC5B,YAAY,EAAE,WAAW;KAC1B;CAC0F,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pbr-projection.d.ts","sourceRoot":"","sources":["../../../../src/modules/lighting/pbr-material/pbr-projection.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"pbr-projection.d.ts","sourceRoot":"","sources":["../../../../src/modules/lighting/pbr-material/pbr-projection.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,YAAY,EAAE,aAAa,EAAC,MAAM,eAAe,CAAC;AAE/D,OAAO,EAAC,YAAY,EAAC,oDAAiD;AAWtE,MAAM,MAAM,kBAAkB,GAAG;IAC/B,yBAAyB,EAAE,aAAa,CAAC;IACzC,WAAW,EAAE,aAAa,CAAC;IAC3B,YAAY,EAAE,aAAa,CAAC;IAC5B,MAAM,EAAE,YAAY,CAAC;CACtB,CAAC;AAEF,eAAO,MAAM,aAAa,EAAE,YAAY,CAAC,kBAAkB,CAY1D,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pbr-projection.js","sourceRoot":"","sources":["../../../../src/modules/lighting/pbr-material/pbr-projection.ts"],"names":[],"mappings":"AAAA,UAAU;AACV,+BAA+B;AAC/B,oCAAoC;
|
|
1
|
+
{"version":3,"file":"pbr-projection.js","sourceRoot":"","sources":["../../../../src/modules/lighting/pbr-material/pbr-projection.ts"],"names":[],"mappings":"AAAA,UAAU;AACV,+BAA+B;AAC/B,oCAAoC;AAMpC,MAAM,YAAY,GAAG,UAAU,CAAC;;;;;;;CAO/B,CAAC;AASF,MAAM,CAAC,MAAM,aAAa,GAAqC;IAC7D,IAAI,EAAE,eAAe;IACrB,EAAE,EAAE,YAAY;IAChB,EAAE,EAAE,YAAY;IAChB,2BAA2B;IAC3B,WAAW,EAAE,KAAK,CAAC,EAAE,CAAC,KAAK;IAC3B,YAAY,EAAE;QACZ,yBAAyB,EAAE,aAAa;QACxC,WAAW,EAAE,aAAa;QAC1B,YAAY,EAAE,aAAa;QAC3B,MAAM,EAAE,WAAW;KACpB;CACF,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"phong-material.js","sourceRoot":"","sources":["../../../../src/modules/lighting/phong-material/phong-material.ts"],"names":[],"mappings":"AAAA,UAAU;AACV,+BAA+B;AAC/B,oCAAoC;AAIpC,OAAO,EAAC,QAAQ,EAAC,8BAA2B;AAC5C,OAAO,EAAC,UAAU,EAAC,gCAA6B;AAChD,OAAO,EAAC,QAAQ,EAAE,QAAQ,EAAC,gCAA6B;AAUxD,wIAAwI;AACxI,MAAM,CAAC,MAAM,aAAa,GAAqC;IAC7D,IAAI,EAAE,eAAe;IACrB,YAAY,EAAE,CAAC,QAAQ,CAAC;IACxB,oDAAoD;IACpD,MAAM,EAAE,UAAU;IAClB,EAAE,EAAE,QAAQ;IACZ,EAAE,EAAE,QAAQ;IACZ,OAAO,EAAE;QACP,iBAAiB,EAAE,
|
|
1
|
+
{"version":3,"file":"phong-material.js","sourceRoot":"","sources":["../../../../src/modules/lighting/phong-material/phong-material.ts"],"names":[],"mappings":"AAAA,UAAU;AACV,+BAA+B;AAC/B,oCAAoC;AAIpC,OAAO,EAAC,QAAQ,EAAC,8BAA2B;AAC5C,OAAO,EAAC,UAAU,EAAC,gCAA6B;AAChD,OAAO,EAAC,QAAQ,EAAE,QAAQ,EAAC,gCAA6B;AAUxD,wIAAwI;AACxI,MAAM,CAAC,MAAM,aAAa,GAAqC;IAC7D,IAAI,EAAE,eAAe;IACrB,YAAY,EAAE,CAAC,QAAQ,CAAC;IACxB,oDAAoD;IACpD,MAAM,EAAE,UAAU;IAClB,EAAE,EAAE,QAAQ;IACZ,EAAE,EAAE,QAAQ;IACZ,OAAO,EAAE;QACP,iBAAiB,EAAE,IAAI;KACxB;IACD,YAAY,EAAE;QACZ,OAAO,EAAE,KAAK;QACd,OAAO,EAAE,KAAK;QACd,SAAS,EAAE,KAAK;QAChB,aAAa,EAAE,WAAW;KAC3B;IACD,eAAe,EAAE;QACf,OAAO,EAAE,IAAI;QACb,OAAO,EAAE,GAAG;QACZ,SAAS,EAAE,EAAE;QACb,aAAa,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC;KAClC;IACD,WAAW,CAAC,KAA0B;QACpC,MAAM,QAAQ,GAAG,EAAC,GAAG,KAAK,EAAC,CAAC;QAC5B,IAAI,QAAQ,CAAC,aAAa,EAAE,CAAC;YAC3B,QAAQ,CAAC,aAAa,GAAG,QAAQ,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,GAAG,CAAiB,CAAC;QACpF,CAAC;QACD,OAAO,EAAC,GAAG,aAAa,CAAC,eAAe,EAAE,GAAG,QAAQ,EAAC,CAAC;IACzD,CAAC;CACF,CAAC"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export declare const PHONG_VS = "uniform phongMaterialUniforms {\n uniform float ambient;\n uniform float diffuse;\n uniform float shininess;\n uniform vec3 specularColor;\n} material;\n";
|
|
2
|
-
export declare const PHONG_FS = "
|
|
2
|
+
export declare const PHONG_FS = "#define MAX_LIGHTS 1\n\nuniform phongMaterialUniforms {\n uniform float ambient;\n uniform float diffuse;\n uniform float shininess;\n uniform vec3 specularColor;\n} material;\n\nvec3 lighting_getLightColor(vec3 surfaceColor, vec3 light_direction, vec3 view_direction, vec3 normal_worldspace, vec3 color) {\n vec3 halfway_direction = normalize(light_direction + view_direction);\n float lambertian = dot(light_direction, normal_worldspace);\n float specular = 0.0;\n if (lambertian > 0.0) {\n float specular_angle = max(dot(normal_worldspace, halfway_direction), 0.0);\n specular = pow(specular_angle, material.shininess);\n }\n lambertian = max(lambertian, 0.0);\n return (lambertian * material.diffuse * surfaceColor + specular * material.specularColor) * color;\n}\n\nvec3 lighting_getLightColor(vec3 surfaceColor, vec3 cameraPosition, vec3 position_worldspace, vec3 normal_worldspace) {\n vec3 lightColor = surfaceColor;\n\n if (lighting.enabled == 0) {\n return lightColor;\n }\n\n vec3 view_direction = normalize(cameraPosition - position_worldspace);\n lightColor = material.ambient * surfaceColor * lighting.ambientColor;\n\n for (int i = 0; i < lighting.pointLightCount; i++) {\n PointLight pointLight = lighting_getPointLight(i);\n vec3 light_position_worldspace = pointLight.position;\n vec3 light_direction = normalize(light_position_worldspace - position_worldspace);\n float light_attenuation = getPointLightAttenuation(pointLight, distance(light_position_worldspace, position_worldspace));\n lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color / light_attenuation);\n }\n\n int totalLights = min(MAX_LIGHTS, lighting.pointLightCount + lighting.directionalLightCount);\n for (int i = lighting.pointLightCount; i < totalLights; i++) {\n DirectionalLight directionalLight = lighting_getDirectionalLight(i);\n lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color);\n }\n \n return lightColor;\n}\n";
|
|
3
3
|
//# sourceMappingURL=phong-shaders-glsl.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"phong-shaders-glsl.d.ts","sourceRoot":"","sources":["../../../../src/modules/lighting/phong-material/phong-shaders-glsl.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,QAAQ,mKAOpB,CAAC;AAEF,eAAO,MAAM,QAAQ,
|
|
1
|
+
{"version":3,"file":"phong-shaders-glsl.d.ts","sourceRoot":"","sources":["../../../../src/modules/lighting/phong-material/phong-shaders-glsl.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,QAAQ,mKAOpB,CAAC;AAEF,eAAO,MAAM,QAAQ,wkEAgDpB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"phong-shaders-glsl.js","sourceRoot":"","sources":["../../../../src/modules/lighting/phong-material/phong-shaders-glsl.ts"],"names":[],"mappings":"AAAA,UAAU;AACV,+BAA+B;AAC/B,oCAAoC;AAEpC,MAAM,CAAC,MAAM,QAAQ,GAAG,UAAU,CAAC;;;;;;;CAOlC,CAAC;AAEF,MAAM,CAAC,MAAM,QAAQ,GAAG,UAAU,CAAC
|
|
1
|
+
{"version":3,"file":"phong-shaders-glsl.js","sourceRoot":"","sources":["../../../../src/modules/lighting/phong-material/phong-shaders-glsl.ts"],"names":[],"mappings":"AAAA,UAAU;AACV,+BAA+B;AAC/B,oCAAoC;AAEpC,MAAM,CAAC,MAAM,QAAQ,GAAG,UAAU,CAAC;;;;;;;CAOlC,CAAC;AAEF,MAAM,CAAC,MAAM,QAAQ,GAAG,UAAU,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAgDlC,CAAC"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/** Quick random generator for fragment shaders */
|
|
2
2
|
export declare const random: {
|
|
3
3
|
readonly name: "random";
|
|
4
|
+
readonly source: "fn random(scale: vec3f, seed: float) -> f32 {\n /* use the fragment position for a different seed per-pixel */\n return fract(sin(dot(gl_FragCoord.xyz + seed, scale)) * 43758.5453 + seed);\n}\n";
|
|
4
5
|
readonly fs: "float random(vec3 scale, float seed) {\n /* use the fragment position for a different seed per-pixel */\n return fract(sin(dot(gl_FragCoord.xyz + seed, scale)) * 43758.5453 + seed);\n}\n";
|
|
5
6
|
};
|
|
6
7
|
//# sourceMappingURL=random.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"random.d.ts","sourceRoot":"","sources":["../../../../src/modules/math/random/random.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"random.d.ts","sourceRoot":"","sources":["../../../../src/modules/math/random/random.ts"],"names":[],"mappings":"AAoBA,kDAAkD;AAClD,eAAO,MAAM,MAAM;;;;CAIsB,CAAC"}
|
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
// luma.gl
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
|
+
const source = /* wgsl */ `\
|
|
5
|
+
fn random(scale: vec3f, seed: float) -> f32 {
|
|
6
|
+
/* use the fragment position for a different seed per-pixel */
|
|
7
|
+
return fract(sin(dot(gl_FragCoord.xyz + seed, scale)) * 43758.5453 + seed);
|
|
8
|
+
}
|
|
9
|
+
`;
|
|
4
10
|
const fs = /* glsl */ `\
|
|
5
11
|
float random(vec3 scale, float seed) {
|
|
6
12
|
/* use the fragment position for a different seed per-pixel */
|
|
@@ -10,6 +16,7 @@ float random(vec3 scale, float seed) {
|
|
|
10
16
|
/** Quick random generator for fragment shaders */
|
|
11
17
|
export const random = {
|
|
12
18
|
name: 'random',
|
|
19
|
+
source,
|
|
13
20
|
fs
|
|
14
21
|
};
|
|
15
22
|
//# sourceMappingURL=random.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"random.js","sourceRoot":"","sources":["../../../../src/modules/math/random/random.ts"],"names":[],"mappings":"AAAA,UAAU;AACV,+BAA+B;AAC/B,oCAAoC;AAIpC,MAAM,EAAE,GAAG,UAAU,CAAC;;;;;CAKrB,CAAC;AAEF,kDAAkD;AAClD,MAAM,CAAC,MAAM,MAAM,GAAG;IACpB,IAAI,EAAE,QAAQ;IACd,EAAE;CACqC,CAAC"}
|
|
1
|
+
{"version":3,"file":"random.js","sourceRoot":"","sources":["../../../../src/modules/math/random/random.ts"],"names":[],"mappings":"AAAA,UAAU;AACV,+BAA+B;AAC/B,oCAAoC;AAIpC,MAAM,MAAM,GAAG,UAAU,CAAC;;;;;CAKzB,CAAC;AAEF,MAAM,EAAE,GAAG,UAAU,CAAC;;;;;CAKrB,CAAC;AAEF,kDAAkD;AAClD,MAAM,CAAC,MAAM,MAAM,GAAG;IACpB,IAAI,EAAE,QAAQ;IACd,MAAM;IACN,EAAE;CACqC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@luma.gl/shadertools",
|
|
3
|
-
"version": "9.
|
|
3
|
+
"version": "9.2.0-alpha.2",
|
|
4
4
|
"description": "Shader module system for luma.gl",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -46,12 +46,12 @@
|
|
|
46
46
|
"prepublishOnly": "npm run build-minified-bundle && npm run build-dev-bundle"
|
|
47
47
|
},
|
|
48
48
|
"peerDependencies": {
|
|
49
|
-
"@luma.gl/core": "
|
|
49
|
+
"@luma.gl/core": "9.2.0-alpha.1"
|
|
50
50
|
},
|
|
51
51
|
"dependencies": {
|
|
52
52
|
"@math.gl/core": "^4.1.0",
|
|
53
53
|
"@math.gl/types": "^4.1.0",
|
|
54
54
|
"wgsl_reflect": "^1.2.0"
|
|
55
55
|
},
|
|
56
|
-
"gitHead": "
|
|
56
|
+
"gitHead": "dc1e71675ea19a4afbb59d3b9dcd3b01deea3cae"
|
|
57
57
|
}
|
package/src/index.ts
CHANGED
|
@@ -90,20 +90,3 @@ export type {
|
|
|
90
90
|
export type {PBRProjectionProps} from './modules/lighting/pbr-material/pbr-projection';
|
|
91
91
|
|
|
92
92
|
export {pbrMaterial} from './modules/lighting/pbr-material/pbr-material';
|
|
93
|
-
|
|
94
|
-
// DEPRECATED - v8 legacy shader modules (non-uniform buffer)
|
|
95
|
-
|
|
96
|
-
// math libraries
|
|
97
|
-
// export {fp64, fp64arithmetic} from './modules-webgl1/math/fp64/fp64';
|
|
98
|
-
|
|
99
|
-
// projection and lighting
|
|
100
|
-
export {geometry as geometry1} from './modules-webgl1/geometry/geometry';
|
|
101
|
-
export {project as project1} from './modules-webgl1/project/project';
|
|
102
|
-
|
|
103
|
-
export {lights as lights1} from './modules-webgl1/lighting/lights/lights';
|
|
104
|
-
export {dirlight as dirlight1} from './modules-webgl1/lighting/dirlight/dirlight';
|
|
105
|
-
export {
|
|
106
|
-
gouraudLighting,
|
|
107
|
-
phongLighting
|
|
108
|
-
} from './modules-webgl1/lighting/phong-lighting/phong-lighting';
|
|
109
|
-
export {pbr} from './modules-webgl1/lighting/pbr/pbr';
|
|
@@ -14,9 +14,6 @@ import {ShaderHook, normalizeShaderHooks, getShaderHooks} from './shader-hooks';
|
|
|
14
14
|
import {assert} from '../utils/assert';
|
|
15
15
|
import {getShaderInfo} from '../glsl-utils/get-shader-info';
|
|
16
16
|
|
|
17
|
-
/** Define map */
|
|
18
|
-
export type ShaderDefine = string | number | boolean;
|
|
19
|
-
|
|
20
17
|
const INJECT_SHADER_DECLARATIONS = `\n\n${DECLARATION_INJECT_MARKER}\n`;
|
|
21
18
|
|
|
22
19
|
/**
|
|
@@ -48,7 +45,9 @@ export type AssembleShaderOptions = {
|
|
|
48
45
|
/** Modules to be injected */
|
|
49
46
|
modules?: ShaderModule[];
|
|
50
47
|
/** Defines to be injected */
|
|
51
|
-
defines?: Record<string,
|
|
48
|
+
defines?: Record<string, boolean>;
|
|
49
|
+
/** GLSL only: Overrides to be injected. In WGSL these are supplied during Pipeline creation time */
|
|
50
|
+
constants?: Record<string, number>;
|
|
52
51
|
/** Hook functions */
|
|
53
52
|
hookFunctions?: (ShaderHook | string)[];
|
|
54
53
|
/** Code injections */
|
|
@@ -68,7 +67,9 @@ type AssembleStageOptions = {
|
|
|
68
67
|
/** Modules to be injected */
|
|
69
68
|
modules: any[];
|
|
70
69
|
/** Defines to be injected */
|
|
71
|
-
defines?: Record<string,
|
|
70
|
+
defines?: Record<string, boolean>;
|
|
71
|
+
/** GLSL only: Overrides to be injected. In WGSL these are supplied during Pipeline creation time */
|
|
72
|
+
constants?: Record<string, number>;
|
|
72
73
|
/** Hook functions */
|
|
73
74
|
hookFunctions?: (ShaderHook | string)[];
|
|
74
75
|
/** Code injections */
|
|
@@ -280,7 +281,7 @@ function assembleShaderGLSL(
|
|
|
280
281
|
language?: 'glsl' | 'wgsl';
|
|
281
282
|
stage: 'vertex' | 'fragment';
|
|
282
283
|
modules: ShaderModule[];
|
|
283
|
-
defines?: Record<string,
|
|
284
|
+
defines?: Record<string, boolean>;
|
|
284
285
|
hookFunctions?: any[];
|
|
285
286
|
inject?: Record<string, string | ShaderInjection>;
|
|
286
287
|
prologue?: boolean;
|
|
@@ -288,7 +289,6 @@ function assembleShaderGLSL(
|
|
|
288
289
|
}
|
|
289
290
|
) {
|
|
290
291
|
const {
|
|
291
|
-
id,
|
|
292
292
|
source,
|
|
293
293
|
stage,
|
|
294
294
|
language = 'glsl',
|
|
@@ -331,7 +331,6 @@ function assembleShaderGLSL(
|
|
|
331
331
|
${sourceVersionDirective}
|
|
332
332
|
|
|
333
333
|
// ----- PROLOGUE -------------------------
|
|
334
|
-
${getShaderNameDefine({id, source, stage})}
|
|
335
334
|
${`#define SHADER_TYPE_${stage.toUpperCase()}`}
|
|
336
335
|
|
|
337
336
|
${getPlatformShaderDefines(platformInfo)}
|
|
@@ -443,11 +442,12 @@ export function assembleGetUniforms(modules: ShaderModule[]) {
|
|
|
443
442
|
}
|
|
444
443
|
|
|
445
444
|
/**
|
|
445
|
+
* NOTE: Removed as id injection defeated caching of shaders
|
|
446
|
+
*
|
|
446
447
|
* Generate "glslify-compatible" SHADER_NAME defines
|
|
447
448
|
* These are understood by the GLSL error parsing function
|
|
448
449
|
* If id is provided and no SHADER_NAME constant is present in source, create one
|
|
449
|
-
|
|
450
|
-
function getShaderNameDefine(options: {
|
|
450
|
+
unction getShaderNameDefine(options: {
|
|
451
451
|
id?: string;
|
|
452
452
|
source: string;
|
|
453
453
|
stage: 'vertex' | 'fragment';
|
|
@@ -459,9 +459,10 @@ function getShaderNameDefine(options: {
|
|
|
459
459
|
#define SHADER_NAME ${id}_${stage}`
|
|
460
460
|
: '';
|
|
461
461
|
}
|
|
462
|
+
*/
|
|
462
463
|
|
|
463
464
|
/** Generates application defines from an object of key value pairs */
|
|
464
|
-
function getApplicationDefines(defines: Record<string,
|
|
465
|
+
function getApplicationDefines(defines: Record<string, boolean> = {}): string {
|
|
465
466
|
let sourceText = '';
|
|
466
467
|
for (const define in defines) {
|
|
467
468
|
const value = defines[define];
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
*/
|
|
10
10
|
export type PlatformInfo = {
|
|
11
11
|
/** Current Web GPU API backend */
|
|
12
|
-
type: 'webgl' | 'webgpu' | 'unknown';
|
|
12
|
+
type: 'webgl' | 'webgpu' | 'null' | 'unknown';
|
|
13
13
|
/** Which shader language is supported */
|
|
14
14
|
shaderLanguage: 'glsl' | 'wgsl';
|
|
15
15
|
/** Which shader language version is preferred */
|
|
@@ -69,7 +69,7 @@ export type ShaderModule<
|
|
|
69
69
|
prevUniforms?: UniformsT
|
|
70
70
|
) => Partial<UniformsT & BindingsT>;
|
|
71
71
|
|
|
72
|
-
defines?: Record<string,
|
|
72
|
+
defines?: Record<string, boolean>;
|
|
73
73
|
/** Injections */
|
|
74
74
|
inject?: Record<string, string | {injection: string; order: number}>;
|
|
75
75
|
dependencies?: ShaderModule<any, any>[];
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
4
|
|
|
5
|
-
import {
|
|
6
|
-
import {WgslReflect} from 'wgsl_reflect';
|
|
5
|
+
import {AttributeShaderType, ShaderLayout, log} from '@luma.gl/core';
|
|
6
|
+
import {TypeInfo, WgslReflect} from 'wgsl_reflect';
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* Parse a ShaderLayout from WGSL shader source code.
|
|
@@ -23,7 +23,8 @@ export function getShaderLayoutFromWGSL(source: string): ShaderLayout {
|
|
|
23
23
|
|
|
24
24
|
for (const uniform of parsedWGSL.uniforms) {
|
|
25
25
|
const members = [];
|
|
26
|
-
|
|
26
|
+
// @ts-expect-error
|
|
27
|
+
for (const attribute of uniform.type?.members || []) {
|
|
27
28
|
members.push({
|
|
28
29
|
name: attribute.name,
|
|
29
30
|
type: getType(attribute.type)
|
|
@@ -80,8 +81,9 @@ export function getShaderLayoutFromWGSL(source: string): ShaderLayout {
|
|
|
80
81
|
}
|
|
81
82
|
|
|
82
83
|
/** Get a valid shader attribute type string from a wgsl-reflect type */
|
|
83
|
-
function getType(type:
|
|
84
|
-
|
|
84
|
+
function getType(type: TypeInfo | null): AttributeShaderType {
|
|
85
|
+
// @ts-expect-error WgslReflect type checks needed
|
|
86
|
+
return type?.format ? `${type.name}<${type.format.name}>` : type.name;
|
|
85
87
|
}
|
|
86
88
|
|
|
87
89
|
function parseWGSL(source: string): WgslReflect {
|
|
@@ -44,7 +44,7 @@ function getUniforms(
|
|
|
44
44
|
// viewInverseMatrix: view.invert(),
|
|
45
45
|
// viewProjectionInverseMatrix: viewProjectionInverse
|
|
46
46
|
|
|
47
|
-
const uniforms:
|
|
47
|
+
const uniforms: ProjectionUniforms = {};
|
|
48
48
|
if (opts.viewMatrix !== undefined) {
|
|
49
49
|
uniforms.viewMatrix = opts.viewMatrix;
|
|
50
50
|
}
|
|
@@ -54,11 +54,14 @@ function getUniforms(
|
|
|
54
54
|
if (opts.cameraPositionWorld !== undefined) {
|
|
55
55
|
uniforms.cameraPositionWorld = opts.cameraPositionWorld;
|
|
56
56
|
}
|
|
57
|
+
|
|
57
58
|
// COMPOSITE UNIFORMS
|
|
58
|
-
if (opts.projectionMatrix !== undefined
|
|
59
|
-
|
|
60
|
-
uniforms.
|
|
61
|
-
|
|
59
|
+
if (opts.projectionMatrix !== undefined) {
|
|
60
|
+
if (opts.viewMatrix !== undefined) {
|
|
61
|
+
uniforms.viewProjectionMatrix = new Matrix4(uniforms.projectionMatrix).multiplyRight(
|
|
62
|
+
opts.viewMatrix
|
|
63
|
+
);
|
|
64
|
+
}
|
|
62
65
|
}
|
|
63
66
|
|
|
64
67
|
return uniforms;
|
|
@@ -26,7 +26,7 @@ export const gouraudMaterial: ShaderModule<GouraudMaterialProps> = {
|
|
|
26
26
|
fs: PHONG_VS.replace('phongMaterial', 'gouraudMaterial'),
|
|
27
27
|
source: PHONG_WGSL.replaceAll('phongMaterial', 'gouraudMaterial'),
|
|
28
28
|
defines: {
|
|
29
|
-
LIGHTING_VERTEX:
|
|
29
|
+
LIGHTING_VERTEX: true
|
|
30
30
|
},
|
|
31
31
|
dependencies: [lighting],
|
|
32
32
|
uniformTypes: {
|
|
@@ -4,12 +4,12 @@
|
|
|
4
4
|
|
|
5
5
|
import {log} from '@luma.gl/core';
|
|
6
6
|
import {ShaderModule} from '../../../lib/shader-module/shader-module';
|
|
7
|
-
import {lightingUniformsGLSL} from './lighting-
|
|
8
|
-
import {lightingUniformsWGSL} from './lighting-
|
|
7
|
+
import {lightingUniformsGLSL} from './lighting-glsl';
|
|
8
|
+
import {lightingUniformsWGSL} from './lighting-wgsl';
|
|
9
9
|
import type {NumberArray3} from '@math.gl/core';
|
|
10
10
|
|
|
11
11
|
/** Max number of supported lights (in addition to ambient light */
|
|
12
|
-
const MAX_LIGHTS =
|
|
12
|
+
const MAX_LIGHTS = 5;
|
|
13
13
|
|
|
14
14
|
/** Whether to divide */
|
|
15
15
|
const COLOR_FACTOR = 255.0;
|
|
@@ -85,7 +85,7 @@ export const lighting = {
|
|
|
85
85
|
name: 'lighting',
|
|
86
86
|
|
|
87
87
|
defines: {
|
|
88
|
-
MAX_LIGHTS
|
|
88
|
+
// MAX_LIGHTS
|
|
89
89
|
},
|
|
90
90
|
|
|
91
91
|
uniformTypes: {
|
|
@@ -91,10 +91,9 @@ export const dirlight = {
|
|
|
91
91
|
} as const satisfies ShaderModule<DirlightProps, DirlightUniforms>;
|
|
92
92
|
|
|
93
93
|
function getUniforms(opts: DirlightProps = dirlight.defaultUniforms): DirlightUniforms {
|
|
94
|
-
const uniforms:
|
|
94
|
+
const uniforms: DirlightUniforms = {};
|
|
95
95
|
if (opts.lightDirection) {
|
|
96
|
-
|
|
97
|
-
uniforms.dirlight_uLightDirection = opts.lightDirection;
|
|
96
|
+
uniforms.lightDirection = opts.lightDirection;
|
|
98
97
|
}
|
|
99
98
|
return uniforms;
|
|
100
99
|
}
|
|
@@ -4,12 +4,47 @@
|
|
|
4
4
|
|
|
5
5
|
// Attribution:
|
|
6
6
|
// MIT license, Copyright (c) 2016-2017 Mohamad Moneimne and Contributors
|
|
7
|
-
|
|
8
7
|
// This fragment shader defines a reference implementation for Physically Based Shading of
|
|
9
8
|
// a microfacet surface material defined by a glTF model.
|
|
10
9
|
|
|
11
10
|
// TODO - better do the checks outside of shader
|
|
12
11
|
|
|
12
|
+
export const vs = /* glsl */ `\
|
|
13
|
+
out vec3 pbr_vPosition;
|
|
14
|
+
out vec2 pbr_vUV;
|
|
15
|
+
|
|
16
|
+
#ifdef HAS_NORMALS
|
|
17
|
+
# ifdef HAS_TANGENTS
|
|
18
|
+
out mat3 pbr_vTBN;
|
|
19
|
+
# else
|
|
20
|
+
out vec3 pbr_vNormal;
|
|
21
|
+
# endif
|
|
22
|
+
#endif
|
|
23
|
+
|
|
24
|
+
void pbr_setPositionNormalTangentUV(vec4 position, vec4 normal, vec4 tangent, vec2 uv)
|
|
25
|
+
{
|
|
26
|
+
vec4 pos = pbrProjection.modelMatrix * position;
|
|
27
|
+
pbr_vPosition = vec3(pos.xyz) / pos.w;
|
|
28
|
+
|
|
29
|
+
#ifdef HAS_NORMALS
|
|
30
|
+
#ifdef HAS_TANGENTS
|
|
31
|
+
vec3 normalW = normalize(vec3(pbrProjection.normalMatrix * vec4(normal.xyz, 0.0)));
|
|
32
|
+
vec3 tangentW = normalize(vec3(pbrProjection.modelMatrix * vec4(tangent.xyz, 0.0)));
|
|
33
|
+
vec3 bitangentW = cross(normalW, tangentW) * tangent.w;
|
|
34
|
+
pbr_vTBN = mat3(tangentW, bitangentW, normalW);
|
|
35
|
+
#else // HAS_TANGENTS != 1
|
|
36
|
+
pbr_vNormal = normalize(vec3(pbrProjection.modelMatrix * vec4(normal.xyz, 0.0)));
|
|
37
|
+
#endif
|
|
38
|
+
#endif
|
|
39
|
+
|
|
40
|
+
#ifdef HAS_UV
|
|
41
|
+
pbr_vUV = uv;
|
|
42
|
+
#else
|
|
43
|
+
pbr_vUV = vec2(0.,0.);
|
|
44
|
+
#endif
|
|
45
|
+
}
|
|
46
|
+
`;
|
|
47
|
+
|
|
13
48
|
export const fs = /* glsl */ `\
|
|
14
49
|
precision highp float;
|
|
15
50
|
|