@luma.gl/shadertools 9.0.0-alpha.50 → 9.0.0-alpha.51

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 CHANGED
@@ -9904,14 +9904,14 @@ uniform mat4 u_MVPMatrix;
9904
9904
  uniform mat4 u_ModelMatrix;
9905
9905
  uniform mat4 u_NormalMatrix;
9906
9906
 
9907
- varying vec3 pbr_vPosition;
9908
- varying vec2 pbr_vUV;
9907
+ out vec3 pbr_vPosition;
9908
+ out vec2 pbr_vUV;
9909
9909
 
9910
9910
  #ifdef HAS_NORMALS
9911
9911
  # ifdef HAS_TANGENTS
9912
- varying mat3 pbr_vTBN;
9912
+ out mat3 pbr_vTBN;
9913
9913
  # else
9914
- varying vec3 pbr_vNormal;
9914
+ out vec3 pbr_vNormal;
9915
9915
  # endif
9916
9916
  #endif
9917
9917
 
@@ -10003,15 +10003,15 @@ uniform vec4 u_ScaleDiffBaseMR;
10003
10003
  uniform vec4 u_ScaleFGDSpec;
10004
10004
  #endif
10005
10005
 
10006
- varying vec3 pbr_vPosition;
10006
+ in vec3 pbr_vPosition;
10007
10007
 
10008
- varying vec2 pbr_vUV;
10008
+ in vec2 pbr_vUV;
10009
10009
 
10010
10010
  #ifdef HAS_NORMALS
10011
10011
  #ifdef HAS_TANGENTS
10012
- varying mat3 pbr_vTBN;
10012
+ in mat3 pbr_vTBN;
10013
10013
  #else
10014
- varying vec3 pbr_vNormal;
10014
+ in vec3 pbr_vNormal;
10015
10015
  #endif
10016
10016
  #endif
10017
10017
 
@@ -10080,7 +10080,7 @@ vec3 getNormal()
10080
10080
  #endif
10081
10081
 
10082
10082
  #ifdef HAS_NORMALMAP
10083
- vec3 n = texture2D(u_NormalSampler, pbr_vUV).rgb;
10083
+ vec3 n = texture(u_NormalSampler, pbr_vUV).rgb;
10084
10084
  n = normalize(tbn * ((2.0 * n - 1.0) * vec3(u_NormalScale, u_NormalScale, 1.0)));
10085
10085
  #else
10086
10086
  // The tbn matrix is linearly interpolated, so we need to re-normalize
@@ -10099,7 +10099,7 @@ vec3 getIBLContribution(PBRInfo pbrInputs, vec3 n, vec3 reflection)
10099
10099
  float mipCount = 9.0; // resolution of 512x512
10100
10100
  float lod = (pbrInputs.perceptualRoughness * mipCount);
10101
10101
  // retrieve a scale and bias to F0. See [1], Figure 3
