three-realtime-rt 0.3.0 → 0.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/RestirPass.js CHANGED
@@ -21,6 +21,7 @@ uniform sampler2D uGNormalMetal;
21
21
  uniform sampler2D uMaterialsTex; // row 1: emissive tris, rows 2..65: blue noise
22
22
  uniform vec4 uLightPosType[MAX_LIGHTS];
23
23
  uniform vec4 uLightColorRadius[MAX_LIGHTS];
24
+ uniform vec4 uLightDirCone[MAX_LIGHTS]; // spot: direction.xyz + cos(outer)
24
25
  uniform int uLightCount;
25
26
  uniform int uEmissiveCount;
26
27
  uniform float uFrame;
@@ -59,13 +60,20 @@ vec3 candidateContribution(float id, vec2 uv, vec3 P, vec3 N) {
59
60
  int i = int(id);
60
61
  vec4 posType = uLightPosType[i];
61
62
  vec4 colRad = uLightColorRadius[i];
62
- if (posType.w < 0.5) {
63
+ if (posType.w < 0.5 || posType.w >= 1.5) {
63
64
  vec3 d = posType.xyz - P; // light CENTER: soft-radius jitter re-drawn at shading
64
65
  float dl = length(d);
65
66
  if (dl < 1e-5) return vec3(0.0);
66
67
  float NdotL = dot(N, d / dl);
67
68
  if (NdotL <= 0.0) return vec3(0.0);
68
- return colRad.rgb * (NdotL / (dl * dl));
69
+ float cone = 1.0;
70
+ if (posType.w >= 1.5) {
71
+ // spot cone — MUST match RTLightingPass.spotFalloff for a consistent estimator
72
+ vec4 dc = uLightDirCone[i];
73
+ cone = smoothstep(dc.w, posType.w - 2.0, dot(dc.xyz, -d / dl));
74
+ if (cone <= 0.0) return vec3(0.0);
75
+ }
76
+ return colRad.rgb * (cone * NdotL / (dl * dl));
69
77
  }
70
78
  float NdotL = dot(N, -posType.xyz);
71
79
  if (NdotL <= 0.0) return vec3(0.0);
@@ -283,6 +291,7 @@ export class RestirPass {
283
291
  uMaterialsTex: { value: null },
284
292
  uLightPosType: { value: [] },
285
293
  uLightColorRadius: { value: [] },
294
+ uLightDirCone: { value: [] },
286
295
  uLightCount: { value: 0 },
287
296
  uEmissiveCount: { value: 0 },
288
297
  uFrame: { value: 0 },
@@ -334,6 +343,7 @@ export class RestirPass {
334
343
  u.uMaterialsTex.value = compiled.materialsTex;
335
344
  u.uLightPosType.value = compiled.lightPosType;
336
345
  u.uLightColorRadius.value = compiled.lightColorRadius;
346
+ u.uLightDirCone.value = compiled.lightDirCone;
337
347
  u.uLightCount.value = compiled.lightCount;
338
348
  u.uEmissiveCount.value = compiled.emissiveTriCount;
339
349
  }