@luma.gl/shaders 10.0.0-alpha.10 → 10.0.0-alpha.11

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.
Files changed (89) hide show
  1. package/dist/dist.dev.js +1776 -58
  2. package/dist/dist.min.js +1394 -147
  3. package/dist/index.cjs +35 -0
  4. package/dist/index.cjs.map +3 -3
  5. package/dist/index.d.ts +17 -0
  6. package/dist/index.d.ts.map +1 -1
  7. package/dist/index.js +9 -0
  8. package/dist/index.js.map +1 -1
  9. package/dist/modules/lighting/clustered-light-grid/clustered-light-grid.cjs +40 -0
  10. package/dist/modules/lighting/clustered-light-grid/clustered-light-grid.d.ts +6 -0
  11. package/dist/modules/lighting/clustered-light-grid/clustered-light-grid.d.ts.map +1 -0
  12. package/dist/modules/lighting/clustered-light-grid/clustered-light-grid.js +15 -0
  13. package/dist/modules/lighting/clustered-light-grid/clustered-light-grid.js.map +1 -0
  14. package/dist/modules/lighting/contact-shadow/contact-shadow.cjs +348 -0
  15. package/dist/modules/lighting/contact-shadow/contact-shadow.d.ts +188 -0
  16. package/dist/modules/lighting/contact-shadow/contact-shadow.d.ts.map +1 -0
  17. package/dist/modules/lighting/contact-shadow/contact-shadow.js +307 -0
  18. package/dist/modules/lighting/contact-shadow/contact-shadow.js.map +1 -0
  19. package/dist/modules/lighting/pbr-ambient-occlusion/pbr-ambient-occlusion.cjs +87 -0
  20. package/dist/modules/lighting/pbr-ambient-occlusion/pbr-ambient-occlusion.d.ts +21 -0
  21. package/dist/modules/lighting/pbr-ambient-occlusion/pbr-ambient-occlusion.d.ts.map +1 -0
  22. package/dist/modules/lighting/pbr-ambient-occlusion/pbr-ambient-occlusion.js +61 -0
  23. package/dist/modules/lighting/pbr-ambient-occlusion/pbr-ambient-occlusion.js.map +1 -0
  24. package/dist/modules/lighting/pbr-contact-shadow/pbr-contact-shadow.cjs +87 -0
  25. package/dist/modules/lighting/pbr-contact-shadow/pbr-contact-shadow.d.ts +21 -0
  26. package/dist/modules/lighting/pbr-contact-shadow/pbr-contact-shadow.d.ts.map +1 -0
  27. package/dist/modules/lighting/pbr-contact-shadow/pbr-contact-shadow.js +61 -0
  28. package/dist/modules/lighting/pbr-contact-shadow/pbr-contact-shadow.js.map +1 -0
  29. package/dist/modules/lighting/pbr-material/pbr-material-glsl.cjs +33 -11
  30. package/dist/modules/lighting/pbr-material/pbr-material-glsl.d.ts +2 -2
  31. package/dist/modules/lighting/pbr-material/pbr-material-glsl.d.ts.map +1 -1
  32. package/dist/modules/lighting/pbr-material/pbr-material-glsl.js +33 -11
  33. package/dist/modules/lighting/pbr-material/pbr-material-glsl.js.map +1 -1
  34. package/dist/modules/lighting/pbr-material/pbr-material-wgsl.cjs +33 -11
  35. package/dist/modules/lighting/pbr-material/pbr-material-wgsl.d.ts +1 -1
  36. package/dist/modules/lighting/pbr-material/pbr-material-wgsl.d.ts.map +1 -1
  37. package/dist/modules/lighting/pbr-material/pbr-material-wgsl.js +33 -11
  38. package/dist/modules/lighting/pbr-material/pbr-material-wgsl.js.map +1 -1
  39. package/dist/modules/lighting/pbr-material/pbr-material.d.ts +3 -3
  40. package/dist/modules/lighting/pbr-shadow/pbr-shadow.cjs +97 -0
  41. package/dist/modules/lighting/pbr-shadow/pbr-shadow.d.ts +15 -0
  42. package/dist/modules/lighting/pbr-shadow/pbr-shadow.d.ts.map +1 -0
  43. package/dist/modules/lighting/pbr-shadow/pbr-shadow.js +69 -0
  44. package/dist/modules/lighting/pbr-shadow/pbr-shadow.js.map +1 -0
  45. package/dist/modules/lighting/pbr-surface/pbr-surface.cjs +114 -0
  46. package/dist/modules/lighting/pbr-surface/pbr-surface.d.ts +15 -0
  47. package/dist/modules/lighting/pbr-surface/pbr-surface.d.ts.map +1 -0
  48. package/dist/modules/lighting/pbr-surface/pbr-surface.js +88 -0
  49. package/dist/modules/lighting/pbr-surface/pbr-surface.js.map +1 -0
  50. package/dist/modules/lighting/prefiltered-environment/prefiltered-environment.cjs +379 -0
  51. package/dist/modules/lighting/prefiltered-environment/prefiltered-environment.d.ts +41 -0
  52. package/dist/modules/lighting/prefiltered-environment/prefiltered-environment.d.ts.map +1 -0
  53. package/dist/modules/lighting/prefiltered-environment/prefiltered-environment.js +345 -0
  54. package/dist/modules/lighting/prefiltered-environment/prefiltered-environment.js.map +1 -0
  55. package/dist/modules/lighting/shadow/shadow-glsl.cjs +228 -0
  56. package/dist/modules/lighting/shadow/shadow-glsl.d.ts +3 -0
  57. package/dist/modules/lighting/shadow/shadow-glsl.d.ts.map +1 -0
  58. package/dist/modules/lighting/shadow/shadow-glsl.js +204 -0
  59. package/dist/modules/lighting/shadow/shadow-glsl.js.map +1 -0
  60. package/dist/modules/lighting/shadow/shadow-types.cjs +15 -0
  61. package/dist/modules/lighting/shadow/shadow-types.d.ts +63 -0
  62. package/dist/modules/lighting/shadow/shadow-types.d.ts.map +1 -0
  63. package/dist/modules/lighting/shadow/shadow-types.js +5 -0
  64. package/dist/modules/lighting/shadow/shadow-types.js.map +1 -0
  65. package/dist/modules/lighting/shadow/shadow.cjs +458 -0
  66. package/dist/modules/lighting/shadow/shadow.d.ts +117 -0
  67. package/dist/modules/lighting/shadow/shadow.d.ts.map +1 -0
  68. package/dist/modules/lighting/shadow/shadow.js +450 -0
  69. package/dist/modules/lighting/shadow/shadow.js.map +1 -0
  70. package/dist/modules/lighting/unlit-material/unlit-material.cjs +60 -0
  71. package/dist/modules/lighting/unlit-material/unlit-material.d.ts +9 -0
  72. package/dist/modules/lighting/unlit-material/unlit-material.d.ts.map +1 -0
  73. package/dist/modules/lighting/unlit-material/unlit-material.js +40 -0
  74. package/dist/modules/lighting/unlit-material/unlit-material.js.map +1 -0
  75. package/package.json +3 -3
  76. package/src/index.ts +48 -0
  77. package/src/modules/lighting/clustered-light-grid/clustered-light-grid.ts +17 -0
  78. package/src/modules/lighting/contact-shadow/contact-shadow.ts +365 -0
  79. package/src/modules/lighting/pbr-ambient-occlusion/pbr-ambient-occlusion.ts +78 -0
  80. package/src/modules/lighting/pbr-contact-shadow/pbr-contact-shadow.ts +78 -0
  81. package/src/modules/lighting/pbr-material/pbr-material-glsl.ts +33 -11
  82. package/src/modules/lighting/pbr-material/pbr-material-wgsl.ts +33 -11
  83. package/src/modules/lighting/pbr-shadow/pbr-shadow.ts +85 -0
  84. package/src/modules/lighting/pbr-surface/pbr-surface.ts +103 -0
  85. package/src/modules/lighting/prefiltered-environment/prefiltered-environment.ts +370 -0
  86. package/src/modules/lighting/shadow/shadow-glsl.ts +204 -0
  87. package/src/modules/lighting/shadow/shadow-types.ts +68 -0
  88. package/src/modules/lighting/shadow/shadow.ts +536 -0
  89. package/src/modules/lighting/unlit-material/unlit-material.ts +44 -0