10102
- vec3 brdf = SRGBtoLINEAR(texture2D(u_brdfLUT,
10102
+ vec3 brdf = SRGBtoLINEAR(texture(u_brdfLUT,
10103
10103
  vec2(pbrInputs.NdotV, 1.0 - pbrInputs.perceptualRoughness))).rgb;
10104
10104
  vec3 diffuseLight = SRGBtoLINEAR(textureCube(u_DiffuseEnvSampler, n)).rgb;
10105
10105
 
@@ -10206,7 +10206,7 @@ vec4 pbr_filterColor(vec4 colorUnused)
10206
10206
  {
10207
10207
  // The albedo may be defined from a base texture or a flat color
10208
10208
  #ifdef HAS_BASECOLORMAP
10209
- vec4 baseColor = SRGBtoLINEAR(texture2D(u_BaseColorSampler, pbr_vUV)) * u_BaseColorFactor;
10209
+ vec4 baseColor = SRGBtoLINEAR(texture(u_BaseColorSampler, pbr_vUV)) * u_BaseColorFactor;
10210
10210
  #else
10211
10211
  vec4 baseColor = u_BaseColorFactor;
10212
10212
  #endif
@@ -10231,7 +10231,7 @@ vec4 pbr_filterColor(vec4 colorUnused)
10231
10231
  #ifdef HAS_METALROUGHNESSMAP
10232
10232
  // Roughness is stored in the 'g' channel, metallic is stored in the 'b' channel.
10233
10233
  // This layout intentionally reserves the 'r' channel for (optional) occlusion map data
10234
- vec4 mrSample = texture2D(u_MetallicRoughnessSampler, pbr_vUV);
10234
+ vec4 mrSample = texture(u_MetallicRoughnessSampler, pbr_vUV);
10235
10235
  perceptualRoughness = mrSample.g * perceptualRoughness;
10236
10236
  metallic = mrSample.b * metallic;
10237
10237
  #endif
@@ -10310,12 +10310,12 @@ vec4 pbr_filterColor(vec4 colorUnused)
10310
10310
 
10311
10311
  // Apply optional PBR terms for additional (optional) shading
10312
10312
  #ifdef HAS_OCCLUSIONMAP
10313
- float ao = texture2D(u_OcclusionSampler, pbr_vUV).r;
10313
+ float ao = texture(u_OcclusionSampler, pbr_vUV).r;
10314
10314
  color = mix(color, color * ao, u_OcclusionStrength);
10315
10315
  #endif
10316
10316
 
10317
10317
  #ifdef HAS_EMISSIVEMAP
10318
- vec3 emissive = SRGBtoLINEAR(texture2D(u_EmissiveSampler, pbr_vUV)).rgb * u_EmissiveFactor;
10318
+ vec3 emissive = SRGBtoLINEAR(texture(u_EmissiveSampler, pbr_vUV)).rgb * u_EmissiveFactor;
10319
10319
  color += emissive;
10320
10320
  #endif
10321
10321
 
package/dist/index.cjs CHANGED
@@ -8224,14 +8224,14 @@ uniform mat4 u_MVPMatrix;
8224
8224
  uniform mat4 u_ModelMatrix;
8225
8225
  uniform mat4 u_NormalMatrix;
8226
8226
 
8227
- varying vec3 pbr_vPosition;
8228
- varying vec2 pbr_vUV;
8227
+ out vec3 pbr_vPosition;
8228
+ out vec2 pbr_vUV;
8229
8229
 
8230
8230
  #ifdef HAS_NORMALS
8231
8231
  # ifdef HAS_TANGENTS
8232
- varying mat3 pbr_vTBN;
8232
+ out mat3 pbr_vTBN;
8233
8233
  # else
8234
- varying vec3 pbr_vNormal;
8234
+ out vec3 pbr_vNormal;
8235
8235
  # endif
8236
8236
  #endif
8237
8237
 
@@ -8323,15 +8323,15 @@ uniform vec4 u_ScaleDiffBaseMR;
8323
8323
  uniform vec4 u_ScaleFGDSpec;
8324
8324
  #endif
8325
8325
 
8326
- varying vec3 pbr_vPosition;
8326
+ in vec3 pbr_vPosition;
8327
8327
 
8328
- varying vec2 pbr_vUV;
8328
+ in vec2 pbr_vUV;
8329
8329
 
8330
8330
  #ifdef HAS_NORMALS
8331
8331
  #ifdef HAS_TANGENTS
8332
- varying mat3 pbr_vTBN;
8332
+ in mat3 pbr_vTBN;
8333
8333
  #else
8334
- varying vec3 pbr_vNormal;
8334
+ in vec3 pbr_vNormal;
8335
8335
  #endif
8336
8336
  #endif
8337
8337
 
@@ -8400,7 +8400,7 @@ vec3 getNormal()
8400
8400
  #endif
8401
8401
 
8402
8402
  #ifdef HAS_NORMALMAP
8403
- vec3 n = texture2D(u_NormalSampler, pbr_vUV).rgb;
8403
+ vec3 n = texture(u_NormalSampler, pbr_vUV).rgb;
8404
8404
  n = normalize(tbn * ((2.0 * n - 1.0) * vec3(u_NormalScale, u_NormalScale, 1.0)));
8405
8405
  #else
8406
8406
  // The tbn matrix is linearly interpolated, so we need to re-normalize
@@ -8419,7 +8419,7 @@ vec3 getIBLContribution(PBRInfo pbrInputs, vec3 n, vec3 reflection)
8419
8419
  float mipCount = 9.0; // resolution of 512x512
8420
8420
  float lod = (pbrInputs.perceptualRoughness * mipCount);
8421
8421
  // retrieve a scale and bias to F0. See [1], Figure 3
8422
- vec3 brdf = SRGBtoLINEAR(texture2D(u_brdfLUT,
8422
+ vec3 brdf = SRGBtoLINEAR(texture(u_brdfLUT,
8423
8423
  vec2(pbrInputs.NdotV, 1.0 - pbrInputs.perceptualRoughness))).rgb;
8424
8424
  vec3 diffuseLight = SRGBtoLINEAR(textureCube(u_DiffuseEnvSampler, n)).rgb;
8425
8425
 
@@ -8526,7 +8526,7 @@ vec4 pbr_filterColor(vec4 colorUnused)
8526
8526
  {
8527
8527
  // The albedo may be defined from a base texture or a flat color
8528
8528
  #ifdef HAS_BASECOLORMAP
8529
- vec4 baseColor = SRGBtoLINEAR(texture2D(u_BaseColorSampler, pbr_vUV)) * u_BaseColorFactor;
8529
+ vec4 baseColor = SRGBtoLINEAR(texture(u_BaseColorSampler, pbr_vUV)) * u_BaseColorFactor;
8530
8530
  #else
8531
8531
  vec4 baseColor = u_BaseColorFactor;
8532
8532
  #endif
@@ -8551,7 +8551,7 @@ vec4 pbr_filterColor(vec4 colorUnused)
8551
8551
  #ifdef HAS_METALROUGHNESSMAP
8552
8552
  // Roughness is stored in the 'g' channel, metallic is stored in the 'b' channel.
8553
8553
  // This layout intentionally reserves the 'r' channel for (optional) occlusion map data
8554
- vec4 mrSample = texture2D(u_MetallicRoughnessSampler, pbr_vUV);
8554
+ vec4 mrSample = texture(u_MetallicRoughnessSampler, pbr_vUV);
8555
8555
  perceptualRoughness = mrSample.g * perceptualRoughness;
8556
8556
  metallic = mrSample.b * metallic;
8557
8557
  #endif
@@ -8630,12 +8630,12 @@ vec4 pbr_filterColor(vec4 colorUnused)
8630
8630
 
8631
8631
  // Apply optional PBR terms for additional (optional) shading
8632
8632
  #ifdef HAS_OCCLUSIONMAP
8633
- float ao = texture2D(u_OcclusionSampler, pbr_vUV).r;
8633
+ float ao = texture(u_OcclusionSampler, pbr_vUV).r;
8634
8634
  color = mix(color, color * ao, u_OcclusionStrength);
8635
8635
  #endif
8636
8636
 
8637
8637
  #ifdef HAS_EMISSIVEMAP
8638
- vec3 emissive = SRGBtoLINEAR(texture2D(u_EmissiveSampler, pbr_vUV)).rgb * u_EmissiveFactor;
8638
+ vec3 emissive = SRGBtoLINEAR(texture(u_EmissiveSampler, pbr_vUV)).rgb * u_EmissiveFactor;
8639
8639
  color += emissive;
8640
8640
  #endif
8641
8641
 
@@ -62,15 +62,15 @@ uniform vec4 u_ScaleDiffBaseMR;
62
62
  uniform vec4 u_ScaleFGDSpec;
63
63
  #endif
64
64
 
65
- varying vec3 pbr_vPosition;
65
+ in vec3 pbr_vPosition;
66
66
 
67
- varying vec2 pbr_vUV;
67
+ in vec2 pbr_vUV;
68
68
 
69
69
  #ifdef HAS_NORMALS
70
70
  #ifdef HAS_TANGENTS
71
- varying mat3 pbr_vTBN;
71
+ in mat3 pbr_vTBN;
72
72
  #else
73
- varying vec3 pbr_vNormal;
73
+ in vec3 pbr_vNormal;
74
74
  #endif
75
75
  #endif
76
76
 
@@ -139,7 +139,7 @@ vec3 getNormal()
139
139
  #endif
140
140
 
141
141
  #ifdef HAS_NORMALMAP
142
- vec3 n = texture2D(u_NormalSampler, pbr_vUV).rgb;
142
+ vec3 n = texture(u_NormalSampler, pbr_vUV).rgb;
143
143
  n = normalize(tbn * ((2.0 * n - 1.0) * vec3(u_NormalScale, u_NormalScale, 1.0)));
144
144
  #else
145
145
  // The tbn matrix is linearly interpolated, so we need to re-normalize
@@ -158,7 +158,7 @@ vec3 getIBLContribution(PBRInfo pbrInputs, vec3 n, vec3 reflection)
158
158
  float mipCount = 9.0; // resolution of 512x512
159
159
  float lod = (pbrInputs.perceptualRoughness * mipCount);
160
160
  // retrieve a scale and bias to F0. See [1], Figure 3
161
- vec3 brdf = SRGBtoLINEAR(texture2D(u_brdfLUT,
161
+ vec3 brdf = SRGBtoLINEAR(texture(u_brdfLUT,
162
162
  vec2(pbrInputs.NdotV, 1.0 - pbrInputs.perceptualRoughness))).rgb;
163
163
  vec3 diffuseLight = SRGBtoLINEAR(textureCube(u_DiffuseEnvSampler, n)).rgb;
164
164
 
@@ -265,7 +265,7 @@ vec4 pbr_filterColor(vec4 colorUnused)
265
265
  {
266
266
  // The albedo may be defined from a base texture or a flat color
267
267
  #ifdef HAS_BASECOLORMAP
268
- vec4 baseColor = SRGBtoLINEAR(texture2D(u_BaseColorSampler, pbr_vUV)) * u_BaseColorFactor;
268
+ vec4 baseColor = SRGBtoLINEAR(texture(u_BaseColorSampler, pbr_vUV)) * u_BaseColorFactor;
269
269
  #else
270
270
  vec4 baseColor = u_BaseColorFactor;
271
271
  #endif
@@ -290,7 +290,7 @@ vec4 pbr_filterColor(vec4 colorUnused)
290
290
  #ifdef HAS_METALROUGHNESSMAP
291
291
  // Roughness is stored in the 'g' channel, metallic is stored in the 'b' channel.
292
292
  // This layout intentionally reserves the 'r' channel for (optional) occlusion map data
293
- vec4 mrSample = texture2D(u_MetallicRoughnessSampler, pbr_vUV);
293
+ vec4 mrSample = texture(u_MetallicRoughnessSampler, pbr_vUV);
294
294
  perceptualRoughness = mrSample.g * perceptualRoughness;
295
295
  metallic = mrSample.b * metallic;
296
296
  #endif
@@ -369,12 +369,12 @@ vec4 pbr_filterColor(vec4 colorUnused)
369
369
 
370
370
  // Apply optional PBR terms for additional (optional) shading
371
371
  #ifdef HAS_OCCLUSIONMAP
372
- float ao = texture2D(u_OcclusionSampler, pbr_vUV).r;
372
+ float ao = texture(u_OcclusionSampler, pbr_vUV).r;
373
373
  color = mix(color, color * ao, u_OcclusionStrength);
374
374
  #endif
375
375
 
376
376
  #ifdef HAS_EMISSIVEMAP
377
- vec3 emissive = SRGBtoLINEAR(texture2D(u_EmissiveSampler, pbr_vUV)).rgb * u_EmissiveFactor;
377
+ vec3 emissive = SRGBtoLINEAR(texture(u_EmissiveSampler, pbr_vUV)).rgb * u_EmissiveFactor;
378
378
  color += emissive;
379
379
  #endif
380
380
 
@@ -1 +1 @@
1
- {"version":3,"file":"pbr-fragment.glsl.js","names":["glsl","fs"],"sources":["../../../../src/modules-webgl1/lighting/pbr/pbr-fragment.glsl.ts"],"sourcesContent":["// This fragment shader defines a reference implementation for Physically Based Shading of\n// a microfacet surface material defined by a glTF model.\n//\n// Attribution:\n// MIT license, Copyright (c) 2016-2017 Mohamad Moneimne and Contributors\n\n// TODO - better do the checks outside of shader\nimport {glsl} from '../../../lib/glsl-utils/highlight';\n\nexport const fs = glsl`\\\n#if defined(USE_TEX_LOD) && !defined(FEATURE_GLSL_TEXTURE_LOD)\n# error PBR fragment shader: Texture LOD is not available\n#endif\n\n#if !defined(HAS_TANGENTS) && !defined(FEATURE_GLSL_DERIVATIVES)\n# error PBR fragment shader: Derivatives are not available\n#endif\n\n// WebGL 1.0 does not support non-constant in for loops\n// This provides an easy way to handle these cases\n// and still take advantage of WebGL 2.0\n#if (__VERSION__ < 300)\n #define SMART_FOR(INIT, WEBGL1COND, WEBGL2COND, INCR) for (INIT; WEBGL1COND; INCR)\n#else\n #define SMART_FOR(INIT, WEBGL1COND, WEBGL2COND, INCR) for (INIT; WEBGL2COND; INCR)\n#endif\n\nprecision highp float;\n\nuniform bool pbr_uUnlit;\n\n#ifdef USE_IBL\nuniform samplerCube u_DiffuseEnvSampler;\nuniform samplerCube u_SpecularEnvSampler;\nuniform sampler2D u_brdfLUT;\nuniform vec2 u_ScaleIBLAmbient;\n#endif\n\n#ifdef HAS_BASECOLORMAP\nuniform sampler2D u_BaseColorSampler;\n#endif\n#ifdef HAS_NORMALMAP\nuniform sampler2D u_NormalSampler;\nuniform float u_NormalScale;\n#endif\n#ifdef HAS_EMISSIVEMAP\nuniform sampler2D u_EmissiveSampler;\nuniform vec3 u_EmissiveFactor;\n#endif\n#ifdef HAS_METALROUGHNESSMAP\nuniform sampler2D u_MetallicRoughnessSampler;\n#endif\n#ifdef HAS_OCCLUSIONMAP\nuniform sampler2D u_OcclusionSampler;\nuniform float u_OcclusionStrength;\n#endif\n\n#ifdef ALPHA_CUTOFF\nuniform float u_AlphaCutoff;\n#endif\n\nuniform vec2 u_MetallicRoughnessValues;\nuniform vec4 u_BaseColorFactor;\n\nuniform vec3 u_Camera;\n\n// debugging flags used for shader output of intermediate PBR variables\n#ifdef PBR_DEBUG\nuniform vec4 u_ScaleDiffBaseMR;\nuniform vec4 u_ScaleFGDSpec;\n#endif\n\nvarying vec3 pbr_vPosition;\n\nvarying vec2 pbr_vUV;\n\n#ifdef HAS_NORMALS\n#ifdef HAS_TANGENTS\nvarying mat3 pbr_vTBN;\n#else\nvarying vec3 pbr_vNormal;\n#endif\n#endif\n\n// Encapsulate the various inputs used by the various functions in the shading equation\n// We store values in this struct to simplify the integration of alternative implementations\n// of the shading terms, outlined in the Readme.MD Appendix.\nstruct PBRInfo\n{\n float NdotL; // cos angle between normal and light direction\n float NdotV; // cos angle between normal and view direction\n float NdotH; // cos angle between normal and half vector\n float LdotH; // cos angle between light direction and half vector\n float VdotH; // cos angle between view direction and half vector\n float perceptualRoughness; // roughness value, as authored by the model creator (input to shader)\n float metalness; // metallic value at the surface\n vec3 reflectance0; // full reflectance color (normal incidence angle)\n vec3 reflectance90; // reflectance color at grazing angle\n float alphaRoughness; // roughness mapped to a more linear change in the roughness (proposed by [2])\n vec3 diffuseColor; // color contribution from diffuse lighting\n vec3 specularColor; // color contribution from specular lighting\n vec3 n; // normal at surface point\n vec3 v; // vector from surface point to camera\n};\n\nconst float M_PI = 3.141592653589793;\nconst float c_MinRoughness = 0.04;\n\nvec4 SRGBtoLINEAR(vec4 srgbIn)\n{\n#ifdef MANUAL_SRGB\n#ifdef SRGB_FAST_APPROXIMATION\n vec3 linOut = pow(srgbIn.xyz,vec3(2.2));\n#else //SRGB_FAST_APPROXIMATION\n vec3 bLess = step(vec3(0.04045),srgbIn.xyz);\n vec3 linOut = mix( srgbIn.xyz/vec3(12.92), pow((srgbIn.xyz+vec3(0.055))/vec3(1.055),vec3(2.4)), bLess );\n#endif //SRGB_FAST_APPROXIMATION\n return vec4(linOut,srgbIn.w);;\n#else //MANUAL_SRGB\n return srgbIn;\n#endif //MANUAL_SRGB\n}\n\n// Find the normal for this fragment, pulling either from a predefined normal map\n// or from the interpolated mesh normal and tangent attributes.\nvec3 getNormal()\n{\n // Retrieve the tangent space matrix\n#ifndef HAS_TANGENTS\n vec3 pos_dx = dFdx(pbr_vPosition);\n vec3 pos_dy = dFdy(pbr_vPosition);\n vec3 tex_dx = dFdx(vec3(pbr_vUV, 0.0));\n vec3 tex_dy = dFdy(vec3(pbr_vUV, 0.0));\n vec3 t = (tex_dy.t * pos_dx - tex_dx.t * pos_dy) / (tex_dx.s * tex_dy.t - tex_dy.s * tex_dx.t);\n\n#ifdef HAS_NORMALS\n vec3 ng = normalize(pbr_vNormal);\n#else\n vec3 ng = cross(pos_dx, pos_dy);\n#endif\n\n t = normalize(t - ng * dot(ng, t));\n vec3 b = normalize(cross(ng, t));\n mat3 tbn = mat3(t, b, ng);\n#else // HAS_TANGENTS\n mat3 tbn = pbr_vTBN;\n#endif\n\n#ifdef HAS_NORMALMAP\n vec3 n = texture2D(u_NormalSampler, pbr_vUV).rgb;\n n = normalize(tbn * ((2.0 * n - 1.0) * vec3(u_NormalScale, u_NormalScale, 1.0)));\n#else\n // The tbn matrix is linearly interpolated, so we need to re-normalize\n vec3 n = normalize(tbn[2].xyz);\n#endif\n\n return n;\n}\n\n// Calculation of the lighting contribution from an optional Image Based Light source.\n// Precomputed Environment Maps are required uniform inputs and are computed as outlined in [1].\n// See our README.md on Environment Maps [3] for additional discussion.\n#ifdef USE_IBL\nvec3 getIBLContribution(PBRInfo pbrInputs, vec3 n, vec3 reflection)\n{\n float mipCount = 9.0; // resolution of 512x512\n float lod = (pbrInputs.perceptualRoughness * mipCount);\n // retrieve a scale and bias to F0. See [1], Figure 3\n vec3 brdf = SRGBtoLINEAR(texture2D(u_brdfLUT,\n vec2(pbrInputs.NdotV, 1.0 - pbrInputs.perceptualRoughness))).rgb;\n vec3 diffuseLight = SRGBtoLINEAR(textureCube(u_DiffuseEnvSampler, n)).rgb;\n\n#ifdef USE_TEX_LOD\n vec3 specularLight = SRGBtoLINEAR(textureCubeLod(u_SpecularEnvSampler, reflection, lod)).rgb;\n#else\n vec3 specularLight = SRGBtoLINEAR(textureCube(u_SpecularEnvSampler, reflection)).rgb;\n#endif\n\n vec3 diffuse = diffuseLight * pbrInputs.diffuseColor;\n vec3 specular = specularLight * (pbrInputs.specularColor * brdf.x + brdf.y);\n\n // For presentation, this allows us to disable IBL terms\n diffuse *= u_ScaleIBLAmbient.x;\n specular *= u_ScaleIBLAmbient.y;\n\n return diffuse + specular;\n}\n#endif\n\n// Basic Lambertian diffuse\n// Implementation from Lambert's Photometria https://archive.org/details/lambertsphotome00lambgoog\n// See also [1], Equation 1\nvec3 diffuse(PBRInfo pbrInputs)\n{\n return pbrInputs.diffuseColor / M_PI;\n}\n\n// The following equation models the Fresnel reflectance term of the spec equation (aka F())\n// Implementation of fresnel from [4], Equation 15\nvec3 specularReflection(PBRInfo pbrInputs)\n{\n return pbrInputs.reflectance0 +\n (pbrInputs.reflectance90 - pbrInputs.reflectance0) *\n pow(clamp(1.0 - pbrInputs.VdotH, 0.0, 1.0), 5.0);\n}\n\n// This calculates the specular geometric attenuation (aka G()),\n// where rougher material will reflect less light back to the viewer.\n// This implementation is based on [1] Equation 4, and we adopt their modifications to\n// alphaRoughness as input as originally proposed in [2].\nfloat geometricOcclusion(PBRInfo pbrInputs)\n{\n float NdotL = pbrInputs.NdotL;\n float NdotV = pbrInputs.NdotV;\n float r = pbrInputs.alphaRoughness;\n\n float attenuationL = 2.0 * NdotL / (NdotL + sqrt(r * r + (1.0 - r * r) * (NdotL * NdotL)));\n float attenuationV = 2.0 * NdotV / (NdotV + sqrt(r * r + (1.0 - r * r) * (NdotV * NdotV)));\n return attenuationL * attenuationV;\n}\n\n// The following equation(s) model the distribution of microfacet normals across\n// the area being drawn (aka D())\n// Implementation from \"Average Irregularity Representation of a Roughened Surface\n// for Ray Reflection\" by T. S. Trowbridge, and K. P. Reitz\n// Follows the distribution function recommended in the SIGGRAPH 2013 course notes\n// from EPIC Games [1], Equation 3.\nfloat microfacetDistribution(PBRInfo pbrInputs)\n{\n float roughnessSq = pbrInputs.alphaRoughness * pbrInputs.alphaRoughness;\n float f = (pbrInputs.NdotH * roughnessSq - pbrInputs.NdotH) * pbrInputs.NdotH + 1.0;\n return roughnessSq / (M_PI * f * f);\n}\n\nvoid PBRInfo_setAmbientLight(inout PBRInfo pbrInputs) {\n pbrInputs.NdotL = 1.0;\n pbrInputs.NdotH = 0.0;\n pbrInputs.LdotH = 0.0;\n pbrInputs.VdotH = 1.0;\n}\n\nvoid PBRInfo_setDirectionalLight(inout PBRInfo pbrInputs, vec3 lightDirection) {\n vec3 n = pbrInputs.n;\n vec3 v = pbrInputs.v;\n vec3 l = normalize(lightDirection); // Vector from surface point to light\n vec3 h = normalize(l+v); // Half vector between both l and v\n\n pbrInputs.NdotL = clamp(dot(n, l), 0.001, 1.0);\n pbrInputs.NdotH = clamp(dot(n, h), 0.0, 1.0);\n pbrInputs.LdotH = clamp(dot(l, h), 0.0, 1.0);\n pbrInputs.VdotH = clamp(dot(v, h), 0.0, 1.0);\n}\n\nvoid PBRInfo_setPointLight(inout PBRInfo pbrInputs, PointLight pointLight) {\n vec3 light_direction = normalize(pointLight.position - pbr_vPosition);\n PBRInfo_setDirectionalLight(pbrInputs, light_direction);\n}\n\nvec3 calculateFinalColor(PBRInfo pbrInputs, vec3 lightColor) {\n // Calculate the shading terms for the microfacet specular shading model\n vec3 F = specularReflection(pbrInputs);\n float G = geometricOcclusion(pbrInputs);\n float D = microfacetDistribution(pbrInputs);\n\n // Calculation of analytical lighting contribution\n vec3 diffuseContrib = (1.0 - F) * diffuse(pbrInputs);\n vec3 specContrib = F * G * D / (4.0 * pbrInputs.NdotL * pbrInputs.NdotV);\n // Obtain final intensity as reflectance (BRDF) scaled by the energy of the light (cosine law)\n return pbrInputs.NdotL * lightColor * (diffuseContrib + specContrib);\n}\n\nvec4 pbr_filterColor(vec4 colorUnused)\n{\n // The albedo may be defined from a base texture or a flat color\n#ifdef HAS_BASECOLORMAP\n vec4 baseColor = SRGBtoLINEAR(texture2D(u_BaseColorSampler, pbr_vUV)) * u_BaseColorFactor;\n#else\n vec4 baseColor = u_BaseColorFactor;\n#endif\n\n#ifdef ALPHA_CUTOFF\n if (baseColor.a < u_AlphaCutoff) {\n discard;\n }\n#endif\n\n vec3 color = vec3(0, 0, 0);\n\n if(pbr_uUnlit){\n color.rgb = baseColor.rgb;\n }\n else{\n // Metallic and Roughness material properties are packed together\n // In glTF, these factors can be specified by fixed scalar values\n // or from a metallic-roughness map\n float perceptualRoughness = u_MetallicRoughnessValues.y;\n float metallic = u_MetallicRoughnessValues.x;\n#ifdef HAS_METALROUGHNESSMAP\n // Roughness is stored in the 'g' channel, metallic is stored in the 'b' channel.\n // This layout intentionally reserves the 'r' channel for (optional) occlusion map data\n vec4 mrSample = texture2D(u_MetallicRoughnessSampler, pbr_vUV);\n perceptualRoughness = mrSample.g * perceptualRoughness;\n metallic = mrSample.b * metallic;\n#endif\n perceptualRoughness = clamp(perceptualRoughness, c_MinRoughness, 1.0);\n metallic = clamp(metallic, 0.0, 1.0);\n // Roughness is authored as perceptual roughness; as is convention,\n // convert to material roughness by squaring the perceptual roughness [2].\n float alphaRoughness = perceptualRoughness * perceptualRoughness;\n\n vec3 f0 = vec3(0.04);\n vec3 diffuseColor = baseColor.rgb * (vec3(1.0) - f0);\n diffuseColor *= 1.0 - metallic;\n vec3 specularColor = mix(f0, baseColor.rgb, metallic);\n\n // Compute reflectance.\n float reflectance = max(max(specularColor.r, specularColor.g), specularColor.b);\n\n // For typical incident reflectance range (between 4% to 100%) set the grazing\n // reflectance to 100% for typical fresnel effect.\n // For very low reflectance range on highly diffuse objects (below 4%),\n // incrementally reduce grazing reflecance to 0%.\n float reflectance90 = clamp(reflectance * 25.0, 0.0, 1.0);\n vec3 specularEnvironmentR0 = specularColor.rgb;\n vec3 specularEnvironmentR90 = vec3(1.0, 1.0, 1.0) * reflectance90;\n\n vec3 n = getNormal(); // normal at surface point\n vec3 v = normalize(u_Camera - pbr_vPosition); // Vector from surface point to camera\n\n float NdotV = clamp(abs(dot(n, v)), 0.001, 1.0);\n vec3 reflection = -normalize(reflect(v, n));\n\n PBRInfo pbrInputs = PBRInfo(\n 0.0, // NdotL\n NdotV,\n 0.0, // NdotH\n 0.0, // LdotH\n 0.0, // VdotH\n perceptualRoughness,\n metallic,\n specularEnvironmentR0,\n specularEnvironmentR90,\n alphaRoughness,\n diffuseColor,\n specularColor,\n n,\n v\n );\n\n#ifdef USE_LIGHTS\n // Apply ambient light\n PBRInfo_setAmbientLight(pbrInputs);\n color += calculateFinalColor(pbrInputs, lighting_uAmbientLight.color);\n\n // Apply directional light\n SMART_FOR(int i = 0, i < MAX_LIGHTS, i < lighting_uDirectionalLightCount, i++) {\n if (i < lighting_uDirectionalLightCount) {\n PBRInfo_setDirectionalLight(pbrInputs, lighting_uDirectionalLight[i].direction);\n color += calculateFinalColor(pbrInputs, lighting_uDirectionalLight[i].color);\n }\n }\n\n // Apply point light\n SMART_FOR(int i = 0, i < MAX_LIGHTS, i < lighting_uPointLightCount, i++) {\n if (i < lighting_uPointLightCount) {\n PBRInfo_setPointLight(pbrInputs, lighting_uPointLight[i]);\n float attenuation = getPointLightAttenuation(lighting_uPointLight[i], distance(lighting_uPointLight[i].position, pbr_vPosition));\n color += calculateFinalColor(pbrInputs, lighting_uPointLight[i].color / attenuation);\n }\n }\n#endif\n\n // Calculate lighting contribution from image based lighting source (IBL)\n#ifdef USE_IBL\n color += getIBLContribution(pbrInputs, n, reflection);\n#endif\n\n // Apply optional PBR terms for additional (optional) shading\n#ifdef HAS_OCCLUSIONMAP\n float ao = texture2D(u_OcclusionSampler, pbr_vUV).r;\n color = mix(color, color * ao, u_OcclusionStrength);\n#endif\n\n#ifdef HAS_EMISSIVEMAP\n vec3 emissive = SRGBtoLINEAR(texture2D(u_EmissiveSampler, pbr_vUV)).rgb * u_EmissiveFactor;\n color += emissive;\n#endif\n\n // This section uses mix to override final color for reference app visualization\n // of various parameters in the lighting equation.\n#ifdef PBR_DEBUG\n // TODO: Figure out how to debug multiple lights\n\n // color = mix(color, F, u_ScaleFGDSpec.x);\n // color = mix(color, vec3(G), u_ScaleFGDSpec.y);\n // color = mix(color, vec3(D), u_ScaleFGDSpec.z);\n // color = mix(color, specContrib, u_ScaleFGDSpec.w);\n\n // color = mix(color, diffuseContrib, u_ScaleDiffBaseMR.x);\n color = mix(color, baseColor.rgb, u_ScaleDiffBaseMR.y);\n color = mix(color, vec3(metallic), u_ScaleDiffBaseMR.z);\n color = mix(color, vec3(perceptualRoughness), u_ScaleDiffBaseMR.w);\n#endif\n\n }\n\n return vec4(pow(color,vec3(1.0/2.2)), baseColor.a);\n}\n`;\n"],"mappings":"SAOQA,IAAI;AAEZ,OAAO,MAAMC,EAAE,GAAGD,IAAK;AACvB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,CAAC"}
1
+ {"version":3,"file":"pbr-fragment.glsl.js","names":["glsl","fs"],"sources":["../../../../src/modules-webgl1/lighting/pbr/pbr-fragment.glsl.ts"],"sourcesContent":["// This fragment shader defines a reference implementation for Physically Based Shading of\n// a microfacet surface material defined by a glTF model.\n//\n// Attribution:\n// MIT license, Copyright (c) 2016-2017 Mohamad Moneimne and Contributors\n\n// TODO - better do the checks outside of shader\nimport {glsl} from '../../../lib/glsl-utils/highlight';\n\nexport const fs = glsl`\\\n#if defined(USE_TEX_LOD) && !defined(FEATURE_GLSL_TEXTURE_LOD)\n# error PBR fragment shader: Texture LOD is not available\n#endif\n\n#if !defined(HAS_TANGENTS) && !defined(FEATURE_GLSL_DERIVATIVES)\n# error PBR fragment shader: Derivatives are not available\n#endif\n\n// WebGL 1.0 does not support non-constant in for loops\n// This provides an easy way to handle these cases\n// and still take advantage of WebGL 2.0\n#if (__VERSION__ < 300)\n #define SMART_FOR(INIT, WEBGL1COND, WEBGL2COND, INCR) for (INIT; WEBGL1COND; INCR)\n#else\n #define SMART_FOR(INIT, WEBGL1COND, WEBGL2COND, INCR) for (INIT; WEBGL2COND; INCR)\n#endif\n\nprecision highp float;\n\nuniform bool pbr_uUnlit;\n\n#ifdef USE_IBL\nuniform samplerCube u_DiffuseEnvSampler;\nuniform samplerCube u_SpecularEnvSampler;\nuniform sampler2D u_brdfLUT;\nuniform vec2 u_ScaleIBLAmbient;\n#endif\n\n#ifdef HAS_BASECOLORMAP\nuniform sampler2D u_BaseColorSampler;\n#endif\n#ifdef HAS_NORMALMAP\nuniform sampler2D u_NormalSampler;\nuniform float u_NormalScale;\n#endif\n#ifdef HAS_EMISSIVEMAP\nuniform sampler2D u_EmissiveSampler;\nuniform vec3 u_EmissiveFactor;\n#endif\n#ifdef HAS_METALROUGHNESSMAP\nuniform sampler2D u_MetallicRoughnessSampler;\n#endif\n#ifdef HAS_OCCLUSIONMAP\nuniform sampler2D u_OcclusionSampler;\nuniform float u_OcclusionStrength;\n#endif\n\n#ifdef ALPHA_CUTOFF\nuniform float u_AlphaCutoff;\n#endif\n\nuniform vec2 u_MetallicRoughnessValues;\nuniform vec4 u_BaseColorFactor;\n\nuniform vec3 u_Camera;\n\n// debugging flags used for shader output of intermediate PBR variables\n#ifdef PBR_DEBUG\nuniform vec4 u_ScaleDiffBaseMR;\nuniform vec4 u_ScaleFGDSpec;\n#endif\n\nin vec3 pbr_vPosition;\n\nin vec2 pbr_vUV;\n\n#ifdef HAS_NORMALS\n#ifdef HAS_TANGENTS\nin mat3 pbr_vTBN;\n#else\nin vec3 pbr_vNormal;\n#endif\n#endif\n\n// Encapsulate the various inputs used by the various functions in the shading equation\n// We store values in this struct to simplify the integration of alternative implementations\n// of the shading terms, outlined in the Readme.MD Appendix.\nstruct PBRInfo\n{\n float NdotL; // cos angle between normal and light direction\n float NdotV; // cos angle between normal and view direction\n float NdotH; // cos angle between normal and half vector\n float LdotH; // cos angle between light direction and half vector\n float VdotH; // cos angle between view direction and half vector\n float perceptualRoughness; // roughness value, as authored by the model creator (input to shader)\n float metalness; // metallic value at the surface\n vec3 reflectance0; // full reflectance color (normal incidence angle)\n vec3 reflectance90; // reflectance color at grazing angle\n float alphaRoughness; // roughness mapped to a more linear change in the roughness (proposed by [2])\n vec3 diffuseColor; // color contribution from diffuse lighting\n vec3 specularColor; // color contribution from specular lighting\n vec3 n; // normal at surface point\n vec3 v; // vector from surface point to camera\n};\n\nconst float M_PI = 3.141592653589793;\nconst float c_MinRoughness = 0.04;\n\nvec4 SRGBtoLINEAR(vec4 srgbIn)\n{\n#ifdef MANUAL_SRGB\n#ifdef SRGB_FAST_APPROXIMATION\n vec3 linOut = pow(srgbIn.xyz,vec3(2.2));\n#else //SRGB_FAST_APPROXIMATION\n vec3 bLess = step(vec3(0.04045),srgbIn.xyz);\n vec3 linOut = mix( srgbIn.xyz/vec3(12.92), pow((srgbIn.xyz+vec3(0.055))/vec3(1.055),vec3(2.4)), bLess );\n#endif //SRGB_FAST_APPROXIMATION\n return vec4(linOut,srgbIn.w);;\n#else //MANUAL_SRGB\n return srgbIn;\n#endif //MANUAL_SRGB\n}\n\n// Find the normal for this fragment, pulling either from a predefined normal map\n// or from the interpolated mesh normal and tangent attributes.\nvec3 getNormal()\n{\n // Retrieve the tangent space matrix\n#ifndef HAS_TANGENTS\n vec3 pos_dx = dFdx(pbr_vPosition);\n vec3 pos_dy = dFdy(pbr_vPosition);\n vec3 tex_dx = dFdx(vec3(pbr_vUV, 0.0));\n vec3 tex_dy = dFdy(vec3(pbr_vUV, 0.0));\n vec3 t = (tex_dy.t * pos_dx - tex_dx.t * pos_dy) / (tex_dx.s * tex_dy.t - tex_dy.s * tex_dx.t);\n\n#ifdef HAS_NORMALS\n vec3 ng = normalize(pbr_vNormal);\n#else\n vec3 ng = cross(pos_dx, pos_dy);\n#endif\n\n t = normalize(t - ng * dot(ng, t));\n vec3 b = normalize(cross(ng, t));\n mat3 tbn = mat3(t, b, ng);\n#else // HAS_TANGENTS\n mat3 tbn = pbr_vTBN;\n#endif\n\n#ifdef HAS_NORMALMAP\n vec3 n = texture(u_NormalSampler, pbr_vUV).rgb;\n n = normalize(tbn * ((2.0 * n - 1.0) * vec3(u_NormalScale, u_NormalScale, 1.0)));\n#else\n // The tbn matrix is linearly interpolated, so we need to re-normalize\n vec3 n = normalize(tbn[2].xyz);\n#endif\n\n return n;\n}\n\n// Calculation of the lighting contribution from an optional Image Based Light source.\n// Precomputed Environment Maps are required uniform inputs and are computed as outlined in [1].\n// See our README.md on Environment Maps [3] for additional discussion.\n#ifdef USE_IBL\nvec3 getIBLContribution(PBRInfo pbrInputs, vec3 n, vec3 reflection)\n{\n float mipCount = 9.0; // resolution of 512x512\n float lod = (pbrInputs.perceptualRoughness * mipCount);\n // retrieve a scale and bias to F0. See [1], Figure 3\n vec3 brdf = SRGBtoLINEAR(texture(u_brdfLUT,\n vec2(pbrInputs.NdotV, 1.0 - pbrInputs.perceptualRoughness))).rgb;\n vec3 diffuseLight = SRGBtoLINEAR(textureCube(u_DiffuseEnvSampler, n)).rgb;\n\n#ifdef USE_TEX_LOD\n vec3 specularLight = SRGBtoLINEAR(textureCubeLod(u_SpecularEnvSampler, reflection, lod)).rgb;\n#else\n vec3 specularLight = SRGBtoLINEAR(textureCube(u_SpecularEnvSampler, reflection)).rgb;\n#endif\n\n vec3 diffuse = diffuseLight * pbrInputs.diffuseColor;\n vec3 specular = specularLight * (pbrInputs.specularColor * brdf.x + brdf.y);\n\n // For presentation, this allows us to disable IBL terms\n diffuse *= u_ScaleIBLAmbient.x;\n specular *= u_ScaleIBLAmbient.y;\n\n return diffuse + specular;\n}\n#endif\n\n// Basic Lambertian diffuse\n// Implementation from Lambert's Photometria https://archive.org/details/lambertsphotome00lambgoog\n// See also [1], Equation 1\nvec3 diffuse(PBRInfo pbrInputs)\n{\n return pbrInputs.diffuseColor / M_PI;\n}\n\n// The following equation models the Fresnel reflectance term of the spec equation (aka F())\n// Implementation of fresnel from [4], Equation 15\nvec3 specularReflection(PBRInfo pbrInputs)\n{\n return pbrInputs.reflectance0 +\n (pbrInputs.reflectance90 - pbrInputs.reflectance0) *\n pow(clamp(1.0 - pbrInputs.VdotH, 0.0, 1.0), 5.0);\n}\n\n// This calculates the specular geometric attenuation (aka G()),\n// where rougher material will reflect less light back to the viewer.\n// This implementation is based on [1] Equation 4, and we adopt their modifications to\n// alphaRoughness as input as originally proposed in [2].\nfloat geometricOcclusion(PBRInfo pbrInputs)\n{\n float NdotL = pbrInputs.NdotL;\n float NdotV = pbrInputs.NdotV;\n float r = pbrInputs.alphaRoughness;\n\n float attenuationL = 2.0 * NdotL / (NdotL + sqrt(r * r + (1.0 - r * r) * (NdotL * NdotL)));\n float attenuationV = 2.0 * NdotV / (NdotV + sqrt(r * r + (1.0 - r * r) * (NdotV * NdotV)));\n return attenuationL * attenuationV;\n}\n\n// The following equation(s) model the distribution of microfacet normals across\n// the area being drawn (aka D())\n// Implementation from \"Average Irregularity Representation of a Roughened Surface\n// for Ray Reflection\" by T. S. Trowbridge, and K. P. Reitz\n// Follows the distribution function recommended in the SIGGRAPH 2013 course notes\n// from EPIC Games [1], Equation 3.\nfloat microfacetDistribution(PBRInfo pbrInputs)\n{\n float roughnessSq = pbrInputs.alphaRoughness * pbrInputs.alphaRoughness;\n float f = (pbrInputs.NdotH * roughnessSq - pbrInputs.NdotH) * pbrInputs.NdotH + 1.0;\n return roughnessSq / (M_PI * f * f);\n}\n\nvoid PBRInfo_setAmbientLight(inout PBRInfo pbrInputs) {\n pbrInputs.NdotL = 1.0;\n pbrInputs.NdotH = 0.0;\n pbrInputs.LdotH = 0.0;\n pbrInputs.VdotH = 1.0;\n}\n\nvoid PBRInfo_setDirectionalLight(inout PBRInfo pbrInputs, vec3 lightDirection) {\n vec3 n = pbrInputs.n;\n vec3 v = pbrInputs.v;\n vec3 l = normalize(lightDirection); // Vector from surface point to light\n vec3 h = normalize(l+v); // Half vector between both l and v\n\n pbrInputs.NdotL = clamp(dot(n, l), 0.001, 1.0);\n pbrInputs.NdotH = clamp(dot(n, h), 0.0, 1.0);\n pbrInputs.LdotH = clamp(dot(l, h), 0.0, 1.0);\n pbrInputs.VdotH = clamp(dot(v, h), 0.0, 1.0);\n}\n\nvoid PBRInfo_setPointLight(inout PBRInfo pbrInputs, PointLight pointLight) {\n vec3 light_direction = normalize(pointLight.position - pbr_vPosition);\n PBRInfo_setDirectionalLight(pbrInputs, light_direction);\n}\n\nvec3 calculateFinalColor(PBRInfo pbrInputs, vec3 lightColor) {\n // Calculate the shading terms for the microfacet specular shading model\n vec3 F = specularReflection(pbrInputs);\n float G = geometricOcclusion(pbrInputs);\n float D = microfacetDistribution(pbrInputs);\n\n // Calculation of analytical lighting contribution\n vec3 diffuseContrib = (1.0 - F) * diffuse(pbrInputs);\n vec3 specContrib = F * G * D / (4.0 * pbrInputs.NdotL * pbrInputs.NdotV);\n // Obtain final intensity as reflectance (BRDF) scaled by the energy of the light (cosine law)\n return pbrInputs.NdotL * lightColor * (diffuseContrib + specContrib);\n}\n\nvec4 pbr_filterColor(vec4 colorUnused)\n{\n // The albedo may be defined from a base texture or a flat color\n#ifdef HAS_BASECOLORMAP\n vec4 baseColor = SRGBtoLINEAR(texture(u_BaseColorSampler, pbr_vUV)) * u_BaseColorFactor;\n#else\n vec4 baseColor = u_BaseColorFactor;\n#endif\n\n#ifdef ALPHA_CUTOFF\n if (baseColor.a < u_AlphaCutoff) {\n discard;\n }\n#endif\n\n vec3 color = vec3(0, 0, 0);\n\n if(pbr_uUnlit){\n color.rgb = baseColor.rgb;\n }\n else{\n // Metallic and Roughness material properties are packed together\n // In glTF, these factors can be specified by fixed scalar values\n // or from a metallic-roughness map\n float perceptualRoughness = u_MetallicRoughnessValues.y;\n float metallic = u_MetallicRoughnessValues.x;\n#ifdef HAS_METALROUGHNESSMAP\n // Roughness is stored in the 'g' channel, metallic is stored in the 'b' channel.\n // This layout intentionally reserves the 'r' channel for (optional) occlusion map data\n vec4 mrSample = texture(u_MetallicRoughnessSampler, pbr_vUV);\n perceptualRoughness = mrSample.g * perceptualRoughness;\n metallic = mrSample.b * metallic;\n#endif\n perceptualRoughness = clamp(perceptualRoughness, c_MinRoughness, 1.0);\n metallic = clamp(metallic, 0.0, 1.0);\n // Roughness is authored as perceptual roughness; as is convention,\n // convert to material roughness by squaring the perceptual roughness [2].\n float alphaRoughness = perceptualRoughness * perceptualRoughness;\n\n vec3 f0 = vec3(0.04);\n vec3 diffuseColor = baseColor.rgb * (vec3(1.0) - f0);\n diffuseColor *= 1.0 - metallic;\n vec3 specularColor = mix(f0, baseColor.rgb, metallic);\n\n // Compute reflectance.\n float reflectance = max(max(specularColor.r, specularColor.g), specularColor.b);\n\n // For typical incident reflectance range (between 4% to 100%) set the grazing\n // reflectance to 100% for typical fresnel effect.\n // For very low reflectance range on highly diffuse objects (below 4%),\n // incrementally reduce grazing reflecance to 0%.\n float reflectance90 = clamp(reflectance * 25.0, 0.0, 1.0);\n vec3 specularEnvironmentR0 = specularColor.rgb;\n vec3 specularEnvironmentR90 = vec3(1.0, 1.0, 1.0) * reflectance90;\n\n vec3 n = getNormal(); // normal at surface point\n vec3 v = normalize(u_Camera - pbr_vPosition); // Vector from surface point to camera\n\n float NdotV = clamp(abs(dot(n, v)), 0.001, 1.0);\n vec3 reflection = -normalize(reflect(v, n));\n\n PBRInfo pbrInputs = PBRInfo(\n 0.0, // NdotL\n NdotV,\n 0.0, // NdotH\n 0.0, // LdotH\n 0.0, // VdotH\n perceptualRoughness,\n metallic,\n specularEnvironmentR0,\n specularEnvironmentR90,\n alphaRoughness,\n diffuseColor,\n specularColor,\n n,\n v\n );\n\n#ifdef USE_LIGHTS\n // Apply ambient light\n PBRInfo_setAmbientLight(pbrInputs);\n color += calculateFinalColor(pbrInputs, lighting_uAmbientLight.color);\n\n // Apply directional light\n SMART_FOR(int i = 0, i < MAX_LIGHTS, i < lighting_uDirectionalLightCount, i++) {\n if (i < lighting_uDirectionalLightCount) {\n PBRInfo_setDirectionalLight(pbrInputs, lighting_uDirectionalLight[i].direction);\n color += calculateFinalColor(pbrInputs, lighting_uDirectionalLight[i].color);\n }\n }\n\n // Apply point light\n SMART_FOR(int i = 0, i < MAX_LIGHTS, i < lighting_uPointLightCount, i++) {\n if (i < lighting_uPointLightCount) {\n PBRInfo_setPointLight(pbrInputs, lighting_uPointLight[i]);\n float attenuation = getPointLightAttenuation(lighting_uPointLight[i], distance(lighting_uPointLight[i].position, pbr_vPosition));\n color += calculateFinalColor(pbrInputs, lighting_uPointLight[i].color / attenuation);\n }\n }\n#endif\n\n // Calculate lighting contribution from image based lighting source (IBL)\n#ifdef USE_IBL\n color += getIBLContribution(pbrInputs, n, reflection);\n#endif\n\n // Apply optional PBR terms for additional (optional) shading\n#ifdef HAS_OCCLUSIONMAP\n float ao = texture(u_OcclusionSampler, pbr_vUV).r;\n color = mix(color, color * ao, u_OcclusionStrength);\n#endif\n\n#ifdef HAS_EMISSIVEMAP\n vec3 emissive = SRGBtoLINEAR(texture(u_EmissiveSampler, pbr_vUV)).rgb * u_EmissiveFactor;\n color += emissive;\n#endif\n\n // This section uses mix to override final color for reference app visualization\n // of various parameters in the lighting equation.\n#ifdef PBR_DEBUG\n // TODO: Figure out how to debug multiple lights\n\n // color = mix(color, F, u_ScaleFGDSpec.x);\n // color = mix(color, vec3(G), u_ScaleFGDSpec.y);\n // color = mix(color, vec3(D), u_ScaleFGDSpec.z);\n // color = mix(color, specContrib, u_ScaleFGDSpec.w);\n\n // color = mix(color, diffuseContrib, u_ScaleDiffBaseMR.x);\n color = mix(color, baseColor.rgb, u_ScaleDiffBaseMR.y);\n color = mix(color, vec3(metallic), u_ScaleDiffBaseMR.z);\n color = mix(color, vec3(perceptualRoughness), u_ScaleDiffBaseMR.w);\n#endif\n\n }\n\n return vec4(pow(color,vec3(1.0/2.2)), baseColor.a);\n}\n`;\n"],"mappings":"SAOQA,IAAI;AAEZ,OAAO,MAAMC,EAAE,GAAGD,IAAK;AACvB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,CAAC"}
@@ -4,14 +4,14 @@ uniform mat4 u_MVPMatrix;
4
4
  uniform mat4 u_ModelMatrix;
5
5
  uniform mat4 u_NormalMatrix;
6
6
 
7
- varying vec3 pbr_vPosition;
8
- varying vec2 pbr_vUV;
7
+ out vec3 pbr_vPosition;
8
+ out vec2 pbr_vUV;
9
9
 
10
10
  #ifdef HAS_NORMALS
11
11
  # ifdef HAS_TANGENTS
12
- varying mat3 pbr_vTBN;
12
+ out mat3 pbr_vTBN;
13
13
  # else
14
- varying vec3 pbr_vNormal;
14
+ out vec3 pbr_vNormal;
15
15
  # endif
16
16
  #endif
17
17
 
@@ -1 +1 @@
1
- {"version":3,"file":"pbr-vertex.glsl.js","names":["glsl","vs"],"sources":["../../../../src/modules-webgl1/lighting/pbr/pbr-vertex.glsl.ts"],"sourcesContent":["import {glsl} from '../../../lib/glsl-utils/highlight';\n\nexport const vs = glsl`\\\nuniform mat4 u_MVPMatrix;\nuniform mat4 u_ModelMatrix;\nuniform mat4 u_NormalMatrix;\n\nvarying vec3 pbr_vPosition;\nvarying vec2 pbr_vUV;\n\n#ifdef HAS_NORMALS\n# ifdef HAS_TANGENTS\nvarying mat3 pbr_vTBN;\n# else\nvarying vec3 pbr_vNormal;\n# endif\n#endif\n\nvoid pbr_setPositionNormalTangentUV(vec4 position, vec4 normal, vec4 tangent, vec2 uv)\n{\n vec4 pos = u_ModelMatrix * position;\n pbr_vPosition = vec3(pos.xyz) / pos.w;\n\n#ifdef HAS_NORMALS\n#ifdef HAS_TANGENTS\n vec3 normalW = normalize(vec3(u_NormalMatrix * vec4(normal.xyz, 0.0)));\n vec3 tangentW = normalize(vec3(u_ModelMatrix * vec4(tangent.xyz, 0.0)));\n vec3 bitangentW = cross(normalW, tangentW) * tangent.w;\n pbr_vTBN = mat3(tangentW, bitangentW, normalW);\n#else // HAS_TANGENTS != 1\n pbr_vNormal = normalize(vec3(u_ModelMatrix * vec4(normal.xyz, 0.0)));\n#endif\n#endif\n\n#ifdef HAS_UV\n pbr_vUV = uv;\n#else\n pbr_vUV = vec2(0.,0.);\n#endif\n}\n`;\n"],"mappings":"SAAQA,IAAI;AAEZ,OAAO,MAAMC,EAAE,GAAGD,IAAK;AACvB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,CAAC"}
1
+ {"version":3,"file":"pbr-vertex.glsl.js","names":["glsl","vs"],"sources":["../../../../src/modules-webgl1/lighting/pbr/pbr-vertex.glsl.ts"],"sourcesContent":["import {glsl} from '../../../lib/glsl-utils/highlight';\n\nexport const vs = glsl`\\\nuniform mat4 u_MVPMatrix;\nuniform mat4 u_ModelMatrix;\nuniform mat4 u_NormalMatrix;\n\nout vec3 pbr_vPosition;\nout vec2 pbr_vUV;\n\n#ifdef HAS_NORMALS\n# ifdef HAS_TANGENTS\nout mat3 pbr_vTBN;\n# else\nout vec3 pbr_vNormal;\n# endif\n#endif\n\nvoid pbr_setPositionNormalTangentUV(vec4 position, vec4 normal, vec4 tangent, vec2 uv)\n{\n vec4 pos = u_ModelMatrix * position;\n pbr_vPosition = vec3(pos.xyz) / pos.w;\n\n#ifdef HAS_NORMALS\n#ifdef HAS_TANGENTS\n vec3 normalW = normalize(vec3(u_NormalMatrix * vec4(normal.xyz, 0.0)));\n vec3 tangentW = normalize(vec3(u_ModelMatrix * vec4(tangent.xyz, 0.0)));\n vec3 bitangentW = cross(normalW, tangentW) * tangent.w;\n pbr_vTBN = mat3(tangentW, bitangentW, normalW);\n#else // HAS_TANGENTS != 1\n pbr_vNormal = normalize(vec3(u_ModelMatrix * vec4(normal.xyz, 0.0)));\n#endif\n#endif\n\n#ifdef HAS_UV\n pbr_vUV = uv;\n#else\n pbr_vUV = vec2(0.,0.);\n#endif\n}\n`;\n"],"mappings":"SAAQA,IAAI;AAEZ,OAAO,MAAMC,EAAE,GAAGD,IAAK;AACvB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,CAAC"}
package/dist.min.js CHANGED
@@ -5857,14 +5857,14 @@ vec3 lighting_getSpecularLightColor(vec3 cameraPosition, vec3 position_worldspac
5857
5857
  uniform mat4 u_ModelMatrix;
5858
5858
  uniform mat4 u_NormalMatrix;
5859
5859
 
5860
- varying vec3 pbr_vPosition;
5861
- varying vec2 pbr_vUV;
5860
+ out vec3 pbr_vPosition;
5861
+ out vec2 pbr_vUV;
5862
5862
 
5863
5863
  #ifdef HAS_NORMALS
5864
5864
  # ifdef HAS_TANGENTS
5865
- varying mat3 pbr_vTBN;
5865
+ out mat3 pbr_vTBN;
5866
5866
  # else
5867
- varying vec3 pbr_vNormal;
5867
+ out vec3 pbr_vNormal;
5868
5868
  # endif
5869
5869
  #endif
5870
5870
 
@@ -5895,14 +5895,14 @@ uniform mat4 u_MVPMatrix;
5895
5895
  uniform mat4 u_ModelMatrix;
5896
5896
  uniform mat4 u_NormalMatrix;
5897
5897
 
5898
- varying vec3 pbr_vPosition;
5899
- varying vec2 pbr_vUV;
5898
+ out vec3 pbr_vPosition;
5899
+ out vec2 pbr_vUV;
5900
5900
 
5901
5901
  #ifdef HAS_NORMALS
5902
5902
  # ifdef HAS_TANGENTS
5903
- varying mat3 pbr_vTBN;
5903
+ out mat3 pbr_vTBN;
5904
5904
  # else
5905
- varying vec3 pbr_vNormal;
5905
+ out vec3 pbr_vNormal;
5906
5906
  # endif
5907
5907
  #endif
5908
5908
 
@@ -5990,15 +5990,15 @@ uniform vec4 u_ScaleDiffBaseMR;
5990
5990
  uniform vec4 u_ScaleFGDSpec;
5991
5991
  #endif
5992
5992
 
5993
- varying vec3 pbr_vPosition;
5993
+ in vec3 pbr_vPosition;
5994
5994
 
5995
- varying vec2 pbr_vUV;
5995
+ in vec2 pbr_vUV;
5996
5996
 
5997
5997
  #ifdef HAS_NORMALS
5998
5998
  #ifdef HAS_TANGENTS
5999
- varying mat3 pbr_vTBN;
5999
+ in mat3 pbr_vTBN;
6000
6000
  #else
6001
- varying vec3 pbr_vNormal;
6001
+ in vec3 pbr_vNormal;
6002
6002
  #endif
6003
6003
  #endif
6004
6004
 
@@ -6067,7 +6067,7 @@ vec3 getNormal()
6067
6067
  #endif
6068
6068
 
6069
6069
  #ifdef HAS_NORMALMAP
6070
- vec3 n = texture2D(u_NormalSampler, pbr_vUV).rgb;
6070
+ vec3 n = texture(u_NormalSampler, pbr_vUV).rgb;
6071
6071
  n = normalize(tbn * ((2.0 * n - 1.0) * vec3(u_NormalScale, u_NormalScale, 1.0)));
6072
6072
  #else
6073
6073
  // The tbn matrix is linearly interpolated, so we need to re-normalize
@@ -6086,7 +6086,7 @@ vec3 getIBLContribution(PBRInfo pbrInputs, vec3 n, vec3 reflection)
6086
6086
  float mipCount = 9.0; // resolution of 512x512
6087
6087
  float lod = (pbrInputs.perceptualRoughness * mipCount);
6088
6088
  // retrieve a scale and bias to F0. See [1], Figure 3
6089
- vec3 brdf = SRGBtoLINEAR(texture2D(u_brdfLUT,
6089
+ vec3 brdf = SRGBtoLINEAR(texture(u_brdfLUT,
6090
6090
  vec2(pbrInputs.NdotV, 1.0 - pbrInputs.perceptualRoughness))).rgb;
6091
6091
  vec3 diffuseLight = SRGBtoLINEAR(textureCube(u_DiffuseEnvSampler, n)).rgb;
6092
6092
 
@@ -6193,7 +6193,7 @@ vec4 pbr_filterColor(vec4 colorUnused)
6193
6193
  {
6194
6194
  // The albedo may be defined from a base texture or a flat color
6195
6195
  #ifdef HAS_BASECOLORMAP
6196
- vec4 baseColor = SRGBtoLINEAR(texture2D(u_BaseColorSampler, pbr_vUV)) * u_BaseColorFactor;
6196
+ vec4 baseColor = SRGBtoLINEAR(texture(u_BaseColorSampler, pbr_vUV)) * u_BaseColorFactor;
6197
6197
  #else
6198
6198
  vec4 baseColor = u_BaseColorFactor;
6199
6199
  #endif
@@ -6218,7 +6218,7 @@ vec4 pbr_filterColor(vec4 colorUnused)
6218
6218
  #ifdef HAS_METALROUGHNESSMAP
6219
6219
  // Roughness is stored in the 'g' channel, metallic is stored in the 'b' channel.
6220
6220
  // This layout intentionally reserves the 'r' channel for (optional) occlusion map data
6221
- vec4 mrSample = texture2D(u_MetallicRoughnessSampler, pbr_vUV);
6221
+ vec4 mrSample = texture(u_MetallicRoughnessSampler, pbr_vUV);
6222
6222
  perceptualRoughness = mrSample.g * perceptualRoughness;
6223
6223
  metallic = mrSample.b * metallic;
6224
6224
  #endif
@@ -6297,12 +6297,12 @@ vec4 pbr_filterColor(vec4 colorUnused)
6297
6297
 
6298
6298
  // Apply optional PBR terms for additional (optional) shading
6299
6299
  #ifdef HAS_OCCLUSIONMAP
6300
- float ao = texture2D(u_OcclusionSampler, pbr_vUV).r;
6300
+ float ao = texture(u_OcclusionSampler, pbr_vUV).r;
6301
6301
  color = mix(color, color * ao, u_OcclusionStrength);
6302
6302
  #endif
6303
6303
 
6304
6304
  #ifdef HAS_EMISSIVEMAP
6305
- vec3 emissive = SRGBtoLINEAR(texture2D(u_EmissiveSampler, pbr_vUV)).rgb * u_EmissiveFactor;
6305
+ vec3 emissive = SRGBtoLINEAR(texture(u_EmissiveSampler, pbr_vUV)).rgb * u_EmissiveFactor;
6306
6306
  color += emissive;
6307
6307
  #endif
6308
6308
 
@@ -6389,15 +6389,15 @@ uniform vec4 u_ScaleDiffBaseMR;
6389
6389
  uniform vec4 u_ScaleFGDSpec;
6390
6390
  #endif
6391
6391
 
6392
- varying vec3 pbr_vPosition;
6392
+ in vec3 pbr_vPosition;
6393
6393
 
6394
- varying vec2 pbr_vUV;
6394
+ in vec2 pbr_vUV;
6395
6395
 
6396
6396
  #ifdef HAS_NORMALS
6397
6397
  #ifdef HAS_TANGENTS
6398
- varying mat3 pbr_vTBN;
6398
+ in mat3 pbr_vTBN;
6399
6399
  #else
6400
- varying vec3 pbr_vNormal;
6400
+ in vec3 pbr_vNormal;
6401
6401
  #endif
6402
6402
  #endif
6403
6403
 
@@ -6466,7 +6466,7 @@ vec3 getNormal()
6466
6466
  #endif
6467
6467
 
6468
6468
  #ifdef HAS_NORMALMAP
6469
- vec3 n = texture2D(u_NormalSampler, pbr_vUV).rgb;
6469
+ vec3 n = texture(u_NormalSampler, pbr_vUV).rgb;
6470
6470
  n = normalize(tbn * ((2.0 * n - 1.0) * vec3(u_NormalScale, u_NormalScale, 1.0)));
6471
6471
  #else
6472
6472
  // The tbn matrix is linearly interpolated, so we need to re-normalize
@@ -6485,7 +6485,7 @@ vec3 getIBLContribution(PBRInfo pbrInputs, vec3 n, vec3 reflection)
6485
6485
  float mipCount = 9.0; // resolution of 512x512
6486
6486
  float lod = (pbrInputs.perceptualRoughness * mipCount);
6487
6487
  // retrieve a scale and bias to F0. See [1], Figure 3
6488
- vec3 brdf = SRGBtoLINEAR(texture2D(u_brdfLUT,
6488
+ vec3 brdf = SRGBtoLINEAR(texture(u_brdfLUT,
6489
6489
  vec2(pbrInputs.NdotV, 1.0 - pbrInputs.perceptualRoughness))).rgb;
6490
6490
  vec3 diffuseLight = SRGBtoLINEAR(textureCube(u_DiffuseEnvSampler, n)).rgb;
6491
6491
 
@@ -6592,7 +6592,7 @@ vec4 pbr_filterColor(vec4 colorUnused)
6592
6592
  {
6593
6593
  // The albedo may be defined from a base texture or a flat color
6594
6594
  #ifdef HAS_BASECOLORMAP
6595
- vec4 baseColor = SRGBtoLINEAR(texture2D(u_BaseColorSampler, pbr_vUV)) * u_BaseColorFactor;
6595
+ vec4 baseColor = SRGBtoLINEAR(texture(u_BaseColorSampler, pbr_vUV)) * u_BaseColorFactor;
6596
6596
  #else
6597
6597
  vec4 baseColor = u_BaseColorFactor;
6598
6598
  #endif
@@ -6617,7 +6617,7 @@ vec4 pbr_filterColor(vec4 colorUnused)
6617
6617
  #ifdef HAS_METALROUGHNESSMAP
6618
6618
  // Roughness is stored in the 'g' channel, metallic is stored in the 'b' channel.
6619
6619
  // This layout intentionally reserves the 'r' channel for (optional) occlusion map data
6620
- vec4 mrSample = texture2D(u_MetallicRoughnessSampler, pbr_vUV);
6620
+ vec4 mrSample = texture(u_MetallicRoughnessSampler, pbr_vUV);
6621
6621
  perceptualRoughness = mrSample.g * perceptualRoughness;
6622
6622
  metallic = mrSample.b * metallic;
6623
6623
  #endif
@@ -6696,12 +6696,12 @@ vec4 pbr_filterColor(vec4 colorUnused)
6696
6696
 
6697
6697
  // Apply optional PBR terms for additional (optional) shading
6698
6698
  #ifdef HAS_OCCLUSIONMAP
6699
- float ao = texture2D(u_OcclusionSampler, pbr_vUV).r;
6699
+ float ao = texture(u_OcclusionSampler, pbr_vUV).r;
6700
6700
  color = mix(color, color * ao, u_OcclusionStrength);
6701
6701
  #endif
6702
6702
 
6703
6703
  #ifdef HAS_EMISSIVEMAP
6704
- vec3 emissive = SRGBtoLINEAR(texture2D(u_EmissiveSampler, pbr_vUV)).rgb * u_EmissiveFactor;
6704
+ vec3 emissive = SRGBtoLINEAR(texture(u_EmissiveSampler, pbr_vUV)).rgb * u_EmissiveFactor;
6705
6705
  color += emissive;
6706
6706
  #endif
6707
6707
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@luma.gl/shadertools",
3
- "version": "9.0.0-alpha.50",
3
+ "version": "9.0.0-alpha.51",
4
4
  "description": "Shader module system for luma.gl",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -46,9 +46,9 @@
46
46
  },
47
47
  "dependencies": {
48
48
  "@babel/runtime": "^7.0.0",
49
- "@luma.gl/core": "9.0.0-alpha.50",
49
+ "@luma.gl/core": "9.0.0-alpha.51",
50
50
  "@math.gl/core": "^4.0.0",
51
51
  "@math.gl/types": "^4.0.0"
52
52
  },
53
- "gitHead": "83899806fcfab67f97cc8b308f81e4844a05ca05"
53
+ "gitHead": "368b615bdd46d0006717f004244a942f3d2812e7"
54
54
  }
@@ -70,15 +70,15 @@ uniform vec4 u_ScaleDiffBaseMR;
70
70
  uniform vec4 u_ScaleFGDSpec;
71
71
  #endif
72
72
 
73
- varying vec3 pbr_vPosition;
73
+ in vec3 pbr_vPosition;
74
74
 
75
- varying vec2 pbr_vUV;
75
+ in vec2 pbr_vUV;
76
76
 
77
77
  #ifdef HAS_NORMALS
78
78
  #ifdef HAS_TANGENTS
79
- varying mat3 pbr_vTBN;
79
+ in mat3 pbr_vTBN;
80
80
  #else
81
- varying vec3 pbr_vNormal;
81
+ in vec3 pbr_vNormal;
82
82
  #endif
83
83
  #endif
84
84
 
@@ -147,7 +147,7 @@ vec3 getNormal()
147
147
  #endif
148
148
 
149
149
  #ifdef HAS_NORMALMAP
150
- vec3 n = texture2D(u_NormalSampler, pbr_vUV).rgb;
150
+ vec3 n = texture(u_NormalSampler, pbr_vUV).rgb;
151
151
  n = normalize(tbn * ((2.0 * n - 1.0) * vec3(u_NormalScale, u_NormalScale, 1.0)));
152
152
  #else
153
153
  // The tbn matrix is linearly interpolated, so we need to re-normalize
@@ -166,7 +166,7 @@ vec3 getIBLContribution(PBRInfo pbrInputs, vec3 n, vec3 reflection)
166
166
  float mipCount = 9.0; // resolution of 512x512
167
167
  float lod = (pbrInputs.perceptualRoughness * mipCount);
168
168
  // retrieve a scale and bias to F0. See [1], Figure 3
169
- vec3 brdf = SRGBtoLINEAR(texture2D(u_brdfLUT,
169
+ vec3 brdf = SRGBtoLINEAR(texture(u_brdfLUT,
170
170
  vec2(pbrInputs.NdotV, 1.0 - pbrInputs.perceptualRoughness))).rgb;
171
171
  vec3 diffuseLight = SRGBtoLINEAR(textureCube(u_DiffuseEnvSampler, n)).rgb;
172
172
 
@@ -273,7 +273,7 @@ vec4 pbr_filterColor(vec4 colorUnused)
273
273
  {
274
274
  // The albedo may be defined from a base texture or a flat color
275
275
  #ifdef HAS_BASECOLORMAP
276
- vec4 baseColor = SRGBtoLINEAR(texture2D(u_BaseColorSampler, pbr_vUV)) * u_BaseColorFactor;
276
+ vec4 baseColor = SRGBtoLINEAR(texture(u_BaseColorSampler, pbr_vUV)) * u_BaseColorFactor;
277
277
  #else
278
278
  vec4 baseColor = u_BaseColorFactor;
279
279
  #endif
@@ -298,7 +298,7 @@ vec4 pbr_filterColor(vec4 colorUnused)
298
298
  #ifdef HAS_METALROUGHNESSMAP
299
299
  // Roughness is stored in the 'g' channel, metallic is stored in the 'b' channel.
300
300
  // This layout intentionally reserves the 'r' channel for (optional) occlusion map data
301
- vec4 mrSample = texture2D(u_MetallicRoughnessSampler, pbr_vUV);
301
+ vec4 mrSample = texture(u_MetallicRoughnessSampler, pbr_vUV);
302
302
  perceptualRoughness = mrSample.g * perceptualRoughness;
303
303
  metallic = mrSample.b * metallic;
304
304
  #endif
@@ -377,12 +377,12 @@ vec4 pbr_filterColor(vec4 colorUnused)
377
377
 
378
378
  // Apply optional PBR terms for additional (optional) shading
379
379
  #ifdef HAS_OCCLUSIONMAP
380
- float ao = texture2D(u_OcclusionSampler, pbr_vUV).r;
380
+ float ao = texture(u_OcclusionSampler, pbr_vUV).r;
381
381
  color = mix(color, color * ao, u_OcclusionStrength);
382
382
  #endif
383
383
 
384
384
  #ifdef HAS_EMISSIVEMAP
385
- vec3 emissive = SRGBtoLINEAR(texture2D(u_EmissiveSampler, pbr_vUV)).rgb * u_EmissiveFactor;
385
+ vec3 emissive = SRGBtoLINEAR(texture(u_EmissiveSampler, pbr_vUV)).rgb * u_EmissiveFactor;
386
386
  color += emissive;
387
387
  #endif
388
388
 
@@ -5,14 +5,14 @@ uniform mat4 u_MVPMatrix;
5
5
  uniform mat4 u_ModelMatrix;
6
6
  uniform mat4 u_NormalMatrix;
7
7
 
8
- varying vec3 pbr_vPosition;
9
- varying vec2 pbr_vUV;
8
+ out vec3 pbr_vPosition;
9
+ out vec2 pbr_vUV;
10
10
 
11
11
  #ifdef HAS_NORMALS
12
12
  # ifdef HAS_TANGENTS
13
- varying mat3 pbr_vTBN;
13
+ out mat3 pbr_vTBN;
14
14
  # else
15
- varying vec3 pbr_vNormal;
15
+ out vec3 pbr_vNormal;
16
16
  # endif
17
17
  #endif
18
18