@luma.gl/shadertools 9.1.0-alpha.1 → 9.1.0-alpha.12
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 +1005 -487
- package/dist/dist.min.js +2489 -1625
- package/dist/index.cjs +2864 -1817
- package/dist/index.cjs.map +4 -4
- package/dist/index.d.ts +29 -28
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -12
- package/dist/lib/glsl-utils/shader-utils.d.ts.map +1 -1
- package/dist/lib/glsl-utils/shader-utils.js +2 -3
- package/dist/lib/shader-assembler.d.ts +3 -4
- package/dist/lib/shader-assembler.d.ts.map +1 -1
- package/dist/lib/shader-assembler.js +3 -2
- package/dist/lib/shader-assembly/assemble-shaders.d.ts +4 -3
- package/dist/lib/shader-assembly/assemble-shaders.d.ts.map +1 -1
- package/dist/lib/shader-assembly/assemble-shaders.js +46 -18
- package/dist/lib/shader-assembly/platform-defines.d.ts.map +1 -1
- package/dist/lib/shader-assembly/platform-defines.js +14 -6
- package/dist/lib/shader-module/shader-module-dependencies.d.ts +53 -0
- package/dist/lib/shader-module/shader-module-dependencies.d.ts.map +1 -0
- package/dist/lib/{shader-assembly/resolve-modules.js → shader-module/shader-module-dependencies.js} +38 -14
- package/dist/lib/shader-module/shader-module.d.ts +30 -12
- package/dist/lib/shader-module/shader-module.d.ts.map +1 -1
- package/dist/lib/shader-module/shader-module.js +76 -6
- package/dist/lib/shader-module/shader-pass.d.ts +3 -2
- package/dist/lib/shader-module/shader-pass.d.ts.map +1 -1
- package/dist/module-injectors.d.ts +2 -2
- package/dist/module-injectors.d.ts.map +1 -1
- package/dist/module-injectors.js +13 -10
- package/dist/modules/engine/geometry/geometry.d.ts.map +1 -1
- package/dist/modules/engine/geometry/geometry.js +12 -8
- package/dist/modules/engine/picking/picking.d.ts +9 -9
- package/dist/modules/engine/picking/picking.d.ts.map +1 -1
- package/dist/modules/engine/picking/picking.js +103 -66
- package/dist/modules/engine/project/project.d.ts +2 -2
- package/dist/modules/engine/project/project.d.ts.map +1 -1
- package/dist/modules/engine/project/project.js +36 -22
- package/dist/modules/engine/transform/transform.d.ts.map +1 -1
- package/dist/modules/engine/transform/transform.js +28 -16
- package/dist/modules/lighting/gouraud-material/gouraud-material.d.ts +10 -7
- package/dist/modules/lighting/gouraud-material/gouraud-material.d.ts.map +1 -1
- package/dist/modules/lighting/gouraud-material/gouraud-material.js +2 -0
- package/dist/modules/lighting/gouraud-material/gouraud-shaders-glsl.d.ts +2 -2
- package/dist/modules/lighting/gouraud-material/gouraud-shaders-glsl.d.ts.map +1 -1
- package/dist/modules/lighting/gouraud-material/gouraud-shaders-glsl.js +79 -53
- package/dist/modules/lighting/lights/lighting-uniforms-glsl.d.ts +1 -1
- package/dist/modules/lighting/lights/lighting-uniforms-glsl.d.ts.map +1 -1
- package/dist/modules/lighting/lights/lighting-uniforms-glsl.js +38 -23
- package/dist/modules/lighting/lights/lighting-uniforms-wgsl.d.ts +2 -0
- package/dist/modules/lighting/lights/lighting-uniforms-wgsl.d.ts.map +1 -0
- package/dist/modules/lighting/lights/lighting-uniforms-wgsl.js +56 -0
- package/dist/modules/lighting/lights/lighting.d.ts +5 -4
- package/dist/modules/lighting/lights/lighting.d.ts.map +1 -1
- package/dist/modules/lighting/lights/lighting.js +7 -5
- package/dist/modules/lighting/no-material/dirlight.d.ts +8 -8
- package/dist/modules/lighting/no-material/dirlight.d.ts.map +1 -1
- package/dist/modules/lighting/no-material/dirlight.js +34 -20
- package/dist/modules/lighting/pbr-material/pbr-fragment-glsl.d.ts +1 -1
- package/dist/modules/lighting/pbr-material/pbr-fragment-glsl.d.ts.map +1 -1
- package/dist/modules/lighting/pbr-material/pbr-fragment-glsl.js +304 -181
- package/dist/modules/lighting/pbr-material/pbr-material.d.ts +72 -69
- package/dist/modules/lighting/pbr-material/pbr-material.d.ts.map +1 -1
- package/dist/modules/lighting/pbr-material/pbr-material.js +4 -2
- package/dist/modules/lighting/pbr-material/pbr-uniforms-glsl.d.ts +1 -1
- package/dist/modules/lighting/pbr-material/pbr-uniforms-glsl.d.ts.map +1 -1
- package/dist/modules/lighting/pbr-material/pbr-uniforms-glsl.js +38 -20
- package/dist/modules/lighting/pbr-material/pbr-vertex-glsl.d.ts +1 -1
- package/dist/modules/lighting/pbr-material/pbr-vertex-glsl.d.ts.map +1 -1
- package/dist/modules/lighting/pbr-material/pbr-vertex-glsl.js +21 -16
- package/dist/modules/lighting/phong-material/phong-material.d.ts +14 -12
- package/dist/modules/lighting/phong-material/phong-material.d.ts.map +1 -1
- package/dist/modules/lighting/phong-material/phong-material.js +5 -3
- package/dist/modules/lighting/phong-material/phong-shaders-glsl.d.ts +2 -2
- package/dist/modules/lighting/phong-material/phong-shaders-glsl.d.ts.map +1 -1
- package/dist/modules/lighting/phong-material/phong-shaders-glsl.js +82 -54
- package/dist/modules/lighting/phong-material/phong-shaders-wgsl.d.ts +41 -0
- package/dist/modules/lighting/phong-material/phong-shaders-wgsl.d.ts.map +1 -0
- package/dist/modules/lighting/phong-material/phong-shaders-wgsl.js +130 -0
- package/dist/modules/math/fp32/fp32.d.ts.map +1 -1
- package/dist/modules/math/fp32/fp32.js +127 -100
- package/dist/modules/math/fp64/fp64-utils.d.ts +3 -3
- package/dist/modules/math/fp64/fp64-utils.d.ts.map +1 -1
- package/dist/modules/math/random/random.d.ts +1 -1
- package/dist/modules/math/random/random.d.ts.map +1 -1
- package/dist/modules/math/random/random.js +3 -3
- package/dist/modules/module-injectors.d.ts +2 -2
- package/dist/modules/module-injectors.d.ts.map +1 -1
- package/dist/modules/module-injectors.js +13 -10
- package/dist/modules/postprocessing/image-adjust-filters/brightnesscontrast.d.ts +4 -1
- package/dist/modules/postprocessing/image-adjust-filters/brightnesscontrast.d.ts.map +1 -1
- package/dist/modules/postprocessing/image-adjust-filters/brightnesscontrast.js +16 -12
- package/dist/modules/postprocessing/image-adjust-filters/denoise.d.ts +4 -1
- package/dist/modules/postprocessing/image-adjust-filters/denoise.d.ts.map +1 -1
- package/dist/modules/postprocessing/image-adjust-filters/denoise.js +21 -17
- package/dist/modules/postprocessing/image-adjust-filters/huesaturation.d.ts +5 -2
- package/dist/modules/postprocessing/image-adjust-filters/huesaturation.d.ts.map +1 -1
- package/dist/modules/postprocessing/image-adjust-filters/huesaturation.js +29 -22
- package/dist/modules/postprocessing/image-adjust-filters/noise.d.ts +4 -1
- package/dist/modules/postprocessing/image-adjust-filters/noise.d.ts.map +1 -1
- package/dist/modules/postprocessing/image-adjust-filters/noise.js +14 -10
- package/dist/modules/postprocessing/image-adjust-filters/sepia.d.ts +4 -1
- package/dist/modules/postprocessing/image-adjust-filters/sepia.d.ts.map +1 -1
- package/dist/modules/postprocessing/image-adjust-filters/sepia.js +17 -12
- package/dist/modules/postprocessing/image-adjust-filters/vibrance.d.ts +4 -1
- package/dist/modules/postprocessing/image-adjust-filters/vibrance.d.ts.map +1 -1
- package/dist/modules/postprocessing/image-adjust-filters/vibrance.js +12 -9
- package/dist/modules/postprocessing/image-adjust-filters/vignette.d.ts +4 -1
- package/dist/modules/postprocessing/image-adjust-filters/vignette.d.ts.map +1 -1
- package/dist/modules/postprocessing/image-adjust-filters/vignette.js +13 -10
- package/dist/modules/postprocessing/image-blur-filters/tiltshift.d.ts +5 -2
- package/dist/modules/postprocessing/image-blur-filters/tiltshift.d.ts.map +1 -1
- package/dist/modules/postprocessing/image-blur-filters/tiltshift.js +40 -26
- package/dist/modules/postprocessing/image-blur-filters/triangleblur.d.ts +5 -2
- package/dist/modules/postprocessing/image-blur-filters/triangleblur.d.ts.map +1 -1
- package/dist/modules/postprocessing/image-blur-filters/triangleblur.js +32 -19
- package/dist/modules/postprocessing/image-blur-filters/zoomblur.d.ts +4 -1
- package/dist/modules/postprocessing/image-blur-filters/zoomblur.d.ts.map +1 -1
- package/dist/modules/postprocessing/image-blur-filters/zoomblur.js +2 -0
- package/dist/modules/postprocessing/image-fun-filters/colorhalftone.d.ts +4 -1
- package/dist/modules/postprocessing/image-fun-filters/colorhalftone.d.ts.map +1 -1
- package/dist/modules/postprocessing/image-fun-filters/colorhalftone.js +31 -27
- package/dist/modules/postprocessing/image-fun-filters/dotscreen.d.ts +4 -1
- package/dist/modules/postprocessing/image-fun-filters/dotscreen.d.ts.map +1 -1
- package/dist/modules/postprocessing/image-fun-filters/dotscreen.js +19 -15
- package/dist/modules/postprocessing/image-fun-filters/edgework.d.ts +8 -5
- package/dist/modules/postprocessing/image-fun-filters/edgework.d.ts.map +1 -1
- package/dist/modules/postprocessing/image-fun-filters/edgework.js +53 -42
- package/dist/modules/postprocessing/image-fun-filters/hexagonalpixelate.d.ts +4 -1
- package/dist/modules/postprocessing/image-fun-filters/hexagonalpixelate.d.ts.map +1 -1
- package/dist/modules/postprocessing/image-fun-filters/hexagonalpixelate.js +41 -33
- package/dist/modules/postprocessing/image-fun-filters/ink.d.ts +4 -1
- package/dist/modules/postprocessing/image-fun-filters/ink.d.ts.map +1 -1
- package/dist/modules/postprocessing/image-fun-filters/ink.js +27 -25
- package/dist/modules/postprocessing/image-fun-filters/magnify.d.ts +2 -1
- package/dist/modules/postprocessing/image-fun-filters/magnify.d.ts.map +1 -1
- package/dist/modules/postprocessing/image-fun-filters/magnify.js +17 -16
- package/dist/modules/postprocessing/image-warp-filters/bulgepinch.d.ts +5 -2
- package/dist/modules/postprocessing/image-warp-filters/bulgepinch.d.ts.map +1 -1
- package/dist/modules/postprocessing/image-warp-filters/bulgepinch.js +24 -20
- package/dist/modules/postprocessing/image-warp-filters/swirl.d.ts +5 -2
- package/dist/modules/postprocessing/image-warp-filters/swirl.d.ts.map +1 -1
- package/dist/modules/postprocessing/image-warp-filters/swirl.js +26 -22
- package/dist/modules/postprocessing/image-warp-filters/warp.d.ts +2 -1
- package/dist/modules/postprocessing/image-warp-filters/warp.d.ts.map +1 -1
- package/dist/modules/postprocessing/image-warp-filters/warp.js +9 -8
- package/dist/modules-webgl1/geometry/geometry.d.ts.map +1 -1
- package/dist/modules-webgl1/geometry/geometry.js +12 -8
- package/dist/modules-webgl1/lighting/dirlight/dirlight.d.ts +2 -2
- package/dist/modules-webgl1/lighting/dirlight/dirlight.d.ts.map +1 -1
- package/dist/modules-webgl1/lighting/dirlight/dirlight.js +8 -5
- package/dist/modules-webgl1/lighting/lights/lights-glsl.d.ts +1 -1
- package/dist/modules-webgl1/lighting/lights/lights-glsl.d.ts.map +1 -1
- package/dist/modules-webgl1/lighting/lights/lights-glsl.js +19 -11
- package/dist/modules-webgl1/lighting/pbr/pbr-fragment-glsl.d.ts +1 -1
- package/dist/modules-webgl1/lighting/pbr/pbr-fragment-glsl.d.ts.map +1 -1
- package/dist/modules-webgl1/lighting/pbr/pbr-fragment-glsl.js +268 -157
- package/dist/modules-webgl1/lighting/pbr/pbr-vertex-glsl.d.ts +1 -1
- package/dist/modules-webgl1/lighting/pbr/pbr-vertex-glsl.d.ts.map +1 -1
- package/dist/modules-webgl1/lighting/pbr/pbr-vertex-glsl.js +16 -12
- package/dist/modules-webgl1/lighting/phong-lighting/phong-lighting-glsl.d.ts +1 -1
- package/dist/modules-webgl1/lighting/phong-lighting/phong-lighting-glsl.d.ts.map +1 -1
- package/dist/modules-webgl1/lighting/phong-lighting/phong-lighting-glsl.js +64 -55
- package/dist/modules-webgl1/math/fp64/fp64-arithmetic-glsl.d.ts +1 -1
- package/dist/modules-webgl1/math/fp64/fp64-arithmetic-glsl.d.ts.map +1 -1
- package/dist/modules-webgl1/math/fp64/fp64-arithmetic-glsl.js +113 -81
- package/dist/modules-webgl1/math/fp64/fp64-functions-glsl.d.ts +1 -1
- package/dist/modules-webgl1/math/fp64/fp64-functions-glsl.d.ts.map +1 -1
- package/dist/modules-webgl1/math/fp64/fp64-functions-glsl.js +588 -433
- package/dist/modules-webgl1/project/project.d.ts +2 -2
- package/dist/modules-webgl1/project/project.d.ts.map +1 -1
- package/dist/modules-webgl1/project/project.js +5 -4
- package/package.json +5 -5
- package/src/index.ts +78 -32
- package/src/lib/glsl-utils/shader-utils.ts +1 -3
- package/src/lib/shader-assembler.ts +7 -8
- package/src/lib/shader-assembly/assemble-shaders.ts +55 -22
- package/src/lib/shader-assembly/platform-defines.ts +5 -6
- package/src/lib/shader-module/shader-module-dependencies.ts +111 -0
- package/src/lib/shader-module/shader-module.ts +134 -19
- package/src/lib/shader-module/shader-pass.ts +3 -2
- package/src/module-injectors.ts +2 -4
- package/src/modules/engine/geometry/geometry.ts +2 -3
- package/src/modules/engine/picking/picking.ts +12 -10
- package/src/modules/engine/project/project.ts +2 -3
- package/src/modules/engine/transform/transform.ts +1 -3
- package/src/modules/lighting/gouraud-material/gouraud-material.ts +4 -0
- package/src/modules/lighting/gouraud-material/gouraud-shaders-glsl.ts +2 -4
- package/src/modules/lighting/lights/lighting-uniforms-glsl.ts +1 -3
- package/src/modules/lighting/lights/lighting-uniforms-wgsl.ts +57 -0
- package/src/modules/lighting/lights/lighting.ts +9 -5
- package/src/modules/lighting/no-material/dirlight.ts +30 -19
- package/src/modules/lighting/pbr-material/pbr-fragment-glsl.ts +1 -2
- package/src/modules/lighting/pbr-material/pbr-material.ts +44 -38
- package/src/modules/lighting/pbr-material/pbr-uniforms-glsl.ts +1 -3
- package/src/modules/lighting/pbr-material/pbr-vertex-glsl.ts +1 -3
- package/src/modules/lighting/phong-material/phong-material.ts +6 -3
- package/src/modules/lighting/phong-material/phong-shaders-glsl.ts +2 -4
- package/src/modules/lighting/phong-material/phong-shaders-wgsl.ts +132 -0
- package/src/modules/math/fp32/fp32.ts +1 -2
- package/src/modules/math/fp64/fp64-utils.ts +3 -3
- package/src/modules/math/random/random.ts +1 -2
- package/src/modules/module-injectors.ts +2 -4
- package/src/modules/postprocessing/image-adjust-filters/brightnesscontrast.ts +6 -2
- package/src/modules/postprocessing/image-adjust-filters/denoise.ts +7 -3
- package/src/modules/postprocessing/image-adjust-filters/huesaturation.ts +9 -4
- package/src/modules/postprocessing/image-adjust-filters/noise.ts +6 -2
- package/src/modules/postprocessing/image-adjust-filters/sepia.ts +6 -2
- package/src/modules/postprocessing/image-adjust-filters/vibrance.ts +5 -2
- package/src/modules/postprocessing/image-adjust-filters/vignette.ts +11 -4
- package/src/modules/postprocessing/image-blur-filters/tiltshift.ts +6 -2
- package/src/modules/postprocessing/image-blur-filters/triangleblur.ts +6 -2
- package/src/modules/postprocessing/image-blur-filters/zoomblur.ts +5 -0
- package/src/modules/postprocessing/image-fun-filters/colorhalftone.ts +6 -2
- package/src/modules/postprocessing/image-fun-filters/dotscreen.ts +6 -2
- package/src/modules/postprocessing/image-fun-filters/edgework.ts +10 -4
- package/src/modules/postprocessing/image-fun-filters/hexagonalpixelate.ts +6 -2
- package/src/modules/postprocessing/image-fun-filters/ink.ts +8 -3
- package/src/modules/postprocessing/image-fun-filters/magnify.ts +3 -2
- package/src/modules/postprocessing/image-warp-filters/bulgepinch.ts +6 -2
- package/src/modules/postprocessing/image-warp-filters/swirl.ts +8 -2
- package/src/modules/postprocessing/image-warp-filters/warp.ts +3 -2
- package/src/modules-webgl1/geometry/geometry.ts +2 -3
- package/src/modules-webgl1/lighting/dirlight/dirlight.ts +3 -4
- package/src/modules-webgl1/lighting/lights/lights-glsl.ts +1 -3
- package/src/modules-webgl1/lighting/pbr/pbr-fragment-glsl.ts +1 -2
- package/src/modules-webgl1/lighting/pbr/pbr-vertex-glsl.ts +1 -3
- package/src/modules-webgl1/lighting/phong-lighting/phong-lighting-glsl.ts +1 -3
- package/src/modules-webgl1/math/fp64/fp64-arithmetic-glsl.ts +1 -3
- package/src/modules-webgl1/math/fp64/fp64-functions-glsl.ts +1 -3
- package/src/modules-webgl1/project/project.ts +1 -2
- package/dist/lib/glsl-utils/highlight.d.ts +0 -6
- package/dist/lib/glsl-utils/highlight.d.ts.map +0 -1
- package/dist/lib/glsl-utils/highlight.js +0 -9
- package/dist/lib/shader-assembly/resolve-modules.d.ts +0 -40
- package/dist/lib/shader-assembly/resolve-modules.d.ts.map +0 -1
- package/dist/lib/shader-module/normalize-shader-module.d.ts +0 -3
- package/dist/lib/shader-module/normalize-shader-module.d.ts.map +0 -1
- package/dist/lib/shader-module/normalize-shader-module.js +0 -14
- package/dist/lib/shader-module/shader-module-instance.d.ts +0 -28
- package/dist/lib/shader-module/shader-module-instance.d.ts.map +0 -1
- package/dist/lib/shader-module/shader-module-instance.js +0 -126
- package/src/lib/glsl-utils/highlight.ts +0 -11
- package/src/lib/shader-assembly/resolve-modules.ts +0 -81
- package/src/lib/shader-module/normalize-shader-module.ts +0 -17
- package/src/lib/shader-module/shader-module-instance.ts +0 -167
|
@@ -6,31 +6,49 @@
|
|
|
6
6
|
// This fragment shader defines a reference implementation for Physically Based Shading of
|
|
7
7
|
// a microfacet surface material defined by a glTF model.
|
|
8
8
|
// TODO - better do the checks outside of shader
|
|
9
|
-
|
|
10
|
-
export const fs = `\
|
|
9
|
+
export const fs = /* glsl */ `\
|
|
11
10
|
precision highp float;
|
|
11
|
+
|
|
12
12
|
uniform Projection {
|
|
13
|
-
|
|
13
|
+
// Projection
|
|
14
|
+
uniform vec3 u_Camera;
|
|
14
15
|
};
|
|
16
|
+
|
|
15
17
|
uniform pbrMaterial {
|
|
16
|
-
|
|
17
|
-
bool
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
18
|
+
// Material is unlit
|
|
19
|
+
bool unlit;
|
|
20
|
+
|
|
21
|
+
// Base color map
|
|
22
|
+
bool baseColorMapEnabled;
|
|
23
|
+
vec4 baseColorFactor;
|
|
24
|
+
|
|
25
|
+
bool normalMapEnabled;
|
|
26
|
+
float normalScale; // #ifdef HAS_NORMALMAP
|
|
27
|
+
|
|
28
|
+
bool emissiveMapEnabled;
|
|
29
|
+
vec3 emissiveFactor; // #ifdef HAS_EMISSIVEMAP
|
|
30
|
+
|
|
31
|
+
vec2 metallicRoughnessValues;
|
|
32
|
+
bool metallicRoughnessMapEnabled;
|
|
33
|
+
|
|
34
|
+
bool occlusionMapEnabled;
|
|
35
|
+
float occlusionStrength; // #ifdef HAS_OCCLUSIONMAP
|
|
36
|
+
|
|
37
|
+
bool alphaCutoffEnabled;
|
|
38
|
+
float alphaCutoff; // #ifdef ALPHA_CUTOFF
|
|
39
|
+
|
|
40
|
+
// IBL
|
|
41
|
+
bool IBLenabled;
|
|
42
|
+
vec2 scaleIBLAmbient; // #ifdef USE_IBL
|
|
43
|
+
|
|
44
|
+
// debugging flags used for shader output of intermediate PBR variables
|
|
45
|
+
// #ifdef PBR_DEBUG
|
|
46
|
+
vec4 scaleDiffBaseMR;
|
|
47
|
+
vec4 scaleFGDSpec;
|
|
48
|
+
// #endif
|
|
33
49
|
} u_pbrMaterial;
|
|
50
|
+
|
|
51
|
+
// Samplers
|
|
34
52
|
#ifdef HAS_BASECOLORMAP
|
|
35
53
|
uniform sampler2D u_BaseColorSampler;
|
|
36
54
|
#endif
|
|
@@ -51,8 +69,12 @@ uniform samplerCube u_DiffuseEnvSampler;
|
|
|
51
69
|
uniform samplerCube u_SpecularEnvSampler;
|
|
52
70
|
uniform sampler2D u_brdfLUT;
|
|
53
71
|
#endif
|
|
72
|
+
|
|
73
|
+
// Inputs from vertex shader
|
|
74
|
+
|
|
54
75
|
varying vec3 pbr_vPosition;
|
|
55
76
|
varying vec2 pbr_vUV;
|
|
77
|
+
|
|
56
78
|
#ifdef HAS_NORMALS
|
|
57
79
|
#ifdef HAS_TANGENTS
|
|
58
80
|
varying mat3 pbr_vTBN;
|
|
@@ -60,233 +82,334 @@ varying mat3 pbr_vTBN;
|
|
|
60
82
|
varying vec3 pbr_vNormal;
|
|
61
83
|
#endif
|
|
62
84
|
#endif
|
|
85
|
+
|
|
86
|
+
// Encapsulate the various inputs used by the various functions in the shading equation
|
|
87
|
+
// We store values in this struct to simplify the integration of alternative implementations
|
|
88
|
+
// of the shading terms, outlined in the Readme.MD Appendix.
|
|
63
89
|
struct PBRInfo {
|
|
64
|
-
float NdotL;
|
|
65
|
-
float NdotV;
|
|
66
|
-
float NdotH;
|
|
67
|
-
float LdotH;
|
|
68
|
-
float VdotH;
|
|
69
|
-
float perceptualRoughness;
|
|
70
|
-
float metalness;
|
|
71
|
-
vec3 reflectance0;
|
|
72
|
-
vec3 reflectance90;
|
|
73
|
-
float alphaRoughness;
|
|
74
|
-
vec3 diffuseColor;
|
|
75
|
-
vec3 specularColor;
|
|
76
|
-
vec3 n;
|
|
77
|
-
vec3 v;
|
|
90
|
+
float NdotL; // cos angle between normal and light direction
|
|
91
|
+
float NdotV; // cos angle between normal and view direction
|
|
92
|
+
float NdotH; // cos angle between normal and half vector
|
|
93
|
+
float LdotH; // cos angle between light direction and half vector
|
|
94
|
+
float VdotH; // cos angle between view direction and half vector
|
|
95
|
+
float perceptualRoughness; // roughness value, as authored by the model creator (input to shader)
|
|
96
|
+
float metalness; // metallic value at the surface
|
|
97
|
+
vec3 reflectance0; // full reflectance color (normal incidence angle)
|
|
98
|
+
vec3 reflectance90; // reflectance color at grazing angle
|
|
99
|
+
float alphaRoughness; // roughness mapped to a more linear change in the roughness (proposed by [2])
|
|
100
|
+
vec3 diffuseColor; // color contribution from diffuse lighting
|
|
101
|
+
vec3 specularColor; // color contribution from specular lighting
|
|
102
|
+
vec3 n; // normal at surface point
|
|
103
|
+
vec3 v; // vector from surface point to camera
|
|
78
104
|
};
|
|
105
|
+
|
|
79
106
|
const float M_PI = 3.141592653589793;
|
|
80
107
|
const float c_MinRoughness = 0.04;
|
|
108
|
+
|
|
81
109
|
vec4 SRGBtoLINEAR(vec4 srgbIn)
|
|
82
110
|
{
|
|
83
111
|
#ifdef MANUAL_SRGB
|
|
84
112
|
#ifdef SRGB_FAST_APPROXIMATION
|
|
85
|
-
vec3 linOut = pow(srgbIn.xyz,vec3(2.2));
|
|
86
|
-
#else
|
|
87
|
-
vec3 bLess = step(vec3(0.04045),srgbIn.xyz);
|
|
88
|
-
vec3 linOut = mix( srgbIn.xyz/vec3(12.92), pow((srgbIn.xyz+vec3(0.055))/vec3(1.055),vec3(2.4)), bLess );
|
|
89
|
-
#endif
|
|
90
|
-
return vec4(linOut,srgbIn.w);;
|
|
91
|
-
#else
|
|
92
|
-
return srgbIn;
|
|
93
|
-
#endif
|
|
113
|
+
vec3 linOut = pow(srgbIn.xyz,vec3(2.2));
|
|
114
|
+
#else // SRGB_FAST_APPROXIMATION
|
|
115
|
+
vec3 bLess = step(vec3(0.04045),srgbIn.xyz);
|
|
116
|
+
vec3 linOut = mix( srgbIn.xyz/vec3(12.92), pow((srgbIn.xyz+vec3(0.055))/vec3(1.055),vec3(2.4)), bLess );
|
|
117
|
+
#endif //SRGB_FAST_APPROXIMATION
|
|
118
|
+
return vec4(linOut,srgbIn.w);;
|
|
119
|
+
#else //MANUAL_SRGB
|
|
120
|
+
return srgbIn;
|
|
121
|
+
#endif //MANUAL_SRGB
|
|
94
122
|
}
|
|
123
|
+
|
|
124
|
+
// Find the normal for this fragment, pulling either from a predefined normal map
|
|
125
|
+
// or from the interpolated mesh normal and tangent attributes.
|
|
95
126
|
vec3 getNormal()
|
|
96
127
|
{
|
|
128
|
+
// Retrieve the tangent space matrix
|
|
97
129
|
#ifndef HAS_TANGENTS
|
|
98
|
-
vec3 pos_dx = dFdx(pbr_vPosition);
|
|
99
|
-
vec3 pos_dy = dFdy(pbr_vPosition);
|
|
100
|
-
vec3 tex_dx = dFdx(vec3(pbr_vUV, 0.0));
|
|
101
|
-
vec3 tex_dy = dFdy(vec3(pbr_vUV, 0.0));
|
|
102
|
-
vec3 t = (tex_dy.t * pos_dx - tex_dx.t * pos_dy) / (tex_dx.s * tex_dy.t - tex_dy.s * tex_dx.t);
|
|
130
|
+
vec3 pos_dx = dFdx(pbr_vPosition);
|
|
131
|
+
vec3 pos_dy = dFdy(pbr_vPosition);
|
|
132
|
+
vec3 tex_dx = dFdx(vec3(pbr_vUV, 0.0));
|
|
133
|
+
vec3 tex_dy = dFdy(vec3(pbr_vUV, 0.0));
|
|
134
|
+
vec3 t = (tex_dy.t * pos_dx - tex_dx.t * pos_dy) / (tex_dx.s * tex_dy.t - tex_dy.s * tex_dx.t);
|
|
135
|
+
|
|
103
136
|
#ifdef HAS_NORMALS
|
|
104
|
-
vec3 ng = normalize(pbr_vNormal);
|
|
137
|
+
vec3 ng = normalize(pbr_vNormal);
|
|
105
138
|
#else
|
|
106
|
-
vec3 ng = cross(pos_dx, pos_dy);
|
|
139
|
+
vec3 ng = cross(pos_dx, pos_dy);
|
|
107
140
|
#endif
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
141
|
+
|
|
142
|
+
t = normalize(t - ng * dot(ng, t));
|
|
143
|
+
vec3 b = normalize(cross(ng, t));
|
|
144
|
+
mat3 tbn = mat3(t, b, ng);
|
|
145
|
+
#else // HAS_TANGENTS
|
|
146
|
+
mat3 tbn = pbr_vTBN;
|
|
113
147
|
#endif
|
|
148
|
+
|
|
114
149
|
#ifdef HAS_NORMALMAP
|
|
115
|
-
vec3 n = texture2D(u_NormalSampler, pbr_vUV).rgb;
|
|
116
|
-
n = normalize(tbn * ((2.0 * n - 1.0) * vec3(u_pbrMaterial.normalScale, u_pbrMaterial.normalScale, 1.0)));
|
|
150
|
+
vec3 n = texture2D(u_NormalSampler, pbr_vUV).rgb;
|
|
151
|
+
n = normalize(tbn * ((2.0 * n - 1.0) * vec3(u_pbrMaterial.normalScale, u_pbrMaterial.normalScale, 1.0)));
|
|
117
152
|
#else
|
|
118
|
-
|
|
153
|
+
// The tbn matrix is linearly interpolated, so we need to re-normalize
|
|
154
|
+
vec3 n = normalize(tbn[2].xyz);
|
|
119
155
|
#endif
|
|
120
|
-
|
|
156
|
+
|
|
157
|
+
return n;
|
|
121
158
|
}
|
|
159
|
+
|
|
160
|
+
// Calculation of the lighting contribution from an optional Image Based Light source.
|
|
161
|
+
// Precomputed Environment Maps are required uniform inputs and are computed as outlined in [1].
|
|
162
|
+
// See our README.md on Environment Maps [3] for additional discussion.
|
|
122
163
|
#ifdef USE_IBL
|
|
123
164
|
vec3 getIBLContribution(PBRInfo pbrInfo, vec3 n, vec3 reflection)
|
|
124
165
|
{
|
|
125
|
-
float mipCount = 9.0;
|
|
126
|
-
float lod = (pbrInfo.perceptualRoughness * mipCount);
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
166
|
+
float mipCount = 9.0; // resolution of 512x512
|
|
167
|
+
float lod = (pbrInfo.perceptualRoughness * mipCount);
|
|
168
|
+
// retrieve a scale and bias to F0. See [1], Figure 3
|
|
169
|
+
vec3 brdf = SRGBtoLINEAR(texture2D(u_brdfLUT,
|
|
170
|
+
vec2(pbrInfo.NdotV, 1.0 - pbrInfo.perceptualRoughness))).rgb;
|
|
171
|
+
vec3 diffuseLight = SRGBtoLINEAR(textureCube(u_DiffuseEnvSampler, n)).rgb;
|
|
172
|
+
|
|
130
173
|
#ifdef USE_TEX_LOD
|
|
131
|
-
vec3 specularLight = SRGBtoLINEAR(textureCubeLod(u_SpecularEnvSampler, reflection, lod)).rgb;
|
|
174
|
+
vec3 specularLight = SRGBtoLINEAR(textureCubeLod(u_SpecularEnvSampler, reflection, lod)).rgb;
|
|
132
175
|
#else
|
|
133
|
-
vec3 specularLight = SRGBtoLINEAR(textureCube(u_SpecularEnvSampler, reflection)).rgb;
|
|
176
|
+
vec3 specularLight = SRGBtoLINEAR(textureCube(u_SpecularEnvSampler, reflection)).rgb;
|
|
134
177
|
#endif
|
|
135
|
-
|
|
136
|
-
vec3
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
178
|
+
|
|
179
|
+
vec3 diffuse = diffuseLight * pbrInfo.diffuseColor;
|
|
180
|
+
vec3 specular = specularLight * (pbrInfo.specularColor * brdf.x + brdf.y);
|
|
181
|
+
|
|
182
|
+
// For presentation, this allows us to disable IBL terms
|
|
183
|
+
diffuse *= u_pbrMaterial.scaleIBLAmbient.x;
|
|
184
|
+
specular *= u_pbrMaterial.scaleIBLAmbient.y;
|
|
185
|
+
|
|
186
|
+
return diffuse + specular;
|
|
140
187
|
}
|
|
141
188
|
#endif
|
|
189
|
+
|
|
190
|
+
// Basic Lambertian diffuse
|
|
191
|
+
// Implementation from Lambert's Photometria https://archive.org/details/lambertsphotome00lambgoog
|
|
192
|
+
// See also [1], Equation 1
|
|
142
193
|
vec3 diffuse(PBRInfo pbrInfo)
|
|
143
194
|
{
|
|
144
|
-
return pbrInfo.diffuseColor / M_PI;
|
|
195
|
+
return pbrInfo.diffuseColor / M_PI;
|
|
145
196
|
}
|
|
197
|
+
|
|
198
|
+
// The following equation models the Fresnel reflectance term of the spec equation (aka F())
|
|
199
|
+
// Implementation of fresnel from [4], Equation 15
|
|
146
200
|
vec3 specularReflection(PBRInfo pbrInfo)
|
|
147
201
|
{
|
|
148
|
-
return pbrInfo.reflectance0 +
|
|
149
|
-
(pbrInfo.reflectance90 - pbrInfo.reflectance0) *
|
|
150
|
-
pow(clamp(1.0 - pbrInfo.VdotH, 0.0, 1.0), 5.0);
|
|
202
|
+
return pbrInfo.reflectance0 +
|
|
203
|
+
(pbrInfo.reflectance90 - pbrInfo.reflectance0) *
|
|
204
|
+
pow(clamp(1.0 - pbrInfo.VdotH, 0.0, 1.0), 5.0);
|
|
151
205
|
}
|
|
206
|
+
|
|
207
|
+
// This calculates the specular geometric attenuation (aka G()),
|
|
208
|
+
// where rougher material will reflect less light back to the viewer.
|
|
209
|
+
// This implementation is based on [1] Equation 4, and we adopt their modifications to
|
|
210
|
+
// alphaRoughness as input as originally proposed in [2].
|
|
152
211
|
float geometricOcclusion(PBRInfo pbrInfo)
|
|
153
212
|
{
|
|
154
|
-
float NdotL = pbrInfo.NdotL;
|
|
155
|
-
float NdotV = pbrInfo.NdotV;
|
|
156
|
-
float r = pbrInfo.alphaRoughness;
|
|
157
|
-
|
|
158
|
-
float
|
|
159
|
-
|
|
213
|
+
float NdotL = pbrInfo.NdotL;
|
|
214
|
+
float NdotV = pbrInfo.NdotV;
|
|
215
|
+
float r = pbrInfo.alphaRoughness;
|
|
216
|
+
|
|
217
|
+
float attenuationL = 2.0 * NdotL / (NdotL + sqrt(r * r + (1.0 - r * r) * (NdotL * NdotL)));
|
|
218
|
+
float attenuationV = 2.0 * NdotV / (NdotV + sqrt(r * r + (1.0 - r * r) * (NdotV * NdotV)));
|
|
219
|
+
return attenuationL * attenuationV;
|
|
160
220
|
}
|
|
221
|
+
|
|
222
|
+
// The following equation(s) model the distribution of microfacet normals across
|
|
223
|
+
// the area being drawn (aka D())
|
|
224
|
+
// Implementation from "Average Irregularity Representation of a Roughened Surface
|
|
225
|
+
// for Ray Reflection" by T. S. Trowbridge, and K. P. Reitz
|
|
226
|
+
// Follows the distribution function recommended in the SIGGRAPH 2013 course notes
|
|
227
|
+
// from EPIC Games [1], Equation 3.
|
|
161
228
|
float microfacetDistribution(PBRInfo pbrInfo)
|
|
162
229
|
{
|
|
163
|
-
float roughnessSq = pbrInfo.alphaRoughness * pbrInfo.alphaRoughness;
|
|
164
|
-
float f = (pbrInfo.NdotH * roughnessSq - pbrInfo.NdotH) * pbrInfo.NdotH + 1.0;
|
|
165
|
-
return roughnessSq / (M_PI * f * f);
|
|
230
|
+
float roughnessSq = pbrInfo.alphaRoughness * pbrInfo.alphaRoughness;
|
|
231
|
+
float f = (pbrInfo.NdotH * roughnessSq - pbrInfo.NdotH) * pbrInfo.NdotH + 1.0;
|
|
232
|
+
return roughnessSq / (M_PI * f * f);
|
|
166
233
|
}
|
|
234
|
+
|
|
167
235
|
void PBRInfo_setAmbientLight(inout PBRInfo pbrInfo) {
|
|
168
|
-
pbrInfo.NdotL = 1.0;
|
|
169
|
-
pbrInfo.NdotH = 0.0;
|
|
170
|
-
pbrInfo.LdotH = 0.0;
|
|
171
|
-
pbrInfo.VdotH = 1.0;
|
|
236
|
+
pbrInfo.NdotL = 1.0;
|
|
237
|
+
pbrInfo.NdotH = 0.0;
|
|
238
|
+
pbrInfo.LdotH = 0.0;
|
|
239
|
+
pbrInfo.VdotH = 1.0;
|
|
172
240
|
}
|
|
241
|
+
|
|
173
242
|
void PBRInfo_setDirectionalLight(inout PBRInfo pbrInfo, vec3 lightDirection) {
|
|
174
|
-
vec3 n = pbrInfo.n;
|
|
175
|
-
vec3 v = pbrInfo.v;
|
|
176
|
-
vec3 l = normalize(lightDirection);
|
|
177
|
-
vec3 h = normalize(l+v);
|
|
178
|
-
|
|
179
|
-
pbrInfo.
|
|
180
|
-
pbrInfo.
|
|
181
|
-
pbrInfo.
|
|
243
|
+
vec3 n = pbrInfo.n;
|
|
244
|
+
vec3 v = pbrInfo.v;
|
|
245
|
+
vec3 l = normalize(lightDirection); // Vector from surface point to light
|
|
246
|
+
vec3 h = normalize(l+v); // Half vector between both l and v
|
|
247
|
+
|
|
248
|
+
pbrInfo.NdotL = clamp(dot(n, l), 0.001, 1.0);
|
|
249
|
+
pbrInfo.NdotH = clamp(dot(n, h), 0.0, 1.0);
|
|
250
|
+
pbrInfo.LdotH = clamp(dot(l, h), 0.0, 1.0);
|
|
251
|
+
pbrInfo.VdotH = clamp(dot(v, h), 0.0, 1.0);
|
|
182
252
|
}
|
|
253
|
+
|
|
183
254
|
void PBRInfo_setPointLight(inout PBRInfo pbrInfo, PointLight pointLight) {
|
|
184
|
-
vec3 light_direction = normalize(pointLight.position - pbr_vPosition);
|
|
185
|
-
PBRInfo_setDirectionalLight(pbrInfo, light_direction);
|
|
255
|
+
vec3 light_direction = normalize(pointLight.position - pbr_vPosition);
|
|
256
|
+
PBRInfo_setDirectionalLight(pbrInfo, light_direction);
|
|
186
257
|
}
|
|
258
|
+
|
|
187
259
|
vec3 calculateFinalColor(PBRInfo pbrInfo, vec3 lightColor) {
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
float
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
260
|
+
// Calculate the shading terms for the microfacet specular shading model
|
|
261
|
+
vec3 F = specularReflection(pbrInfo);
|
|
262
|
+
float G = geometricOcclusion(pbrInfo);
|
|
263
|
+
float D = microfacetDistribution(pbrInfo);
|
|
264
|
+
|
|
265
|
+
// Calculation of analytical lighting contribution
|
|
266
|
+
vec3 diffuseContrib = (1.0 - F) * diffuse(pbrInfo);
|
|
267
|
+
vec3 specContrib = F * G * D / (4.0 * pbrInfo.NdotL * pbrInfo.NdotV);
|
|
268
|
+
// Obtain final intensity as reflectance (BRDF) scaled by the energy of the light (cosine law)
|
|
269
|
+
return pbrInfo.NdotL * lightColor * (diffuseContrib + specContrib);
|
|
194
270
|
}
|
|
271
|
+
|
|
195
272
|
vec4 pbr_filterColor(vec4 colorUnused)
|
|
196
273
|
{
|
|
274
|
+
// The albedo may be defined from a base texture or a flat color
|
|
197
275
|
#ifdef HAS_BASECOLORMAP
|
|
198
|
-
vec4 baseColor = SRGBtoLINEAR(texture2D(u_BaseColorSampler, pbr_vUV)) * u_pbrMaterial.baseColorFactor;
|
|
276
|
+
vec4 baseColor = SRGBtoLINEAR(texture2D(u_BaseColorSampler, pbr_vUV)) * u_pbrMaterial.baseColorFactor;
|
|
199
277
|
#else
|
|
200
|
-
vec4 baseColor = u_pbrMaterial.baseColorFactor;
|
|
278
|
+
vec4 baseColor = u_pbrMaterial.baseColorFactor;
|
|
201
279
|
#endif
|
|
280
|
+
|
|
202
281
|
#ifdef ALPHA_CUTOFF
|
|
203
|
-
if (baseColor.a < u_pbrMaterial.alphaCutoff) {
|
|
204
|
-
discard;
|
|
205
|
-
}
|
|
282
|
+
if (baseColor.a < u_pbrMaterial.alphaCutoff) {
|
|
283
|
+
discard;
|
|
284
|
+
}
|
|
206
285
|
#endif
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
286
|
+
|
|
287
|
+
vec3 color = vec3(0, 0, 0);
|
|
288
|
+
|
|
289
|
+
if(u_pbrMaterial.unlit){
|
|
290
|
+
color.rgb = baseColor.rgb;
|
|
291
|
+
}
|
|
292
|
+
else{
|
|
293
|
+
// Metallic and Roughness material properties are packed together
|
|
294
|
+
// In glTF, these factors can be specified by fixed scalar values
|
|
295
|
+
// or from a metallic-roughness map
|
|
296
|
+
float perceptualRoughness = u_pbrMaterial.metallicRoughnessValues.y;
|
|
297
|
+
float metallic = u_pbrMaterial.metallicRoughnessValues.x;
|
|
214
298
|
#ifdef HAS_METALROUGHNESSMAP
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
299
|
+
// Roughness is stored in the 'g' channel, metallic is stored in the 'b' channel.
|
|
300
|
+
// This layout intentionally reserves the 'r' channel for (optional) occlusion map data
|
|
301
|
+
vec4 mrSample = texture2D(u_MetallicRoughnessSampler, pbr_vUV);
|
|
302
|
+
perceptualRoughness = mrSample.g * perceptualRoughness;
|
|
303
|
+
metallic = mrSample.b * metallic;
|
|
218
304
|
#endif
|
|
219
|
-
perceptualRoughness = clamp(perceptualRoughness, c_MinRoughness, 1.0);
|
|
220
|
-
metallic = clamp(metallic, 0.0, 1.0);
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
vec3
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
vec3
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
0.0,
|
|
238
|
-
|
|
239
|
-
0.0,
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
305
|
+
perceptualRoughness = clamp(perceptualRoughness, c_MinRoughness, 1.0);
|
|
306
|
+
metallic = clamp(metallic, 0.0, 1.0);
|
|
307
|
+
// Roughness is authored as perceptual roughness; as is convention,
|
|
308
|
+
// convert to material roughness by squaring the perceptual roughness [2].
|
|
309
|
+
float alphaRoughness = perceptualRoughness * perceptualRoughness;
|
|
310
|
+
|
|
311
|
+
vec3 f0 = vec3(0.04);
|
|
312
|
+
vec3 diffuseColor = baseColor.rgb * (vec3(1.0) - f0);
|
|
313
|
+
diffuseColor *= 1.0 - metallic;
|
|
314
|
+
vec3 specularColor = mix(f0, baseColor.rgb, metallic);
|
|
315
|
+
|
|
316
|
+
// Compute reflectance.
|
|
317
|
+
float reflectance = max(max(specularColor.r, specularColor.g), specularColor.b);
|
|
318
|
+
|
|
319
|
+
// For typical incident reflectance range (between 4% to 100%) set the grazing
|
|
320
|
+
// reflectance to 100% for typical fresnel effect.
|
|
321
|
+
// For very low reflectance range on highly diffuse objects (below 4%),
|
|
322
|
+
// incrementally reduce grazing reflecance to 0%.
|
|
323
|
+
float reflectance90 = clamp(reflectance * 25.0, 0.0, 1.0);
|
|
324
|
+
vec3 specularEnvironmentR0 = specularColor.rgb;
|
|
325
|
+
vec3 specularEnvironmentR90 = vec3(1.0, 1.0, 1.0) * reflectance90;
|
|
326
|
+
|
|
327
|
+
vec3 n = getNormal(); // normal at surface point
|
|
328
|
+
vec3 v = normalize(u_Camera - pbr_vPosition); // Vector from surface point to camera
|
|
329
|
+
|
|
330
|
+
float NdotV = clamp(abs(dot(n, v)), 0.001, 1.0);
|
|
331
|
+
vec3 reflection = -normalize(reflect(v, n));
|
|
332
|
+
|
|
333
|
+
PBRInfo pbrInfo = PBRInfo(
|
|
334
|
+
0.0, // NdotL
|
|
335
|
+
NdotV,
|
|
336
|
+
0.0, // NdotH
|
|
337
|
+
0.0, // LdotH
|
|
338
|
+
0.0, // VdotH
|
|
339
|
+
perceptualRoughness,
|
|
340
|
+
metallic,
|
|
341
|
+
specularEnvironmentR0,
|
|
342
|
+
specularEnvironmentR90,
|
|
343
|
+
alphaRoughness,
|
|
344
|
+
diffuseColor,
|
|
345
|
+
specularColor,
|
|
346
|
+
n,
|
|
347
|
+
v
|
|
348
|
+
);
|
|
349
|
+
|
|
250
350
|
#ifdef USE_LIGHTS
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
351
|
+
// Apply ambient light
|
|
352
|
+
PBRInfo_setAmbientLight(pbrInfo);
|
|
353
|
+
color += calculateFinalColor(pbrInfo, lighting_uAmbientLight.color);
|
|
354
|
+
|
|
355
|
+
// Apply directional light
|
|
356
|
+
for(int i = 0; i < lighting_uDirectionalLightCount; i++) {
|
|
357
|
+
if (i < lighting_uDirectionalLightCount) {
|
|
358
|
+
PBRInfo_setDirectionalLight(pbrInfo, lighting_uDirectionalLight[i].direction);
|
|
359
|
+
color += calculateFinalColor(pbrInfo, lighting_uDirectionalLight[i].color);
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
// Apply point light
|
|
364
|
+
for(int i = 0; i < lighting_uPointLightCount; i++) {
|
|
365
|
+
if (i < lighting_uPointLightCount) {
|
|
366
|
+
PBRInfo_setPointLight(pbrInfo, lighting_uPointLight[i]);
|
|
367
|
+
float attenuation = getPointLightAttenuation(lighting_uPointLight[i], distance(lighting_uPointLight[i].position, pbr_vPosition));
|
|
368
|
+
color += calculateFinalColor(pbrInfo, lighting_uPointLight[i].color / attenuation);
|
|
369
|
+
}
|
|
370
|
+
}
|
|
266
371
|
#endif
|
|
372
|
+
|
|
373
|
+
// Calculate lighting contribution from image based lighting source (IBL)
|
|
267
374
|
#ifdef USE_IBL
|
|
268
|
-
if (u_pbrMateral.IBLEnabled) {
|
|
269
|
-
color += getIBLContribution(pbrInfo, n, reflection);
|
|
270
|
-
}
|
|
375
|
+
if (u_pbrMateral.IBLEnabled) {
|
|
376
|
+
color += getIBLContribution(pbrInfo, n, reflection);
|
|
377
|
+
}
|
|
271
378
|
#endif
|
|
379
|
+
|
|
380
|
+
// Apply optional PBR terms for additional (optional) shading
|
|
272
381
|
#ifdef HAS_OCCLUSIONMAP
|
|
273
|
-
if (u_pbrMaterial.occlusionMapEnabled) {
|
|
274
|
-
float ao = texture2D(u_OcclusionSampler, pbr_vUV).r;
|
|
275
|
-
color = mix(color, color * ao, u_pbrMaterial.occlusionStrength);
|
|
276
|
-
}
|
|
382
|
+
if (u_pbrMaterial.occlusionMapEnabled) {
|
|
383
|
+
float ao = texture2D(u_OcclusionSampler, pbr_vUV).r;
|
|
384
|
+
color = mix(color, color * ao, u_pbrMaterial.occlusionStrength);
|
|
385
|
+
}
|
|
277
386
|
#endif
|
|
387
|
+
|
|
278
388
|
#ifdef HAS_EMISSIVEMAP
|
|
279
|
-
if (u_pbrMaterial.emmissiveMapEnabled) {
|
|
280
|
-
vec3 emissive = SRGBtoLINEAR(texture2D(u_EmissiveSampler, pbr_vUV)).rgb * u_pbrMaterial.emissiveFactor;
|
|
281
|
-
color += emissive;
|
|
282
|
-
}
|
|
389
|
+
if (u_pbrMaterial.emmissiveMapEnabled) {
|
|
390
|
+
vec3 emissive = SRGBtoLINEAR(texture2D(u_EmissiveSampler, pbr_vUV)).rgb * u_pbrMaterial.emissiveFactor;
|
|
391
|
+
color += emissive;
|
|
392
|
+
}
|
|
283
393
|
#endif
|
|
394
|
+
|
|
395
|
+
// This section uses mix to override final color for reference app visualization
|
|
396
|
+
// of various parameters in the lighting equation.
|
|
284
397
|
#ifdef PBR_DEBUG
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
color = mix(color,
|
|
398
|
+
// TODO: Figure out how to debug multiple lights
|
|
399
|
+
|
|
400
|
+
// color = mix(color, F, u_ScaleFGDSpec.x);
|
|
401
|
+
// color = mix(color, vec3(G), u_ScaleFGDSpec.y);
|
|
402
|
+
// color = mix(color, vec3(D), u_ScaleFGDSpec.z);
|
|
403
|
+
// color = mix(color, specContrib, u_ScaleFGDSpec.w);
|
|
404
|
+
|
|
405
|
+
// color = mix(color, diffuseContrib, u_ScaleDiffBaseMR.x);
|
|
406
|
+
color = mix(color, baseColor.rgb, u_pbrMaterial.scaleDiffBaseMR.y);
|
|
407
|
+
color = mix(color, vec3(metallic), u_pbrMaterial.scaleDiffBaseMR.z);
|
|
408
|
+
color = mix(color, vec3(perceptualRoughness), u_pbrMaterial.scaleDiffBaseMR.w);
|
|
288
409
|
#endif
|
|
289
|
-
|
|
290
|
-
|
|
410
|
+
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
return vec4(pow(color,vec3(1.0/2.2)), baseColor.a);
|
|
291
414
|
}
|
|
292
415
|
`;
|