@@ -0,0 +1,365 @@
1
+ // luma.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
4
+
5
+ import type {NumberArray3, NumberArray16} from '@math.gl/core';
6
+ import type {ShaderPass} from '../../../lib/shader-module/shader-pass';
7
+
8
+ const IDENTITY_MATRIX: NumberArray16 = [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];
9
+
10
+ export type ContactShadowBindings<TextureT = unknown> = {
11
+ depthTexture?: TextureT;
12
+ normalTexture?: TextureT;
13
+ };
14
+
15
+ export type ContactTraceUniforms = {
16
+ projectionMatrix: Readonly<NumberArray16>;
17
+ inverseProjectionMatrix: Readonly<NumberArray16>;
18
+ lightDirectionView: Readonly<NumberArray3>;
19
+ maxDistance: number;
20
+ thickness: number;
21
+ stepCount: number;
22
+ frameIndex: number;
23
+ normalBias: number;
24
+ };
25
+
26
+ /** Runtime controls accepted by the contact-shadow trace and composite passes. */
27
+ export type ContactShadowProps<TextureT = unknown> = Partial<ContactTraceUniforms> & {
28
+ strength?: number;
29
+ debugMode?: number;
30
+ directionalDirectTexture?: TextureT;
31
+ shadowDebugTexture?: TextureT;
32
+ };
33
+
34
+ export const contactShadowTrace = {
35
+ name: 'contactShadowTrace',
36
+ source: /* wgsl */ `\
37
+ struct contactShadowTraceUniforms {
38
+ projectionMatrix: mat4x4f,
39
+ inverseProjectionMatrix: mat4x4f,
40
+ lightDirectionView: vec3f,
41
+ maxDistance: f32,
42
+ thickness: f32,
43
+ stepCount: f32,
44
+ frameIndex: f32,
45
+ normalBias: f32,
46
+ };
47
+ @group(0) @binding(auto) var<uniform> contactShadowTrace: contactShadowTraceUniforms;
48
+ @group(0) @binding(auto) var depthTexture: texture_depth_2d;
49
+ @group(0) @binding(auto) var depthTextureSampler: sampler;
50
+ @group(0) @binding(auto) var normalTexture: texture_2d<f32>;
51
+ @group(0) @binding(auto) var normalTextureSampler: sampler;
52
+
53
+ fn contactShadow_reconstructViewPosition(uv: vec2f, depth: f32) -> vec3f {
54
+ let clip = vec4f(uv.x * 2.0 - 1.0, 1.0 - uv.y * 2.0, depth, 1.0);
55
+ let view = contactShadowTrace.inverseProjectionMatrix * clip;
56
+ return view.xyz / max(abs(view.w), 0.00001);
57
+ }
58
+
59
+ fn contactShadow_projectViewPosition(position: vec3f) -> vec2f {
60
+ let clip = contactShadowTrace.projectionMatrix * vec4f(position, 1.0);
61
+ let ndc = clip.xy / max(abs(clip.w), 0.00001);
62
+ return vec2f(ndc.x * 0.5 + 0.5, 0.5 - ndc.y * 0.5);
63
+ }
64
+
65
+ fn contactShadowTrace_sampleColor(
66
+ sourceTexture: texture_2d<f32>, sourceTextureSampler: sampler, texSize: vec2f, texCoord: vec2f
67
+ ) -> vec4f {
68
+ let centerDepth = textureSampleLevel(depthTexture, depthTextureSampler, texCoord, 0);
69
+ if (centerDepth >= 0.99999) { return vec4f(1.0); }
70
+ let centerNormal = normalize(textureSampleLevel(normalTexture, normalTextureSampler, texCoord, 0.0).xyz * 2.0 - 1.0);
71
+ let centerPosition = contactShadow_reconstructViewPosition(texCoord, centerDepth) + centerNormal * contactShadowTrace.normalBias;
72
+ let rayDirection = normalize(contactShadowTrace.lightDirectionView);
73
+ let noise = fract(sin(dot(texCoord * texSize + contactShadowTrace.frameIndex, vec2f(12.9898, 78.233))) * 43758.5453);
74
+ for (var index: i32 = 0; index < 40; index++) {
75
+ if (f32(index) >= contactShadowTrace.stepCount) { break; }
76
+ let fraction = (f32(index) + 0.35 + noise * 0.5) / max(contactShadowTrace.stepCount, 1.0);
77
+ let travel = contactShadowTrace.maxDistance * fraction * fraction;
78
+ let rayPosition = centerPosition + rayDirection * travel;
79
+ let sampleUv = contactShadow_projectViewPosition(rayPosition);
80
+ if (any(sampleUv <= vec2f(0.0)) || any(sampleUv >= vec2f(1.0))) { break; }
81
+ let sampleDepth = textureSampleLevel(depthTexture, depthTextureSampler, sampleUv, 0);
82
+ if (sampleDepth >= 0.99999) { continue; }
83
+ let scenePosition = contactShadow_reconstructViewPosition(sampleUv, sampleDepth);
84
+ let depthDelta = (-rayPosition.z) - (-scenePosition.z);
85
+ let hitThickness = contactShadowTrace.thickness + travel * 0.02;
86
+ if (depthDelta >= 0.0 && depthDelta <= hitThickness) {
87
+ let distanceFade = 1.0 - clamp(travel / contactShadowTrace.maxDistance, 0.0, 1.0);
88
+ return vec4f(vec3f(1.0 - distanceFade), 1.0);
89
+ }
90
+ if (depthDelta > hitThickness * 8.0) { break; }
91
+ }
92
+ return vec4f(1.0);
93
+ }`,
94
+ fs: /* glsl */ `
95
+ layout(std140) uniform contactShadowTraceUniforms {
96
+ mat4 projectionMatrix;
97
+ mat4 inverseProjectionMatrix;
98
+ vec3 lightDirectionView;
99
+ float maxDistance;
100
+ float thickness;
101
+ float stepCount;
102
+ float frameIndex;
103
+ float normalBias;
104
+ } contactShadowTrace;
105
+ uniform sampler2D depthTexture;
106
+ uniform sampler2D normalTexture;
107
+ vec3 contactShadow_reconstructViewPosition(vec2 uv, float depth) {
108
+ vec4 view = contactShadowTrace.inverseProjectionMatrix * vec4(uv * 2.0 - 1.0, depth * 2.0 - 1.0, 1.0);
109
+ return view.xyz / max(abs(view.w), 0.00001);
110
+ }
111
+ vec2 contactShadow_projectViewPosition(vec3 position) {
112
+ vec4 clip = contactShadowTrace.projectionMatrix * vec4(position,1.0);
113
+ return clip.xy / max(abs(clip.w),0.00001) * 0.5 + 0.5;
114
+ }
115
+ vec4 contactShadowTrace_sampleColor(sampler2D sourceTexture,vec2 texSize,vec2 texCoord) {
116
+ float centerDepth = texture(depthTexture,texCoord).r;
117
+ if(centerDepth >= 0.99999) return vec4(1.0);
118
+ vec3 centerNormal = normalize(texture(normalTexture,texCoord).xyz * 2.0 - 1.0);
119
+ vec3 centerPosition = contactShadow_reconstructViewPosition(texCoord,centerDepth) + centerNormal * contactShadowTrace.normalBias;
120
+ vec3 rayDirection = normalize(contactShadowTrace.lightDirectionView);
121
+ float noise = fract(sin(dot(texCoord * texSize + contactShadowTrace.frameIndex,vec2(12.9898,78.233))) * 43758.5453);
122
+ for(int index=0;index<40;index++) {
123
+ if(float(index)>=contactShadowTrace.stepCount) break;
124
+ float fraction=(float(index)+0.35+noise*0.5)/max(contactShadowTrace.stepCount,1.0);
125
+ float travel=contactShadowTrace.maxDistance*fraction*fraction;
126
+ vec3 rayPosition=centerPosition+rayDirection*travel;
127
+ vec2 sampleUv=contactShadow_projectViewPosition(rayPosition);
128
+ if(any(lessThanEqual(sampleUv,vec2(0.0)))||any(greaterThanEqual(sampleUv,vec2(1.0))))break;
129
+ float sampleDepth=texture(depthTexture,sampleUv).r;
130
+ if(sampleDepth>=0.99999)continue;
131
+ vec3 scenePosition=contactShadow_reconstructViewPosition(sampleUv,sampleDepth);
132
+ float depthDelta=(-rayPosition.z)-(-scenePosition.z);
133
+ float hitThickness=contactShadowTrace.thickness+travel*0.02;
134
+ if(depthDelta>=0.0&&depthDelta<=hitThickness) {
135
+ float distanceFade=1.0-clamp(travel/contactShadowTrace.maxDistance,0.0,1.0);
136
+ return vec4(vec3(1.0-distanceFade),1.0);
137
+ }
138
+ if(depthDelta>hitThickness*8.0)break;
139
+ }
140
+ return vec4(1.0);
141
+ }
142
+ `,
143
+ bindingLayout: [
144
+ {name: 'depthTexture', group: 0},
145
+ {name: 'normalTexture', group: 0}
146
+ ],
147
+ props: {} as Partial<ContactTraceUniforms> & ContactShadowBindings,
148
+ uniforms: {} as ContactTraceUniforms,
149
+ bindings: {} as ContactShadowBindings,
150
+ uniformTypes: {
151
+ projectionMatrix: 'mat4x4<f32>',
152
+ inverseProjectionMatrix: 'mat4x4<f32>',
153
+ lightDirectionView: 'vec3<f32>',
154
+ maxDistance: 'f32',
155
+ thickness: 'f32',
156
+ stepCount: 'f32',
157
+ frameIndex: 'f32',
158
+ normalBias: 'f32'
159
+ },
160
+ propTypes: {
161
+ projectionMatrix: {value: IDENTITY_MATRIX, private: true},
162
+ inverseProjectionMatrix: {value: IDENTITY_MATRIX, private: true},
163
+ lightDirectionView: {value: [0, 1, 0], private: true},
164
+ maxDistance: {value: 4, min: 0.1, softMax: 16},
165
+ thickness: {value: 0.12, min: 0.005, softMax: 1},
166
+ stepCount: {value: 24, min: 1, max: 40},
167
+ frameIndex: {value: 0, private: true},
168
+ normalBias: {value: 0.035, min: 0, softMax: 0.2}
169
+ },
170
+ passes: [{sampler: true}]
171
+ } as const satisfies ShaderPass<
172
+ Partial<ContactTraceUniforms> & ContactShadowBindings,
173
+ ContactTraceUniforms,
174
+ ContactShadowBindings
175
+ >;
176
+
177
+ export type ContactBlurUniforms = {
178
+ direction: [number, number];
179
+ radius: number;
180
+ depthSigma: number;
181
+ normalPower: number;
182
+ };
183
+
184
+ export const contactShadowBilateralBlur = {
185
+ name: 'contactShadowBilateralBlur',
186
+ source: /* wgsl */ `\
187
+ struct contactShadowBilateralBlurUniforms {
188
+ direction: vec2f,
189
+ radius: f32,
190
+ depthSigma: f32,
191
+ normalPower: f32,
192
+ };
193
+ @group(0) @binding(auto) var<uniform> contactShadowBilateralBlur: contactShadowBilateralBlurUniforms;
194
+ @group(0) @binding(auto) var depthTexture: texture_depth_2d;
195
+ @group(0) @binding(auto) var depthTextureSampler: sampler;
196
+ @group(0) @binding(auto) var normalTexture: texture_2d<f32>;
197
+ @group(0) @binding(auto) var normalTextureSampler: sampler;
198
+
199
+ fn contactShadowBilateralBlur_sampleColor(
200
+ sourceTexture: texture_2d<f32>, sourceTextureSampler: sampler, texSize: vec2f, texCoord: vec2f
201
+ ) -> vec4f {
202
+ let sourceDimensions = vec2f(textureDimensions(sourceTexture));
203
+ let texel = contactShadowBilateralBlur.direction / sourceDimensions;
204
+ let centerDepth = textureSampleLevel(depthTexture, depthTextureSampler, texCoord, 0);
205
+ let centerNormal = normalize(textureSampleLevel(normalTexture, normalTextureSampler, texCoord, 0.0).xyz * 2.0 - 1.0);
206
+ var result = textureSampleLevel(sourceTexture, sourceTextureSampler, texCoord, 0.0).r;
207
+ var totalWeight = 1.0;
208
+ for (var index: i32 = 1; index <= 6; index++) {
209
+ if (f32(index) > contactShadowBilateralBlur.radius) { break; }
210
+ for (var side: i32 = -1; side <= 1; side += 2) {
211
+ let sampleUv = clamp(texCoord + texel * f32(index * side), vec2f(0.0), vec2f(1.0));
212
+ let sampleDepth = textureSampleLevel(depthTexture, depthTextureSampler, sampleUv, 0);
213
+ let sampleNormal = normalize(textureSampleLevel(normalTexture, normalTextureSampler, sampleUv, 0.0).xyz * 2.0 - 1.0);
214
+ let depthDelta = abs(sampleDepth - centerDepth);
215
+ let depthWeight = exp(-(depthDelta * depthDelta) / max(2.0 * contactShadowBilateralBlur.depthSigma * contactShadowBilateralBlur.depthSigma, 0.000001));
216
+ let normalWeight = pow(max(dot(centerNormal, sampleNormal), 0.0), contactShadowBilateralBlur.normalPower);
217
+ let spatialWeight = exp(-f32(index * index) / 8.0);
218
+ let weight = depthWeight * normalWeight * spatialWeight;
219
+ result += textureSampleLevel(sourceTexture, sourceTextureSampler, sampleUv, 0.0).r * weight;
220
+ totalWeight += weight;
221
+ }
222
+ }
223
+ let visibility = result / totalWeight;
224
+ return vec4f(vec3f(visibility), 1.0);
225
+ }`,
226
+ fs: /* glsl */ `
227
+ layout(std140) uniform contactShadowBilateralBlurUniforms {
228
+ vec2 direction;
229
+ float radius;
230
+ float depthSigma;
231
+ float normalPower;
232
+ } contactShadowBilateralBlur;
233
+ uniform sampler2D depthTexture;
234
+ uniform sampler2D normalTexture;
235
+ vec4 contactShadowBilateralBlur_sampleColor(sampler2D sourceTexture,vec2 texSize,vec2 texCoord) {
236
+ vec2 texel=contactShadowBilateralBlur.direction/vec2(textureSize(sourceTexture,0));
237
+ float centerDepth=texture(depthTexture,texCoord).r;
238
+ vec3 centerNormal=normalize(texture(normalTexture,texCoord).xyz*2.0-1.0);
239
+ float result=texture(sourceTexture,texCoord).r;
240
+ float totalWeight=1.0;
241
+ for(int index=1;index<=6;index++) {
242
+ if(float(index)>contactShadowBilateralBlur.radius)break;
243
+ for(int side=-1;side<=1;side+=2) {
244
+ vec2 sampleUv=clamp(texCoord+texel*float(index*side),vec2(0.0),vec2(1.0));
245
+ float sampleDepth=texture(depthTexture,sampleUv).r;
246
+ vec3 sampleNormal=normalize(texture(normalTexture,sampleUv).xyz*2.0-1.0);
247
+ float depthDelta=abs(sampleDepth-centerDepth);
248
+ float depthWeight=exp(-(depthDelta*depthDelta)/max(2.0*contactShadowBilateralBlur.depthSigma*contactShadowBilateralBlur.depthSigma,0.000001));
249
+ float normalWeight=pow(max(dot(centerNormal,sampleNormal),0.0),contactShadowBilateralBlur.normalPower);
250
+ float spatialWeight=exp(-float(index*index)/8.0);
251
+ float weight=depthWeight*normalWeight*spatialWeight;
252
+ result+=texture(sourceTexture,sampleUv).r*weight;totalWeight+=weight;
253
+ }
254
+ }
255
+ return vec4(vec3(result/totalWeight),1.0);
256
+ }
257
+ `,
258
+ bindingLayout: [
259
+ {name: 'depthTexture', group: 0},
260
+ {name: 'normalTexture', group: 0}
261
+ ],
262
+ props: {} as Partial<ContactBlurUniforms> & ContactShadowBindings,
263
+ uniforms: {} as ContactBlurUniforms,
264
+ bindings: {} as ContactShadowBindings,
265
+ uniformTypes: {
266
+ direction: 'vec2<f32>',
267
+ radius: 'f32',
268
+ depthSigma: 'f32',
269
+ normalPower: 'f32'
270
+ },
271
+ propTypes: {
272
+ direction: {value: [1, 0], private: true},
273
+ radius: {value: 4, min: 1, max: 6},
274
+ depthSigma: {value: 0.006, min: 0.0001, softMax: 0.05},
275
+ normalPower: {value: 24, min: 1, softMax: 64}
276
+ },
277
+ passes: [{sampler: true}]
278
+ } as const satisfies ShaderPass<
279
+ Partial<ContactBlurUniforms> & ContactShadowBindings,
280
+ ContactBlurUniforms,
281
+ ContactShadowBindings
282
+ >;
283
+
284
+ export type ContactCompositeBindings<TextureT = unknown> = {
285
+ contactShadowTexture?: TextureT;
286
+ directionalDirectTexture?: TextureT;
287
+ shadowDebugTexture?: TextureT;
288
+ };
289
+
290
+ type ContactCompositeUniforms = {strength: number; debugMode: number};
291
+
292
+ export const contactShadowComposite = {
293
+ name: 'contactShadowComposite',
294
+ source: /* wgsl */ `\
295
+ struct contactShadowCompositeUniforms {
296
+ strength: f32,
297
+ debugMode: f32,
298
+ };
299
+ @group(0) @binding(auto) var<uniform> contactShadowComposite: contactShadowCompositeUniforms;
300
+ @group(0) @binding(auto) var contactShadowTexture: texture_2d<f32>;
301
+ @group(0) @binding(auto) var contactShadowTextureSampler: sampler;
302
+ @group(0) @binding(auto) var directionalDirectTexture: texture_2d<f32>;
303
+ @group(0) @binding(auto) var directionalDirectTextureSampler: sampler;
304
+ @group(0) @binding(auto) var shadowDebugTexture: texture_2d<f32>;
305
+ @group(0) @binding(auto) var shadowDebugTextureSampler: sampler;
306
+
307
+ fn contactShadowComposite_sampleColor(
308
+ sourceTexture: texture_2d<f32>, sourceTextureSampler: sampler, texSize: vec2f, texCoord: vec2f
309
+ ) -> vec4f {
310
+ let color = textureSampleLevel(sourceTexture, sourceTextureSampler, texCoord, 0.0);
311
+ let contact = textureSampleLevel(contactShadowTexture, contactShadowTextureSampler, texCoord, 0.0).r;
312
+ let appliedContact = mix(1.0, contact, contactShadowComposite.strength);
313
+ if (contactShadowComposite.debugMode > 0.5 && contactShadowComposite.debugMode < 1.5) {
314
+ return vec4f(vec3f(contact), 1.0);
315
+ }
316
+ if (contactShadowComposite.debugMode >= 1.5) {
317
+ let factors = textureSampleLevel(shadowDebugTexture, shadowDebugTextureSampler, texCoord, 0.0).rgb;
318
+ return vec4f(vec3f(factors.x * factors.y * factors.z * contact), 1.0);
319
+ }
320
+ let directionalDirect = textureSampleLevel(
321
+ directionalDirectTexture,
322
+ directionalDirectTextureSampler,
323
+ texCoord,
324
+ 0.0
325
+ ).rgb;
326
+ return vec4f(max(color.rgb - directionalDirect * (1.0 - appliedContact), vec3f(0.0)), color.a);
327
+ }`,
328
+ fs: /* glsl */ `
329
+ layout(std140) uniform contactShadowCompositeUniforms {
330
+ float strength;
331
+ float debugMode;
332
+ } contactShadowComposite;
333
+ uniform sampler2D contactShadowTexture;
334
+ uniform sampler2D directionalDirectTexture;
335
+ uniform sampler2D shadowDebugTexture;
336
+ vec4 contactShadowComposite_sampleColor(sampler2D sourceTexture,vec2 texSize,vec2 texCoord) {
337
+ vec4 color=texture(sourceTexture,texCoord);
338
+ float contact=texture(contactShadowTexture,texCoord).r;
339
+ float appliedContact=mix(1.0,contact,contactShadowComposite.strength);
340
+ if(contactShadowComposite.debugMode>0.5&&contactShadowComposite.debugMode<1.5)return vec4(vec3(contact),1.0);
341
+ if(contactShadowComposite.debugMode>=1.5){vec3 factors=texture(shadowDebugTexture,texCoord).rgb;return vec4(vec3(factors.x*factors.y*factors.z*contact),1.0);}
342
+ vec3 directionalDirect=texture(directionalDirectTexture,texCoord).rgb;
343
+ return vec4(max(color.rgb-directionalDirect*(1.0-appliedContact),vec3(0.0)),color.a);
344
+ }
345
+ `,
346
+ bindingLayout: [
347
+ {name: 'contactShadowTexture', group: 0},
348
+ {name: 'directionalDirectTexture', group: 0},
349
+ {name: 'shadowDebugTexture', group: 0}
350
+ ],
351
+ props: {} as Partial<ContactCompositeUniforms> & ContactCompositeBindings,
352
+ uniforms: {} as ContactCompositeUniforms,
353
+ bindings: {} as ContactCompositeBindings,
354
+ uniformTypes: {strength: 'f32', debugMode: 'f32'},
355
+ propTypes: {
356
+ strength: {value: 1, min: 0, max: 1},
357
+ debugMode: {value: 0, min: 0, max: 2, private: true}
358
+ },
359
+ passes: [{sampler: true}]
360
+ } as const satisfies ShaderPass<
361
+ Partial<ContactCompositeUniforms> & ContactCompositeBindings,
362
+ ContactCompositeUniforms,
363
+ ContactCompositeBindings,
364
+ 'contactShadowFiltered'
365
+ >;
@@ -0,0 +1,78 @@
1
+ // SPDX-License-Identifier: MIT
2
+ // SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
3
+
4
+ import type {NumberArray4} from '@math.gl/core';
5
+ import type {ShaderModule} from '../../../lib/shader-module/shader-module';
6
+ import {pbrMaterial} from '../pbr-material/pbr-material';
7
+
8
+ export type PBRAmbientOcclusionProps<TextureT = unknown> = {
9
+ ambientOcclusionTexture?: TextureT;
10
+ /** Origin and dimensions of the receiver viewport, in physical pixels. */
11
+ viewport?: Readonly<NumberArray4>;
12
+ strength?: number;
13
+ enabled?: boolean;
14
+ };
15
+ type AmbientUniforms = {viewport: Readonly<NumberArray4>; strength: number; enabled: number};
16
+ type AmbientBindings<TextureT = unknown> = {ambientOcclusionTexture?: TextureT};
17
+
18
+ /** Sets ambient visibility for the canonical PBR material; direct lighting and emission remain independent. */
19
+ export const pbrAmbientOcclusion: ShaderModule<
20
+ PBRAmbientOcclusionProps,
21
+ AmbientUniforms,
22
+ AmbientBindings
23
+ > = {
24
+ name: 'pbrAmbientOcclusion',
25
+ dependencies: [pbrMaterial],
26
+ bindingLayout: [
27
+ {name: 'pbrAmbientOcclusion', group: 0},
28
+ {name: 'ambientOcclusionTexture', group: 2}
29
+ ],
30
+ uniformTypes: {viewport: 'vec4<f32>', strength: 'f32', enabled: 'i32'},
31
+ defaultUniforms: {viewport: [0, 0, 1, 1], strength: 1, enabled: 1},
32
+ getUniforms(properties = {}) {
33
+ return {
34
+ ...(properties.viewport ? {viewport: properties.viewport} : {}),
35
+ ...(properties.strength === undefined ? {} : {strength: properties.strength}),
36
+ ...(properties.enabled === undefined ? {} : {enabled: Number(properties.enabled)}),
37
+ ...(properties.ambientOcclusionTexture
38
+ ? {ambientOcclusionTexture: properties.ambientOcclusionTexture}
39
+ : {})
40
+ };
41
+ },
42
+ source: /* wgsl */ `
43
+ struct PBRAmbientOcclusionUniforms {
44
+ viewport: vec4f,
45
+ strength: f32,
46
+ enabled: i32,
47
+ };
48
+ @group(0) @binding(auto) var<uniform> pbrAmbientOcclusion: PBRAmbientOcclusionUniforms;
49
+ @group(2) @binding(auto) var ambientOcclusionTexture: texture_2d<f32>;
50
+ @group(2) @binding(auto) var ambientOcclusionTextureSampler: sampler;
51
+ fn pbrAmbientOcclusion_getFactor(pixelPosition:vec2f)->f32 {
52
+ if(pbrAmbientOcclusion.enabled==0){return 1.0;}
53
+ let coordinates=(pixelPosition-pbrAmbientOcclusion.viewport.xy)/pbrAmbientOcclusion.viewport.zw;
54
+ if(any(coordinates<vec2f(0.0))||any(coordinates>vec2f(1.0))){return 1.0;}
55
+ let visibility=textureSampleLevel(ambientOcclusionTexture,ambientOcclusionTextureSampler,coordinates,0.0).r;
56
+ return mix(1.0,clamp(visibility,0.0,1.0),clamp(pbrAmbientOcclusion.strength,0.0,1.0));
57
+ }
58
+ fn pbrAmbientOcclusion_setFactor(pixelPosition:vec2f) {
59
+ pbr_ambientVisibility = pbrAmbientOcclusion_getFactor(pixelPosition);
60
+ }`,
61
+ fs: /* glsl */ `
62
+ layout(std140) uniform pbrAmbientOcclusionUniforms {
63
+ vec4 viewport;
64
+ float strength;
65
+ int enabled;
66
+ } pbrAmbientOcclusion;
67
+ uniform sampler2D ambientOcclusionTexture;
68
+ float pbrAmbientOcclusion_getFactor(vec2 pixelPosition) {
69
+ if(pbrAmbientOcclusion.enabled==0)return 1.0;
70
+ vec2 coordinates=(pixelPosition-pbrAmbientOcclusion.viewport.xy)/pbrAmbientOcclusion.viewport.zw;
71
+ if(any(lessThan(coordinates,vec2(0.0)))||any(greaterThan(coordinates,vec2(1.0))))return 1.0;
72
+ float visibility=texture(ambientOcclusionTexture,coordinates).r;
73
+ return mix(1.0,clamp(visibility,0.0,1.0),clamp(pbrAmbientOcclusion.strength,0.0,1.0));
74
+ }
75
+ void pbrAmbientOcclusion_setFactor(vec2 pixelPosition) {
76
+ pbr_ambientVisibility = pbrAmbientOcclusion_getFactor(pixelPosition);
77
+ }`
78
+ };
@@ -0,0 +1,78 @@
1
+ // SPDX-License-Identifier: MIT
2
+ // SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
3
+
4
+ import type {NumberArray4} from '@math.gl/core';
5
+ import type {ShaderModule} from '../../../lib/shader-module/shader-module';
6
+ import {pbrMaterial} from '../pbr-material/pbr-material';
7
+
8
+ export type PBRContactShadowProps<TextureT = unknown> = {
9
+ contactShadowTexture?: TextureT;
10
+ /** Origin and dimensions of the receiver viewport, in physical pixels. */
11
+ viewport?: Readonly<NumberArray4>;
12
+ strength?: number;
13
+ enabled?: boolean;
14
+ };
15
+ type ContactUniforms = {viewport: Readonly<NumberArray4>; strength: number; enabled: number};
16
+ type ContactBindings<TextureT = unknown> = {contactShadowTexture?: TextureT};
17
+
18
+ /** Applies a screen-space visibility mask to the first directional light only. */
19
+ export const pbrContactShadow: ShaderModule<
20
+ PBRContactShadowProps,
21
+ ContactUniforms,
22
+ ContactBindings
23
+ > = {
24
+ name: 'pbrContactShadow',
25
+ dependencies: [pbrMaterial],
26
+ bindingLayout: [
27
+ {name: 'pbrContactShadow', group: 0},
28
+ {name: 'contactShadowTexture', group: 2}
29
+ ],
30
+ uniformTypes: {viewport: 'vec4<f32>', strength: 'f32', enabled: 'i32'},
31
+ defaultUniforms: {viewport: [0, 0, 1, 1], strength: 1, enabled: 1},
32
+ getUniforms(properties = {}) {
33
+ return {
34
+ ...(properties.viewport ? {viewport: properties.viewport} : {}),
35
+ ...(properties.strength === undefined ? {} : {strength: properties.strength}),
36
+ ...(properties.enabled === undefined ? {} : {enabled: Number(properties.enabled)}),
37
+ ...(properties.contactShadowTexture
38
+ ? {contactShadowTexture: properties.contactShadowTexture}
39
+ : {})
40
+ };
41
+ },
42
+ source: /* wgsl */ `
43
+ struct PBRContactShadowUniforms {
44
+ viewport: vec4f,
45
+ strength: f32,
46
+ enabled: i32,
47
+ };
48
+ @group(0) @binding(auto) var<uniform> pbrContactShadow: PBRContactShadowUniforms;
49
+ @group(2) @binding(auto) var contactShadowTexture: texture_2d<f32>;
50
+ @group(2) @binding(auto) var contactShadowTextureSampler: sampler;
51
+ fn pbrContactShadow_getFactor(pixelPosition:vec2f)->f32 {
52
+ if(pbrContactShadow.enabled==0){return 1.0;}
53
+ let coordinates=(pixelPosition-pbrContactShadow.viewport.xy)/pbrContactShadow.viewport.zw;
54
+ if(any(coordinates<vec2f(0.0))||any(coordinates>vec2f(1.0))){return 1.0;}
55
+ let visibility=textureSampleLevel(contactShadowTexture,contactShadowTextureSampler,coordinates,0.0).r;
56
+ return mix(1.0,clamp(visibility,0.0,1.0),clamp(pbrContactShadow.strength,0.0,1.0));
57
+ }
58
+ fn pbrContactShadow_filterColor(vertexColor:vec4f,pixelPosition:vec2f)->vec4f {
59
+ return pbr_filterColorWithShadows(vertexColor,pbrContactShadow_getFactor(pixelPosition),vec4f(1.0),vec4f(1.0));
60
+ }`,
61
+ fs: /* glsl */ `
62
+ layout(std140) uniform pbrContactShadowUniforms {
63
+ vec4 viewport;
64
+ float strength;
65
+ int enabled;
66
+ } pbrContactShadow;
67
+ uniform sampler2D contactShadowTexture;
68
+ float pbrContactShadow_getFactor(vec2 pixelPosition) {
69
+ if(pbrContactShadow.enabled==0)return 1.0;
70
+ vec2 coordinates=(pixelPosition-pbrContactShadow.viewport.xy)/pbrContactShadow.viewport.zw;
71
+ if(any(lessThan(coordinates,vec2(0.0)))||any(greaterThan(coordinates,vec2(1.0))))return 1.0;
72
+ float visibility=texture(contactShadowTexture,coordinates).r;
73
+ return mix(1.0,clamp(visibility,0.0,1.0),clamp(pbrContactShadow.strength,0.0,1.0));
74
+ }
75
+ vec4 pbrContactShadow_filterColor(vec4 vertexColor,vec2 pixelPosition) {
76
+ return pbr_filterColorWithShadows(vertexColor,pbrContactShadow_getFactor(pixelPosition),vec4(1.0),vec4(1.0));
77
+ }`
78
+ };
@@ -41,7 +41,7 @@ void pbr_setPositionNormalTangentUV(
41
41
  vec3 bitangentW = cross(normalW, tangentW) * tangent.w;
42
42
  pbr_vTBN = mat3(tangentW, bitangentW, normalW);
43
43
  #else // HAS_TANGENTS != 1
44
- pbr_vNormal = normalize(vec3(pbrProjection.modelMatrix * vec4(normal.xyz, 0.0)));
44
+ pbr_vNormal = normalize(vec3(pbrProjection.normalMatrix * vec4(normal.xyz, 0.0)));
45
45
  #endif
46
46
  #endif
47
47
 
@@ -1047,7 +1047,9 @@ vec3 calculateFinalColor(PBRInfo pbrInfo, vec3 lightColor) {
1047
1047
  }
1048
1048
 
1049
1049
  // Visibility for the first four spotlights; environment and other lights are unaffected.
1050
- vec4 pbr_filterColorWithSpotShadows(vec4 vertexColor, vec4 spotVisibility)
1050
+ float pbr_ambientVisibility = 1.0;
1051
+
1052
+ vec4 pbr_filterColorWithShadows(vec4 vertexColor, float directionalVisibility, vec4 pointVisibility, vec4 spotVisibility)
1051
1053
  {
1052
1054
  vec2 baseColorUV = getMaterialUV(pbrMaterial.baseColorUVSet, pbrMaterial.baseColorUVTransform);
1053
1055
  vec2 metallicRoughnessUV = getMaterialUV(
@@ -1143,7 +1145,7 @@ vec4 pbr_filterColorWithSpotShadows(vec4 vertexColor, vec4 spotVisibility)
1143
1145
  color.rgb = baseColor.rgb;
1144
1146
  #ifdef HAS_LIGHTMAP
1145
1147
  if (pbrMaterial.lightmapMapEnabled) {
1146
- color *= lightmapIrradiance / M_PI;
1148
+ color *= lightmapIrradiance / M_PI * pbr_ambientVisibility;
1147
1149
  #ifdef HAS_OCCLUSIONMAP
1148
1150
  if (pbrMaterial.occlusionMapEnabled) {
1149
1151
  float ao = texture(pbr_occlusionSampler, occlusionUV).r;
@@ -1245,12 +1247,12 @@ vec4 pbr_filterColorWithSpotShadows(vec4 vertexColor, vec4 spotVisibility)
1245
1247
 
1246
1248
  #ifdef USE_LIGHTS
1247
1249
  PBRInfo_setAmbientLight(pbrInfo);
1248
- color += calculateFinalColor(pbrInfo, lighting.ambientColor);
1250
+ color += calculateFinalColor(pbrInfo, lighting.ambientColor * pbr_ambientVisibility);
1249
1251
 
1250
1252
  for(int i = 0; i < lighting.directionalLightCount; i++) {
1251
1253
  if (i < lighting.directionalLightCount) {
1252
1254
  PBRInfo_setDirectionalLight(pbrInfo, -lighting_getDirectionalLight(i).direction);
1253
- color += calculateFinalColor(pbrInfo, lighting_getDirectionalLight(i).color);
1255
+ color += calculateFinalColor(pbrInfo, lighting_getDirectionalLight(i).color * (i == 0 ? clamp(directionalVisibility, 0.0, 1.0) : 1.0));
1254
1256
  }
1255
1257
  }
1256
1258
 
@@ -1258,7 +1260,7 @@ vec4 pbr_filterColorWithSpotShadows(vec4 vertexColor, vec4 spotVisibility)
1258
1260
  if (i < lighting.pointLightCount) {
1259
1261
  PBRInfo_setPointLight(pbrInfo, lighting_getPointLight(i));
1260
1262
  float attenuation = getPointLightAttenuation(lighting_getPointLight(i), distance(lighting_getPointLight(i).position, pbr_vPosition));
1261
- color += calculateFinalColor(pbrInfo, lighting_getPointLight(i).color / attenuation);
1263
+ color += calculateFinalColor(pbrInfo, lighting_getPointLight(i).color * (i < 4 ? clamp(pointVisibility[min(i, 3)], 0.0, 1.0) : 1.0) / attenuation);
1262
1264
  }
1263
1265
  }
1264
1266
 
@@ -1284,6 +1286,7 @@ vec4 pbr_filterColorWithSpotShadows(vec4 vertexColor, vec4 spotVisibility)
1284
1286
  }
1285
1287
  #endif
1286
1288
 
1289
+ vec3 indirectBaseColor = color;
1287
1290
  #ifdef USE_IBL
1288
1291
  if (pbrMaterial.IBLenabled) {
1289
1292
  color += getIBLContribution(pbrInfo, n, reflection);
@@ -1292,6 +1295,7 @@ vec4 pbr_filterColorWithSpotShadows(vec4 vertexColor, vec4 spotVisibility)
1292
1295
 
1293
1296
  // The pinned KHR_lightmap draft explicitly defines c_diff = (1 - metallic) * baseColor.
1294
1297
  color += baseColor.rgb * (1.0 - metallic) * lightmapIrradiance / M_PI;
1298
+ color = indirectBaseColor + (color - indirectBaseColor) * pbr_ambientVisibility;
1295
1299
 
1296
1300
  #ifdef HAS_OCCLUSIONMAP
1297
1301
  if (pbrMaterial.occlusionMapEnabled) {
@@ -1524,7 +1528,7 @@ vec4 pbr_filterColorWithSpotShadows(vec4 vertexColor, vec4 spotVisibility)
1524
1528
  PBRInfo_setAmbientLight(pbrInfo);
1525
1529
  color += calculateMaterialLightColor(
1526
1530
  pbrInfo,
1527
- lighting.ambientColor,
1531
+ lighting.ambientColor * pbr_ambientVisibility,
1528
1532
  clearcoatNormal,
1529
1533
  clearcoatFactor,
1530
1534
  clearcoatRoughness,
@@ -1540,7 +1544,7 @@ vec4 pbr_filterColorWithSpotShadows(vec4 vertexColor, vec4 spotVisibility)
1540
1544
  PBRInfo_setDirectionalLight(pbrInfo, -lighting_getDirectionalLight(i).direction);
1541
1545
  color += calculateMaterialLightColor(
1542
1546
  pbrInfo,
1543
- lighting_getDirectionalLight(i).color,
1547
+ lighting_getDirectionalLight(i).color * (i == 0 ? clamp(directionalVisibility, 0.0, 1.0) : 1.0),
1544
1548
  clearcoatNormal,
1545
1549
  clearcoatFactor,
1546
1550
  clearcoatRoughness,
@@ -1551,7 +1555,7 @@ vec4 pbr_filterColorWithSpotShadows(vec4 vertexColor, vec4 spotVisibility)
1551
1555
  );
1552
1556
  color += calculateDiffuseTransmissionLight(
1553
1557
  pbrInfo,
1554
- lighting_getDirectionalLight(i).color,
1558
+ lighting_getDirectionalLight(i).color * (i == 0 ? clamp(directionalVisibility, 0.0, 1.0) : 1.0),
1555
1559
  diffuseTransmissionColor,
1556
1560
  diffuseTransmission,
1557
1561
  multiscatterColor,
@@ -1567,7 +1571,7 @@ vec4 pbr_filterColorWithSpotShadows(vec4 vertexColor, vec4 spotVisibility)
1567
1571
  float attenuation = getPointLightAttenuation(lighting_getPointLight(i), distance(lighting_getPointLight(i).position, pbr_vPosition));
1568
1572
  color += calculateMaterialLightColor(
1569
1573
  pbrInfo,
1570
- lighting_getPointLight(i).color / attenuation,
1574
+ lighting_getPointLight(i).color * (i < 4 ? clamp(pointVisibility[min(i, 3)], 0.0, 1.0) : 1.0) / attenuation,
1571
1575
  clearcoatNormal,
1572
1576
  clearcoatFactor,
1573
1577
  clearcoatRoughness,
@@ -1578,7 +1582,7 @@ vec4 pbr_filterColorWithSpotShadows(vec4 vertexColor, vec4 spotVisibility)
1578
1582
  );
1579
1583
  color += calculateDiffuseTransmissionLight(
1580
1584
  pbrInfo,
1581
- lighting_getPointLight(i).color / attenuation,
1585
+ lighting_getPointLight(i).color * (i < 4 ? clamp(pointVisibility[min(i, 3)], 0.0, 1.0) : 1.0) / attenuation,
1582
1586
  diffuseTransmissionColor,
1583
1587
  diffuseTransmission,
1584
1588
  multiscatterColor,
@@ -1647,6 +1651,7 @@ vec4 pbr_filterColorWithSpotShadows(vec4 vertexColor, vec4 spotVisibility)
1647
1651
  }
1648
1652
  #endif
1649
1653
 
1654
+ vec3 indirectBaseColor = color;
1650
1655
  // Calculate lighting contribution from image based lighting source (IBL)
1651
1656
  #ifdef USE_IBL
1652
1657
  if (pbrMaterial.IBLenabled) {
@@ -1681,6 +1686,8 @@ vec4 pbr_filterColorWithSpotShadows(vec4 vertexColor, vec4 spotVisibility)
1681
1686
  (1.0 - diffuseTransmission) * baseLayerEnergy * lightmapIrradiance / M_PI;
1682
1687
  #endif
1683
1688
 
1689
+ color = indirectBaseColor + (color - indirectBaseColor) * pbr_ambientVisibility;
1690
+
1684
1691
  // Apply optional PBR terms for additional (optional) shading
1685
1692
  #ifdef HAS_OCCLUSIONMAP
1686
1693
  if (pbrMaterial.occlusionMapEnabled) {
@@ -1742,6 +1749,21 @@ vec4 pbr_filterColorWithSpotShadows(vec4 vertexColor, vec4 spotVisibility)
1742
1749
  return vec4(applySceneColorManagement(color), alpha);
1743
1750
  }
1744
1751
 
1752
+ // Depth-only passes use the same base-color alpha, vertex color and UV transform.
1753
+ void pbr_discardMaskedFragment(vec4 vertexColor) {
1754
+ #ifdef ALPHA_CUTOFF
1755
+ float alpha = pbrMaterial.baseColorFactor.a * vertexColor.a;
1756
+ #ifdef HAS_BASECOLORMAP
1757
+ alpha *= texture(pbr_baseColorSampler, getMaterialUV(pbrMaterial.baseColorUVSet, pbrMaterial.baseColorUVTransform)).a;
1758
+ #endif
1759
+ if (alpha < pbrMaterial.alphaCutoff) {discard;}
1760
+ #endif
1761
+ }
1762
+
1763
+ vec4 pbr_filterColorWithSpotShadows(vec4 vertexColor, vec4 spotVisibility) {
1764
+ return pbr_filterColorWithShadows(vertexColor, 1.0, vec4(1.0), spotVisibility);
1765
+ }
1766
+
1745
1767
  vec4 pbr_filterColor(vec4 vertexColor) {
1746
1768
  return pbr_filterColorWithSpotShadows(vertexColor, vec4(1.0));
1747
1769
  }