@meimu/mutracer 0.1.3 → 0.1.4

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 (118) hide show
  1. package/dist/assets/bvh.worker.js +1 -1
  2. package/dist/mutracer.umd.js +4114 -4015
  3. package/docs/api.md +11 -9
  4. package/docs/threejs.md +30 -4
  5. package/lib/Engine.js +18 -1
  6. package/lib/Engine.js.map +1 -1
  7. package/lib/main.d.ts +1 -1
  8. package/lib/main.js.map +1 -1
  9. package/lib/oidn.d.ts +1 -1
  10. package/lib/oidnBundledWeights.cdn.d.ts +2 -2
  11. package/lib/renderer/MaterialTable.d.ts +1 -0
  12. package/lib/renderer/MaterialTable.js +10 -4
  13. package/lib/renderer/MaterialTable.js.map +1 -1
  14. package/lib/renderer/WGPUBloomPass.js +18 -18
  15. package/lib/renderer/WGPUFullQuadPass.js +6 -6
  16. package/lib/renderer/WGPUJNLMDenoiser.js +69 -69
  17. package/lib/renderer/WGPURayTraceOutput.js +14 -14
  18. package/lib/renderer/WGPURayTracePass.d.ts +2 -0
  19. package/lib/renderer/WGPURayTracePass.js +12 -6
  20. package/lib/renderer/WGPURayTracePass.js.map +1 -1
  21. package/lib/renderer/WGPURenderingPipeline.js +15 -15
  22. package/lib/renderer/WebGLJNLMDenoiser.js +69 -69
  23. package/lib/renderer/WebGLRayTraceOutputPass.js +4 -4
  24. package/lib/renderer/WebGLRayTracePass.d.ts +1 -0
  25. package/lib/renderer/WebGLRayTracePass.js +7 -1
  26. package/lib/renderer/WebGLRayTracePass.js.map +1 -1
  27. package/lib/renderer/envMapCreation.d.ts +5 -1
  28. package/lib/renderer/envMapCreation.js +42 -5
  29. package/lib/renderer/envMapCreation.js.map +1 -1
  30. package/lib/renderer/geometryUpdates.js +1 -1
  31. package/lib/renderer/geometryUpdates.js.map +1 -1
  32. package/lib/renderer/glsl/chunks/cameraRay.glsl.js +12 -12
  33. package/lib/renderer/glsl/chunks/envMap.glsl.js +66 -54
  34. package/lib/renderer/glsl/chunks/envMap.glsl.js.map +1 -1
  35. package/lib/renderer/glsl/chunks/intersect.glsl.js +316 -310
  36. package/lib/renderer/glsl/chunks/intersect.glsl.js.map +1 -1
  37. package/lib/renderer/glsl/chunks/materialBuffer.glsl.js +151 -119
  38. package/lib/renderer/glsl/chunks/materialBuffer.glsl.js.map +1 -1
  39. package/lib/renderer/glsl/chunks/openPbrBsdf.glsl.js +414 -414
  40. package/lib/renderer/glsl/chunks/rand.glsl.js +3 -3
  41. package/lib/renderer/glsl/chunks/random.glsl.js +3 -3
  42. package/lib/renderer/glsl/chunks/rayTraceCore.glsl.js +40 -39
  43. package/lib/renderer/glsl/chunks/rayTraceCore.glsl.js.map +1 -1
  44. package/lib/renderer/glsl/chunks/sampleLight.glsl.js +69 -69
  45. package/lib/renderer/glsl/chunks/sampleMaterial.glsl.js +78 -78
  46. package/lib/renderer/glsl/chunks/sampleShadowCatcher.glsl.js +12 -12
  47. package/lib/renderer/glsl/chunks/sampling.glsl.js +75 -75
  48. package/lib/renderer/glsl/chunks/sobol.glsl.js +61 -61
  49. package/lib/renderer/glsl/chunks/textureLinear.glsl.js +5 -5
  50. package/lib/renderer/glsl/chunks/uvProjection.glsl.js +11 -11
  51. package/lib/renderer/glsl/depthQuery.frag.js +5 -5
  52. package/lib/renderer/glsl/depthQuery.frag.js.map +1 -1
  53. package/lib/renderer/glsl/normalizeRayTraceOutput.frag.js +8 -8
  54. package/lib/renderer/glsl/rayTrace.frag.js +133 -133
  55. package/lib/renderer/glsl/rayTrace.frag.js.map +1 -1
  56. package/lib/renderer/glsl/shadowCatcher.frag.js +9 -9
  57. package/lib/renderer/glsl/shadowCatcher.frag.js.map +1 -1
  58. package/lib/renderer/glsl/webglPipeline.frag.js +52 -52
  59. package/lib/renderer/lightsUtil.js +6 -4
  60. package/lib/renderer/lightsUtil.js.map +1 -1
  61. package/lib/renderer/materialChanges.js +1 -1
  62. package/lib/renderer/materialChanges.js.map +1 -1
  63. package/lib/renderer/materialComparison.generated.js +36 -18
  64. package/lib/renderer/materialComparison.generated.js.map +1 -1
  65. package/lib/renderer/prepareMeshBVH.js +2 -2
  66. package/lib/renderer/prepareMeshBVH.js.map +1 -1
  67. package/lib/renderer/sceneChangeDetector.js +4 -1
  68. package/lib/renderer/sceneChangeDetector.js.map +1 -1
  69. package/lib/renderer/sceneLightChanges.js +3 -2
  70. package/lib/renderer/sceneLightChanges.js.map +1 -1
  71. package/lib/renderer/scratchSampling.js +18 -18
  72. package/lib/renderer/wgsl/chunks/common.wgsl.js +4 -4
  73. package/lib/renderer/wgsl/chunks/envMap.wgsl.d.ts +1 -1
  74. package/lib/renderer/wgsl/chunks/envMap.wgsl.js +39 -31
  75. package/lib/renderer/wgsl/chunks/envMap.wgsl.js.map +1 -1
  76. package/lib/renderer/wgsl/chunks/intersect.wgsl.js +475 -469
  77. package/lib/renderer/wgsl/chunks/intersect.wgsl.js.map +1 -1
  78. package/lib/renderer/wgsl/chunks/intersectionAlpha.wgsl.js +8 -8
  79. package/lib/renderer/wgsl/chunks/materialBuffer.wgsl.js +93 -59
  80. package/lib/renderer/wgsl/chunks/materialBuffer.wgsl.js.map +1 -1
  81. package/lib/renderer/wgsl/chunks/openPbrBsdf.wgsl.js +469 -469
  82. package/lib/renderer/wgsl/chunks/pdm_displacement.wgsl.d.ts +1 -1
  83. package/lib/renderer/wgsl/chunks/pdm_displacement.wgsl.js +117 -120
  84. package/lib/renderer/wgsl/chunks/pdm_displacement.wgsl.js.map +1 -1
  85. package/lib/renderer/wgsl/chunks/rand.wgsl.js +3 -3
  86. package/lib/renderer/wgsl/chunks/rayTraceCore.wgsl.js +25 -22
  87. package/lib/renderer/wgsl/chunks/rayTraceCore.wgsl.js.map +1 -1
  88. package/lib/renderer/wgsl/chunks/sampleLight.wgsl.js +127 -127
  89. package/lib/renderer/wgsl/chunks/sampleMaterial.wgsl.js +136 -136
  90. package/lib/renderer/wgsl/chunks/sampleShadowCatcher.wgsl.js +6 -6
  91. package/lib/renderer/wgsl/chunks/sampling.wgsl.js +73 -73
  92. package/lib/renderer/wgsl/chunks/sobol.wgsl.js +62 -62
  93. package/lib/renderer/wgsl/chunks/uvProjection.wgsl.js +11 -11
  94. package/lib/renderer/wgsl/compose.frag.wgsl.js +105 -105
  95. package/lib/renderer/wgsl/customDenoise.wgsl.js +10 -10
  96. package/lib/renderer/wgsl/depthQuery.wgsl.d.ts +1 -1
  97. package/lib/renderer/wgsl/depthQuery.wgsl.js +5 -5
  98. package/lib/renderer/wgsl/depthQuery.wgsl.js.map +1 -1
  99. package/lib/renderer/wgsl/offlineAdaptive.compute.js +28 -28
  100. package/lib/renderer/wgsl/rayTrace.compute.js +251 -248
  101. package/lib/renderer/wgsl/rayTrace.compute.js.map +1 -1
  102. package/lib/scene/EnvironmentLight.d.ts +9 -3
  103. package/lib/scene/EnvironmentLight.js +9 -2
  104. package/lib/scene/EnvironmentLight.js.map +1 -1
  105. package/lib/scene/Scene.d.ts +4 -0
  106. package/lib/scene/Scene.js.map +1 -1
  107. package/lib/scene/SpotLight.d.ts +2 -2
  108. package/lib/scene/SpotLight.js +1 -1
  109. package/lib/scene/SpotLight.js.map +1 -1
  110. package/lib/scene/Texture.d.ts +17 -6
  111. package/lib/scene/Texture.js +13 -4
  112. package/lib/scene/Texture.js.map +1 -1
  113. package/lib/util/fromTHREE.js +151 -29
  114. package/lib/util/fromTHREE.js.map +1 -1
  115. package/lib/version.d.ts +1 -1
  116. package/lib/version.js +1 -1
  117. package/lib/version.js.map +1 -1
  118. package/package.json +1 -1
@@ -12,25 +12,25 @@ int triangleIndex = primitiveOffset + k;
12
12
  ${skipTriangleCode}
13
13
  vec4 r3 = dp(triangleIndex);
14
14
  ivec3 index = floatBitsToInt(r3.xyz) + vertexOffset;
15
- fu tri = fu(
16
- ky(positionBuffer, index.x, vertexColumns).xyz,
17
- ky(positionBuffer, index.y, vertexColumns).xyz,
18
- ky(positionBuffer, index.z, vertexColumns).xyz
15
+ fA tri = fA(
16
+ kG(positionBuffer, index.x, vertexColumns).xyz,
17
+ kG(positionBuffer, index.y, vertexColumns).xyz,
18
+ kG(positionBuffer, index.z, vertexColumns).xyz
19
19
  );
20
- eB hit = fI(o, d, tri, ey, gL, tMax);
20
+ eC hit = fL(o, d, tri, ey, gP, tMax);
21
21
 
22
22
  if (hit.t > 0.0) {
23
23
  tMax = hit.t;
24
24
  vec3 e1 = tri.p1 - tri.p0;
25
25
  vec3 e2 = tri.p2 - tri.p0;
26
26
  vec3 faceNormal = normalize(cross(e1, e2));
27
- int kd = int(ae(
27
+ int kk = int(ae(
28
28
  floatBitsToInt(bv(cf * ${INSTANCE_VEC4_STRIDE}).z)
29
29
  ).x);
30
- bool iI = fetchMatData(
31
- kd * MAT_DATA_SIZE + MAT_ROW_ALPHA
30
+ bool iN = fetchMatData(
31
+ kk * MAT_DATA_SIZE + MAT_ROW_ALPHA
32
32
  ).z > 0.5;
33
- if (!doubleSided && !iI && dot(faceNormal, d) > 0.0) {
33
+ if (!doubleSided && !iN && dot(faceNormal, d) > 0.0) {
34
34
  continue;
35
35
  }
36
36
 
@@ -41,31 +41,31 @@ ${handleHitCode}
41
41
  return glsl `
42
42
  ivec2 stack[STACK_SIZE];
43
43
  int top = -1;
44
- int sG = -1;
44
+ int sO = -1;
45
45
  float tMax = ${initialTMax};
46
46
 
47
47
  vec3 o = ray.o;
48
48
  vec3 d = ray.d;
49
49
 
50
- bool qT = false;
51
- vec3 hx;
50
+ bool rb = false;
51
+ vec3 hB;
52
52
  vec3 aB;
53
- ivec3 hs;
53
+ ivec3 hw;
54
54
 
55
- fu lp;
55
+ fA lC;
56
56
 
57
57
 
58
58
  top = 0;
59
59
  stack[0] = ivec2(0, -1);
60
60
 
61
- int wk = 0;
62
- while(top >= 0 && wk < 5000) {
63
- wk++;
61
+ int wr = 0;
62
+ while(top >= 0 && wr < 5000) {
63
+ wr++;
64
64
  ivec2 node = stack[top--];
65
65
 
66
66
  int cf = node.y;
67
67
 
68
- if (cf != sG) {
68
+ if (cf != sO) {
69
69
  if (cf < 0) {
70
70
  o = ray.o;
71
71
  d = ray.d;
@@ -81,110 +81,110 @@ o = (w2l * vec4(ray.o, 1.0)).xyz;
81
81
  d = (w2l * vec4(ray.d, 0.0)).xyz;
82
82
  }
83
83
  ey = maxDimension(abs(d));
84
- gL = mj(d, ey);
85
- sG = cf;
84
+ gP = mv(d, ey);
85
+ sO = cf;
86
86
  }
87
87
 
88
88
  int bo = cf < 0 ? 0 : blasOffset;
89
- uint fG = cf < 0 ? 0u : floatBitsToUint(bv(cf * ${INSTANCE_VEC4_STRIDE}).x);
90
- int gN = int(fG >> 30u);
91
- int eS = int(fG & 0x3fffffffu);
89
+ uint fJ = cf < 0 ? 0u : floatBitsToUint(bv(cf * ${INSTANCE_VEC4_STRIDE}).x);
90
+ int gR = int(fJ >> 30u);
91
+ int eW = int(fJ & 0x3fffffffu);
92
92
  int bh = 0;
93
93
  int primitiveOffset = 0;
94
94
 
95
- if (gN == 3) {
96
- uint hS = uint(node.x);
97
- if ((hS & 0x80000000u) != 0u) {
98
- bh = int((hS >> 23u) & 0xffu);
99
- primitiveOffset = bo + eS + int(hS & 0x007fffffu);
95
+ if (gR == 3) {
96
+ uint hW = uint(node.x);
97
+ if ((hW & 0x80000000u) != 0u) {
98
+ bh = int((hW >> 23u) & 0xffu);
99
+ primitiveOffset = bo + eW + int(hW & 0x007fffffu);
100
100
  }
101
101
  else {
102
102
  int i = node.x + bo;
103
- vec4 ju = dp(i);
104
- vec4 fC = dp(i + 1);
105
- vec4 mK = dp(i + 2);
106
- vec4 mL = dp(i + 3);
107
- vec4 mM = dp(i + 4);
108
- uint header = floatBitsToUint(ju.w);
109
- int rv = int(header << 24u) >> 24;
110
- int rw = int((header >> 8u) << 24u) >> 24;
111
- int rA = int((header >> 16u) << 24u) >> 24;
112
- vec3 hF = vec3(
113
- uintBitsToFloat(uint(rv + 127) << 23u),
114
- uintBitsToFloat(uint(rw + 127) << 23u),
115
- uintBitsToFloat(uint(rA + 127) << 23u)
103
+ vec4 jA = dp(i);
104
+ vec4 fF = dp(i + 1);
105
+ vec4 mV = dp(i + 2);
106
+ vec4 mW = dp(i + 3);
107
+ vec4 mX = dp(i + 4);
108
+ uint header = floatBitsToUint(jA.w);
109
+ int rG = int(header << 24u) >> 24;
110
+ int rH = int((header >> 8u) << 24u) >> 24;
111
+ int rI = int((header >> 16u) << 24u) >> 24;
112
+ vec3 hJ = vec3(
113
+ uintBitsToFloat(uint(rG + 127) << 23u),
114
+ uintBitsToFloat(uint(rH + 127) << 23u),
115
+ uintBitsToFloat(uint(rI + 127) << 23u)
116
116
  );
117
- uint childBase = floatBitsToUint(fC.x);
118
- uint oH = floatBitsToUint(fC.y);
117
+ uint childBase = floatBitsToUint(fF.x);
118
+ uint oQ = floatBitsToUint(fF.y);
119
119
  uint internalMask = header >> 24u;
120
- uint ul = (d.x < 0.0 ? 4u : 0u) |
120
+ uint ut = (d.x < 0.0 ? 4u : 0u) |
121
121
  (d.y < 0.0 ? 2u : 0u) |
122
122
  (d.z < 0.0 ? 1u : 0u);
123
- uint gE[12] = uint[12](
124
- floatBitsToUint(mK.x), floatBitsToUint(mK.y),
125
- floatBitsToUint(mK.z), floatBitsToUint(mK.w),
126
- floatBitsToUint(mL.x), floatBitsToUint(mL.y),
127
- floatBitsToUint(mL.z), floatBitsToUint(mL.w),
128
- floatBitsToUint(mM.x), floatBitsToUint(mM.y),
129
- floatBitsToUint(mM.z), floatBitsToUint(mM.w)
123
+ uint gI[12] = uint[12](
124
+ floatBitsToUint(mV.x), floatBitsToUint(mV.y),
125
+ floatBitsToUint(mV.z), floatBitsToUint(mV.w),
126
+ floatBitsToUint(mW.x), floatBitsToUint(mW.y),
127
+ floatBitsToUint(mW.z), floatBitsToUint(mW.w),
128
+ floatBitsToUint(mX.x), floatBitsToUint(mX.y),
129
+ floatBitsToUint(mX.z), floatBitsToUint(mX.w)
130
130
  );
131
131
 
132
132
  for (int order = 7; order >= 0; order--) {
133
- uint slot = uint(order) ^ ul;
134
- uint su = slot >= 4u
135
- ? floatBitsToUint(fC.w)
136
- : floatBitsToUint(fC.z);
137
- uint meta = (su >> ((slot & 3u) * 8u)) & 0xffu;
133
+ uint slot = uint(order) ^ ut;
134
+ uint sE = slot >= 4u
135
+ ? floatBitsToUint(fF.w)
136
+ : floatBitsToUint(fF.z);
137
+ uint meta = (sE >> ((slot & 3u) * 8u)) & 0xffu;
138
138
  if (meta == 0u) continue;
139
- uint lO = (slot & 3u) * 8u;
140
- uint kM = slot >> 2u;
141
- vec3 tA = vec3(
142
- float((gE[kM] >> lO) & 0xffu),
143
- float((gE[2u + kM] >> lO) & 0xffu),
144
- float((gE[4u + kM] >> lO) & 0xffu)
139
+ uint lY = (slot & 3u) * 8u;
140
+ uint kV = slot >> 2u;
141
+ vec3 tH = vec3(
142
+ float((gI[kV] >> lY) & 0xffu),
143
+ float((gI[2u + kV] >> lY) & 0xffu),
144
+ float((gI[4u + kV] >> lY) & 0xffu)
145
145
  );
146
- vec3 tw = vec3(
147
- float((gE[6u + kM] >> lO) & 0xffu),
148
- float((gE[8u + kM] >> lO) & 0xffu),
149
- float((gE[10u + kM] >> lO) & 0xffu)
146
+ vec3 tG = vec3(
147
+ float((gI[6u + kV] >> lY) & 0xffu),
148
+ float((gI[8u + kV] >> lY) & 0xffu),
149
+ float((gI[10u + kV] >> lY) & 0xffu)
150
150
  );
151
- vec3 uP = ju.xyz + tA * hF;
152
- vec3 uO = ju.xyz + tw * hF;
153
- if (cM(o, d, uP, uO, tMax) <= 0.0) continue;
154
- uint jw = meta & 0x1fu;
155
- if (jw >= 24u) {
156
- uint ne = internalMask & ((1u << slot) - 1u);
157
- uint sQ = childBase + qK(ne);
151
+ vec3 uW = jA.xyz + tH * hJ;
152
+ vec3 uV = jA.xyz + tG * hJ;
153
+ if (cM(o, d, uW, uV, tMax) <= 0.0) continue;
154
+ uint jC = meta & 0x1fu;
155
+ if (jC >= 24u) {
156
+ uint ns = internalMask & ((1u << slot) - 1u);
157
+ uint sX = childBase + qT(ns);
158
158
  stack[++top] = ivec2(
159
- eS + int(sQ * 5u), cf
159
+ eW + int(sX * 5u), cf
160
160
  );
161
161
  }
162
162
  else {
163
- uint triangleCount = qK(meta >> 5u);
164
- uint rK = oH + jw;
165
- uint uZ = 0x80000000u |
163
+ uint triangleCount = qT(meta >> 5u);
164
+ uint rS = oQ + jC;
165
+ uint vh = 0x80000000u |
166
166
  (triangleCount << 23u) |
167
- (rK & 0x007fffffu);
168
- stack[++top] = ivec2(int(uZ), cf);
167
+ (rS & 0x007fffffu);
168
+ stack[++top] = ivec2(int(vh), cf);
169
169
  }
170
170
  }
171
171
  }
172
172
  }
173
- else if (gN == 2) {
173
+ else if (gR == 2) {
174
174
  int i = node.x + bo;
175
- vec4 uR = dp(i);
176
- vec4 uS = dp(i + 1);
177
- vec4 uT = dp(i + 2);
178
- vec4 uU = dp(i + 3);
179
- bh = int(floatBitsToUint(uT.w));
175
+ vec4 uY = dp(i);
176
+ vec4 uZ = dp(i + 1);
177
+ vec4 va = dp(i + 2);
178
+ vec4 vb = dp(i + 3);
179
+ bh = int(floatBitsToUint(va.w));
180
180
  if (bh > 0) {
181
- primitiveOffset = bo + eS + int(floatBitsToUint(uU.w));
181
+ primitiveOffset = bo + eW + int(floatBitsToUint(vb.w));
182
182
  }
183
183
  else {
184
- int left = eS + int(floatBitsToUint(uR.w) * 4u);
185
- int right = eS + int(floatBitsToUint(uS.w) * 4u);
186
- float d0 = cM(o, d, uR.xyz, uS.xyz, tMax);
187
- float d1 = cM(o, d, uT.xyz, uU.xyz, tMax);
184
+ int left = eW + int(floatBitsToUint(uY.w) * 4u);
185
+ int right = eW + int(floatBitsToUint(uZ.w) * 4u);
186
+ float d0 = cM(o, d, uY.xyz, uZ.xyz, tMax);
187
+ float d1 = cM(o, d, va.xyz, vb.xyz, tMax);
188
188
  if (d0 > d1) {
189
189
  if (d0 > 0.0) stack[++top] = ivec2(left, cf);
190
190
  if (d1 > 0.0) stack[++top] = ivec2(right, cf);
@@ -195,62 +195,62 @@ if (d0 > 0.0) stack[++top] = ivec2(left, cf);
195
195
  }
196
196
  }
197
197
  }
198
- else if (gN == 1) {
199
- uint hS = uint(node.x);
200
- if ((hS & 0x80000000u) != 0u) {
201
- bh = int((hS >> 23u) & 0xffu);
202
- primitiveOffset = bo + eS + int(hS & 0x007fffffu);
198
+ else if (gR == 1) {
199
+ uint hW = uint(node.x);
200
+ if ((hW & 0x80000000u) != 0u) {
201
+ bh = int((hW >> 23u) & 0xffu);
202
+ primitiveOffset = bo + eW + int(hW & 0x007fffffu);
203
203
  }
204
204
  else {
205
205
  int i = node.x + bo;
206
- vec4 ub = dp(i);
207
- vec4 rf = dp(i + 1);
208
- vec4 rh = dp(i + 2);
209
- vec4 ri = dp(i + 3);
210
- vec3 nodeMin = ub.xyz;
211
- vec3 ec = vec3(ub.w, rf.x, rf.y);
212
- uint lV[4] = uint[4](
213
- floatBitsToUint(rf.z), floatBitsToUint(rf.w),
214
- floatBitsToUint(rh.x), floatBitsToUint(rh.y)
206
+ vec4 ui = dp(i);
207
+ vec4 ro = dp(i + 1);
208
+ vec4 rp = dp(i + 2);
209
+ vec4 rq = dp(i + 3);
210
+ vec3 nodeMin = ui.xyz;
211
+ vec3 ec = vec3(ui.w, ro.x, ro.y);
212
+ uint mh[4] = uint[4](
213
+ floatBitsToUint(ro.z), floatBitsToUint(ro.w),
214
+ floatBitsToUint(rp.x), floatBitsToUint(rp.y)
215
215
  );
216
- vec4 ro = eY(floatBitsToUint(rh.z));
217
- vec4 rp = eY(floatBitsToUint(rh.w));
218
- vec4 rq = eY(floatBitsToUint(ri.x));
219
- vec4 rl = eY(floatBitsToUint(ri.y));
220
- vec4 rm = eY(floatBitsToUint(ri.z));
221
- vec4 rn = eY(floatBitsToUint(ri.w));
222
- vec3 gx = eX(d);
223
- vec3 bJ = eV(gx, o);
224
- vec4 tx0 = (nodeMin.x + ro * ec.x - o.x) * gx.x;
225
- vec4 tx1 = (nodeMin.x + rl * ec.x - o.x) * gx.x;
226
- vec4 ty0 = (nodeMin.y + rp * ec.y - o.y) * gx.y;
227
- vec4 ty1 = (nodeMin.y + rm * ec.y - o.y) * gx.y;
228
- vec4 tz0 = (nodeMin.z + rq * ec.z - o.z) * gx.z;
229
- vec4 tz1 = (nodeMin.z + rn * ec.z - o.z) * gx.z;
230
- vec4 mB = max(max((min(tx0, tx1) - vec4(bJ.x)), (min(ty0, ty1) - vec4(bJ.y))), (min(tz0, tz1) - vec4(bJ.z)));
231
- vec4 rM = min(min((max(tx0, tx1) + vec4(bJ.x)), (max(ty0, ty1) + vec4(bJ.y))), (max(tz0, tz1) + vec4(bJ.z)));
232
- vec4 distance = mix(rM, mB, greaterThan(mB, vec4(0.0)));
233
- distance = mix(distance, vec4(-1.0), greaterThan(mB, min(rM, vec4(tMax))));
234
- float fa[4] = float[4](distance.x, distance.y, distance.z, distance.w);
216
+ vec4 rw = fc(floatBitsToUint(rp.z));
217
+ vec4 rA = fc(floatBitsToUint(rp.w));
218
+ vec4 rB = fc(floatBitsToUint(rq.x));
219
+ vec4 rt = fc(floatBitsToUint(rq.y));
220
+ vec4 ru = fc(floatBitsToUint(rq.z));
221
+ vec4 rv = fc(floatBitsToUint(rq.w));
222
+ vec3 gC = fb(d);
223
+ vec3 bJ = eZ(gC, o);
224
+ vec4 tx0 = (nodeMin.x + rw * ec.x - o.x) * gC.x;
225
+ vec4 tx1 = (nodeMin.x + rt * ec.x - o.x) * gC.x;
226
+ vec4 ty0 = (nodeMin.y + rA * ec.y - o.y) * gC.y;
227
+ vec4 ty1 = (nodeMin.y + ru * ec.y - o.y) * gC.y;
228
+ vec4 tz0 = (nodeMin.z + rB * ec.z - o.z) * gC.z;
229
+ vec4 tz1 = (nodeMin.z + rv * ec.z - o.z) * gC.z;
230
+ vec4 mL = max(max((min(tx0, tx1) - vec4(bJ.x)), (min(ty0, ty1) - vec4(bJ.y))), (min(tz0, tz1) - vec4(bJ.z)));
231
+ vec4 rU = min(min((max(tx0, tx1) + vec4(bJ.x)), (max(ty0, ty1) + vec4(bJ.y))), (max(tz0, tz1) + vec4(bJ.z)));
232
+ vec4 distance = mix(rU, mL, greaterThan(mL, vec4(0.0)));
233
+ distance = mix(distance, vec4(-1.0), greaterThan(mL, min(rU, vec4(tMax))));
234
+ float fd[4] = float[4](distance.x, distance.y, distance.z, distance.w);
235
235
 
236
236
 
237
237
  for (int order = 0; order < 4; order++) {
238
238
  float dX = -1.0;
239
239
  int el = -1;
240
240
  for (int child = 0; child < 4; child++) {
241
- if (lV[child] != 0u && fa[child] > dX) {
242
- dX = fa[child];
241
+ if (mh[child] != 0u && fd[child] > dX) {
242
+ dX = fd[child];
243
243
  el = child;
244
244
  }
245
245
  }
246
246
  if (el >= 0 && dX > 0.0) {
247
- uint nl = lV[el];
248
- int jD = int(nl);
249
- if ((nl & 0x80000000u) == 0u) {
250
- jD += eS;
247
+ uint nD = mh[el];
248
+ int jI = int(nD);
249
+ if ((nD & 0x80000000u) == 0u) {
250
+ jI += eW;
251
251
  }
252
- stack[++top] = ivec2(jD, cf);
253
- fa[el] = -1.0;
252
+ stack[++top] = ivec2(jI, cf);
253
+ fd[el] = -1.0;
254
254
  }
255
255
  }
256
256
  }
@@ -262,7 +262,7 @@ int bb = floatBitsToInt(r1.w);
262
262
 
263
263
  if (bb >= 0) {
264
264
  int left = node.x + 2;
265
- int right = bb + eS;
265
+ int right = bb + eW;
266
266
 
267
267
  float d0 = cM(o, d, dp(left + bo).xyz, dp(left + 1 + bo).xyz, tMax);
268
268
  float d1 = cM(o, d, dp(right + bo).xyz, dp(right + 1 + bo).xyz, tMax);
@@ -321,13 +321,13 @@ export default createShaderMixin({
321
321
  },
322
322
  main: glsl `
323
323
 
324
- struct fu {
324
+ struct fA {
325
325
  vec3 p0;
326
326
  vec3 p1;
327
327
  vec3 p2;
328
328
  };
329
329
  #ifdef NUM_LIGHTS
330
- float ht(float rad, vec3 pos, Ray r) {
330
+ float hx(float rad, vec3 pos, Ray r) {
331
331
  vec3 op = pos - r.o;
332
332
  float eps = 0.001;
333
333
  float b = dot(op, r.d);
@@ -347,7 +347,7 @@ return t2;
347
347
  return INF;
348
348
  }
349
349
 
350
- float mU(vec3 pos, vec3 u, vec3 v, vec3 n, Ray r) {
350
+ float ni(vec3 pos, vec3 u, vec3 v, vec3 n, Ray r) {
351
351
  float dt = dot(r.d, n);
352
352
  float t = (dot(n, pos) - dot(n, r.o)) / dt;
353
353
 
@@ -366,7 +366,7 @@ return t;
366
366
  return INF;
367
367
  }
368
368
 
369
- float mo(Ray r, Light light, out LightSampleRec lightSample) {
369
+ float mz(Ray r, Light light, out LightSampleRec lightSample) {
370
370
 
371
371
 
372
372
 
@@ -383,7 +383,7 @@ vec3 normal = normalize(cross(u, v));
383
383
  if (dot(normal, r.d) > 0.)
384
384
  return INF;
385
385
 
386
- d = mU(pos, u, v, normal, r);
386
+ d = ni(pos, u, v, normal, r);
387
387
  if (d < 0.) {
388
388
  d = INF;
389
389
  }
@@ -400,9 +400,9 @@ lightSample.emission = light.emission;
400
400
  #ifdef HAS_SPHERE_LIGHTS
401
401
  if (type == SPHERE_LIGHT) {
402
402
  if (light.radius <= 0.0) {
403
- vec3 kh = light.position - r.o;
404
- float projection = dot(kh, r.d);
405
- vec3 ba = kh - projection * r.d;
403
+ vec3 ko = light.position - r.o;
404
+ float projection = dot(ko, r.d);
405
+ vec3 ba = ko - projection * r.d;
406
406
  if (projection <= EPS || dot(ba, ba) > 1e-8) return INF;
407
407
  d = projection;
408
408
  lightSample.direction = r.d;
@@ -411,7 +411,7 @@ lightSample.dist = d;
411
411
  lightSample.pdf = 1.0;
412
412
  lightSample.isDelta = true;
413
413
  } else {
414
- d = ht(light.radius, light.position, r);
414
+ d = hx(light.radius, light.position, r);
415
415
  lightSample.isDelta = false;
416
416
  }
417
417
  if (d < 0.) {
@@ -436,9 +436,9 @@ lightSample.emission = light.radius <= 0.0
436
436
  #ifdef HAS_SPOT_LIGHTS
437
437
  if (type == SPOT_LIGHT) {
438
438
  if (light.radius <= 0.0) {
439
- vec3 kh = light.position - r.o;
440
- float projection = dot(kh, r.d);
441
- vec3 ba = kh - projection * r.d;
439
+ vec3 ko = light.position - r.o;
440
+ float projection = dot(ko, r.d);
441
+ vec3 ba = ko - projection * r.d;
442
442
  if (projection <= EPS || dot(ba, ba) > 1e-8) return INF;
443
443
  d = projection;
444
444
  lightSample.direction = r.d;
@@ -447,13 +447,13 @@ lightSample.dist = d;
447
447
  lightSample.pdf = 1.0;
448
448
  lightSample.isDelta = true;
449
449
  } else {
450
- d = ht(light.radius, light.position, r);
450
+ d = hx(light.radius, light.position, r);
451
451
  lightSample.isDelta = false;
452
452
  }
453
453
  if (d != INF) {
454
- vec3 uX = r.o + d * r.d;
455
- float mr = bL(light, normalize(r.o - uX));
456
- if (mr <= 0.0) return INF;
454
+ vec3 ve = r.o + d * r.d;
455
+ float mC = bL(light, normalize(r.o - ve));
456
+ if (mC <= 0.0) return INF;
457
457
  float aj = distance(r.o, light.position);
458
458
  float cosThetaMax = aj <= light.radius
459
459
  ? -1.0
@@ -463,7 +463,7 @@ lightSample.pdf = aj <= light.radius
463
463
  ? INV4PI
464
464
  : 1.0 / max(TWOPI * (1.0 - cosThetaMax), 1e-8);
465
465
  }
466
- lightSample.emission = light.emission * mr * (light.radius <= 0.0
466
+ lightSample.emission = light.emission * mC * (light.radius <= 0.0
467
467
  ? 1.0 / max(d * d, 1e-8)
468
468
  : 1.0);
469
469
  }
@@ -474,7 +474,7 @@ return d;
474
474
  }
475
475
  #endif
476
476
 
477
- int fj(ivec4 m0, ivec4 m1, ivec4 m2, vec3 eZ) {
477
+ int fm(ivec4 m0, ivec4 m1, ivec4 m2, vec3 eK) {
478
478
  vec2 m00 = ae(m0.x);
479
479
  vec2 m01 = ae(m0.y);
480
480
  vec2 m02 = ae(m0.z);
@@ -484,86 +484,92 @@ vec2 m12 = ae(m1.z);
484
484
  vec2 m20 = ae(m2.x);
485
485
  vec2 m21 = ae(m2.y);
486
486
  vec2 m22 = ae(m2.z);
487
- float w00 = m00.y * eZ.x;
488
- float w01 = m01.y * eZ.x;
489
- float w02 = m02.y * eZ.x;
490
- float w10 = m10.y * eZ.y;
491
- float w11 = m11.y * eZ.y;
492
- float w12 = m12.y * eZ.y;
493
- float w20 = m20.y * eZ.z;
494
- float w21 = m21.y * eZ.z;
495
- float w22 = m22.y * eZ.z;
496
-
497
- float hg = w00 + w01 + w02 + w10 + w11 + w12 + w20 + w21 + w22;
498
-
499
- w00 = w00 / hg;
500
- w01 = w01 / hg + w00;
501
- w02 = w02 / hg + w01;
502
- w10 = w10 / hg + w02;
503
- w11 = w11 / hg + w10;
504
- w12 = w12 / hg + w11;
505
- w20 = w20 / hg + w12;
506
- w21 = w21 / hg + w20;
507
- w22 = w22 / hg + w21;
487
+ float w00 = m00.y * eK.x;
488
+ float w01 = m01.y * eK.x;
489
+ float w02 = m02.y * eK.x;
490
+ float w10 = m10.y * eK.y;
491
+ float w11 = m11.y * eK.y;
492
+ float w12 = m12.y * eK.y;
493
+ float w20 = m20.y * eK.z;
494
+ float w21 = m21.y * eK.z;
495
+ float w22 = m22.y * eK.z;
496
+
497
+ float hk = w00 + w01 + w02 + w10 + w11 + w12 + w20 + w21 + w22;
498
+
499
+ w00 = w00 / hk;
500
+ w01 = w01 / hk + w00;
501
+ w02 = w02 / hk + w01;
502
+ w10 = w10 / hk + w02;
503
+ w11 = w11 / hk + w10;
504
+ w12 = w12 / hk + w11;
505
+ w20 = w20 / hk + w12;
506
+ w21 = w21 / hk + w20;
507
+ w22 = w22 / hk + w21;
508
508
 
509
509
  float rand = eo(0u);
510
- float mV;
510
+ float nj;
511
511
  if (rand < w00) {
512
- mV = m00.x;
512
+ nj = m00.x;
513
513
  } else if (rand < w01) {
514
- mV = m01.x;
514
+ nj = m01.x;
515
515
  } else if (rand < w02) {
516
- mV = m02.x;
516
+ nj = m02.x;
517
517
  } else if (rand < w10) {
518
- mV = m10.x;
518
+ nj = m10.x;
519
519
  } else if (rand < w11) {
520
- mV = m11.x;
520
+ nj = m11.x;
521
521
  } else if (rand < w12) {
522
- mV = m12.x;
522
+ nj = m12.x;
523
523
  } else if (rand < w20) {
524
- mV = m20.x;
524
+ nj = m20.x;
525
525
  } else if (rand < w21) {
526
- mV = m21.x;
526
+ nj = m21.x;
527
527
  } else {
528
- mV = m22.x;
528
+ nj = m22.x;
529
529
  }
530
- return int(mV);
530
+ return int(nj);
531
531
  }
532
532
 
533
533
 
534
534
  vec4 bv(int i);
535
535
 
536
536
 
537
- mat2x3 eD(vec3 normal, vec3 dp1, vec3 dp2, vec2 nS, vec2 nT, vec4 aU) {
538
- float determinant = nS.x * nT.y - nS.y * nT.x;
539
- vec3 t = aU.xyz;
537
+ mat2x3 eE(vec3 normal, vec3 dp1, vec3 dp2, vec2 od, vec2 oe, vec4 aT) {
538
+ float determinant = od.x * oe.y - od.y * oe.x;
539
+ vec3 t = aT.xyz;
540
540
  vec3 b = vec3(0.0);
541
541
 
542
- float qu = abs(aU.w) > 1.5 ? 0.0 : aU.w;
542
+ float qC = abs(aT.w) > 1.5 ? 0.0 : aT.w;
543
543
  if (abs(determinant) > 1e-12) {
544
- vec3 dt = (dp1 * nT.y - dp2 * nS.y) / determinant;
545
- vec3 db = (dp2 * nS.x - dp1 * nT.x) / determinant;
544
+ vec3 dt = (dp1 * oe.y - dp2 * od.y) / determinant;
545
+ vec3 db = (dp2 * od.x - dp1 * oe.x) / determinant;
546
546
  if (dot(t, t) < 1e-8) { t = dt; }
547
- if (qu == 0.0) { qu = (dot(cross(normal, dt), db) < 0.0 ? -1.0 : 1.0); }
547
+ if (qC == 0.0) { qC = (dot(cross(normal, dt), db) < 0.0 ? -1.0 : 1.0); }
548
548
  }
549
549
  t -= normal * dot(normal, t);
550
550
  if (dot(t, t) < 1e-8) {
551
- float ie = (normal.z >= 0.0 ? 1.0 : -1.0);
552
- float dW = -1.0 / (ie + normal.z);
551
+ float ik = (normal.z >= 0.0 ? 1.0 : -1.0);
552
+ float dW = -1.0 / (ik + normal.z);
553
553
  float xy = normal.x * normal.y * dW;
554
- t = vec3(1.0 + ie * normal.x * normal.x * dW, ie * xy, -ie * normal.x);
555
- b = vec3(xy, ie + normal.y * normal.y * dW, -normal.y);
554
+ t = vec3(1.0 + ik * normal.x * normal.x * dW, ik * xy, -ik * normal.x);
555
+ b = vec3(xy, ik + normal.y * normal.y * dW, -normal.y);
556
556
  }
557
557
  else { t = normalize(t); b = normalize(cross(normal, t)); }
558
- return mat2x3(t, b * (qu < 0.0 ? -1.0 : 1.0));
558
+ return mat2x3(t, b * (qC < 0.0 ? -1.0 : 1.0));
559
559
  }
560
560
 
561
- void hp(inout ad si, fu tri, vec3 barycentric, ivec3 index) {
561
+ void ht(inout ad si, fA tri, vec3 barycentric, ivec3 index) {
562
562
  si.hit = true;
563
563
  si.position = barycentric.x * tri.p0 + barycentric.y * tri.p1 + barycentric.z * tri.p2;
564
- ivec2 i0 = gM(index.x, vertexColumns);
565
- ivec2 i1 = gM(index.y, vertexColumns);
566
- ivec2 i2 = gM(index.z, vertexColumns);
564
+ ivec2 i0 = gQ(index.x, vertexColumns);
565
+ ivec2 i1 = gQ(index.y, vertexColumns);
566
+ ivec2 i2 = gQ(index.z, vertexColumns);
567
+ si.vertexColor = vec3(1.0);
568
+ #ifdef USE_VERTEX_COLOR
569
+ si.vertexColor = barycentric.x * texelFetch(colorBuffer, i0, 0).rgb
570
+ + barycentric.y * texelFetch(colorBuffer, i1, 0).rgb
571
+ + barycentric.z * texelFetch(colorBuffer, i2, 0).rgb;
572
+ #endif
567
573
 
568
574
  vec3 n0 = texelFetch(normalBuffer, i0, 0).xyz;
569
575
  vec3 n1 = texelFetch(normalBuffer, i1, 0).xyz;
@@ -576,14 +582,14 @@ si.vertexNormal = normal;
576
582
 
577
583
 
578
584
  vec3 geometricNormal = normalize(cross(tri.p1 - tri.p0, tri.p2 - tri.p0));
579
- vec3 kf = barycentric.x * n0 + barycentric.y * n1 + barycentric.z * n2;
585
+ vec3 km = barycentric.x * n0 + barycentric.y * n1 + barycentric.z * n2;
580
586
  float a = dot(n2 - n0, tri.p0 - tri.p2);
581
587
  float b = dot(n2 - n1, tri.p1 - tri.p2);
582
588
  float c = dot(n1 - n0, tri.p1 - tri.p0);
583
589
  float h = a * barycentric.x * (barycentric.x - 1.0)
584
590
  + (a + b + c) * barycentric.x * barycentric.y
585
591
  + b * barycentric.y * (barycentric.y - 1.0);
586
- if (dot(kf, geometricNormal) > 0.0) {
592
+ if (dot(km, geometricNormal) > 0.0) {
587
593
  float h0 = max(max(dot(tri.p1 - tri.p0, n0), dot(tri.p2 - tri.p0, n0)), 0.0);
588
594
  float h1 = max(max(dot(tri.p0 - tri.p1, n1), dot(tri.p2 - tri.p1, n1)), 0.0);
589
595
  float h2 = max(max(dot(tri.p0 - tri.p2, n2), dot(tri.p1 - tri.p2, n2)), 0.0);
@@ -601,7 +607,7 @@ h1 = max(dot(si.position - tri.p1, n1) + h1, 0.0);
601
607
  h2 = max(dot(si.position - tri.p2, n2) + h2, 0.0);
602
608
  h = min(-min(min(h0, h1), h2), h * 0.5);
603
609
  }
604
- si.shadowOffset = kf * h;
610
+ si.shadowOffset = km * h;
605
611
 
606
612
 
607
613
  ivec4 m0 = ivec4(texelFetch(materialIndexBuffer, i0, 0));
@@ -609,7 +615,7 @@ ivec4 m1 = ivec4(texelFetch(materialIndexBuffer, i1, 0));
609
615
  ivec4 m2 = ivec4(texelFetch(materialIndexBuffer, i2, 0));
610
616
 
611
617
  if (m0.x > 0 || m1.x > 0 || m2.x > 0) {
612
- si.materialIndex = fj(m0, m1, m2, barycentric);
618
+ si.materialIndex = fm(m0, m1, m2, barycentric);
613
619
  }
614
620
 
615
621
  vec2 uv0 = texelFetch(uvBuffer, i0, 0).xy;
@@ -624,14 +630,14 @@ vec2 cX = barycentric.x * secondaryUv0
624
630
  + barycentric.y * secondaryUv1
625
631
  + barycentric.z * secondaryUv2;
626
632
 
627
- vec4 lC = fetchMatData(si.materialIndex * MAT_DATA_SIZE + MAT_ROW_UV);
628
- int uvProjection = int(lC.r);
633
+ vec4 lM = fetchMatData(si.materialIndex * MAT_DATA_SIZE + MAT_ROW_UV);
634
+ int uvProjection = int(lM.r);
629
635
  if (uvProjection > 0) {
630
- uv = gC(uvProjection, si.position, normal, lC.zw);
636
+ uv = gH(uvProjection, si.position, normal, lM.zw);
631
637
  cX = uv;
632
638
  } else {
633
- uv *= lC.zw;
634
- cX *= lC.zw;
639
+ uv *= lM.zw;
640
+ cX *= lM.zw;
635
641
  }
636
642
  #else
637
643
  vec2 uv = vec2(0.0);
@@ -640,51 +646,51 @@ vec2 cX = vec2(0.0);
640
646
 
641
647
  #ifdef NUM_COAT_NORMAL_MAPS
642
648
  si.coatNormal = normal;
643
- float lm = fetchMatData(si.materialIndex * MAT_DATA_SIZE + MAT_ROW_LAYER_MAPS).z;
649
+ float lw = fetchMatData(si.materialIndex * MAT_DATA_SIZE + MAT_ROW_LAYER_MAPS).z;
644
650
  #endif
645
651
  vec4 directionMaterial = fetchMatData(si.materialIndex * MAT_DATA_SIZE + MAT_ROW_DIRECTION_NORMAL);
646
- float te = fetchMatData(si.materialIndex * MAT_DATA_SIZE + MAT_ROW_FILM_TEXTURE).x;
647
- if (directionMaterial.x >= 0.0 || directionMaterial.y != 0.0 || te != 0.0
652
+ float tm = fetchMatData(si.materialIndex * MAT_DATA_SIZE + MAT_ROW_FILM_TEXTURE).x;
653
+ if (directionMaterial.x >= 0.0 || directionMaterial.y != 0.0 || tm != 0.0
648
654
  #ifdef NUM_COAT_NORMAL_MAPS
649
- || lm >= 0.0
655
+ || lw >= 0.0
650
656
  #endif
651
657
  ) {
652
658
  vec3 dp1 = tri.p0 - tri.p2;
653
659
  vec3 dp2 = tri.p1 - tri.p2;
654
- vec4 aU = vec4(0.0);
660
+ vec4 aT = vec4(0.0);
655
661
  #ifdef USE_TANGENT
656
- aU = barycentric.x * texelFetch(tangentBuffer, i0, 0)
662
+ aT = barycentric.x * texelFetch(tangentBuffer, i0, 0)
657
663
  + barycentric.y * texelFetch(tangentBuffer, i1, 0)
658
664
  + barycentric.z * texelFetch(tangentBuffer, i2, 0);
659
665
  #endif
660
- mat2x3 eP = eD(normal, dp1, dp2, uv0-uv2, uv1-uv2, aU);
661
- si.geometryTangent = eP[0];
662
- si.geometryBitangent = eP[1];
663
- mat2x3 fU = eP;
666
+ mat2x3 eS = eE(normal, dp1, dp2, uv0-uv2, uv1-uv2, aT);
667
+ si.geometryTangent = eS[0];
668
+ si.geometryBitangent = eS[1];
669
+ mat2x3 fY = eS;
664
670
  #ifdef NUM_ANISOTROPY_MAPS
665
671
  if (directionMaterial.x >= 0.0 && mapUvChannel[int(directionMaterial.x)] > 0.5) {
666
672
  vec2 a = texelFetch(uv1Buffer, i0, 0).xy;
667
673
  vec2 b = texelFetch(uv1Buffer, i1, 0).xy;
668
674
  vec2 c = texelFetch(uv1Buffer, i2, 0).xy;
669
- fU = eD(normal, dp1, dp2, a-c, b-c, (aU.w == 0.0 ? vec4(0.0) : aU));
675
+ fY = eE(normal, dp1, dp2, a-c, b-c, (aT.w == 0.0 ? vec4(0.0) : aT));
670
676
  }
671
677
  #endif
672
- si.directionTangent = fU[0];
673
- si.directionBitangent = fU[1];
678
+ si.directionTangent = fY[0];
679
+ si.directionBitangent = fY[1];
674
680
  #ifdef NUM_COAT_NORMAL_MAPS
675
- if (lm >= 0.0) {
676
- int ku = int(lm);
677
- mat2x3 lW = eP;
678
- if (mapUvChannel[ku] > 0.5) {
681
+ if (lw >= 0.0) {
682
+ int kC = int(lw);
683
+ mat2x3 mi = eS;
684
+ if (mapUvChannel[kC] > 0.5) {
679
685
  vec2 a = texelFetch(uv1Buffer, i0, 0).xy;
680
686
  vec2 b = texelFetch(uv1Buffer, i1, 0).xy;
681
687
  vec2 c = texelFetch(uv1Buffer, i2, 0).xy;
682
- lW = eD(normal, dp1, dp2, a-c, b-c,
683
- aU.w == 0.0 ? vec4(0.0) : aU);
688
+ mi = eE(normal, dp1, dp2, a-c, b-c,
689
+ aT.w == 0.0 ? vec4(0.0) : aT);
684
690
  }
685
- vec3 decoded = sampleMap(ku, getMapUvSet(ku, uv, cX)).rgb * 2.0 - 1.0;
686
- vec3 mapped = lW[0] * decoded.x * directionMaterial.z
687
- + lW[1] * decoded.y * directionMaterial.w + normal * decoded.z;
691
+ vec3 decoded = sampleMap(kC, getMapUvSet(kC, uv, cX)).rgb * 2.0 - 1.0;
692
+ vec3 mapped = mi[0] * decoded.x * directionMaterial.z
693
+ + mi[1] * decoded.y * directionMaterial.w + normal * decoded.z;
688
694
  if (dot(mapped, mapped) > 1e-12) { si.coatNormal = normalize(mapped); }
689
695
  }
690
696
  #endif
@@ -702,52 +708,52 @@ si.tangent = normalize(barycentric.x * t0 + barycentric.y * t1 + barycentric.z *
702
708
  #if defined(NUM_NORMAL_MAPS)
703
709
  vec3 dp1 = tri.p0 - tri.p2;
704
710
  vec3 dp2 = tri.p1 - tri.p2;
705
- vec2 nS = uv0 - uv2;
706
- vec2 nT = uv1 - uv2;
707
- si.normal = ob(
708
- si.materialIndex, uv, normal, dp1, dp2, nS, nT
711
+ vec2 od = uv0 - uv2;
712
+ vec2 oe = uv1 - uv2;
713
+ si.normal = om(
714
+ si.materialIndex, uv, normal, dp1, dp2, od, oe
709
715
  );
710
716
  #else
711
717
  si.normal = normal;
712
718
  #endif
713
719
  }
714
720
 
715
- struct eB {
721
+ struct eC {
716
722
  float t;
717
723
  vec3 barycentric;
718
724
  };
719
725
 
720
726
  vec4 dp(int i) {
721
- return ky(bvhBuffer, i, bvhColumns);
727
+ return kG(bvhBuffer, i, bvhColumns);
722
728
  }
723
729
 
724
730
  vec4 bv(int i) {
725
- return ky(instancesBuffer, i, instancesColumns);
731
+ return kG(instancesBuffer, i, instancesColumns);
726
732
  }
727
733
 
728
734
 
729
735
 
730
- uint qK(uint value) {
736
+ uint qT(uint value) {
731
737
  value -= (value >> 1u) & 0x55555555u;
732
738
  value = (value & 0x33333333u) + ((value >> 2u) & 0x33333333u);
733
739
  value = (value + (value >> 4u)) & 0x0f0f0f0fu;
734
740
  return (value * 0x01010101u) >> 24u;
735
741
  }
736
742
 
737
- vec4 eY(uint lL) {
743
+ vec4 fc(uint lV) {
738
744
  return vec4(
739
- float(lL & 0xffu),
740
- float((lL >> 8u) & 0xffu),
741
- float((lL >> 16u) & 0xffu),
742
- float(lL >> 24u)
745
+ float(lV & 0xffu),
746
+ float((lV >> 8u) & 0xffu),
747
+ float((lV >> 16u) & 0xffu),
748
+ float(lV >> 24u)
743
749
  ) / 255.0;
744
750
  }
745
751
 
746
752
 
747
753
 
748
754
 
749
- eB fI(vec3 o, vec3 d, fu tri, int ey, vec3 gL, float tMax) {
750
- eB ti;
755
+ eC fL(vec3 o, vec3 d, fA tri, int ey, vec3 gP, float tMax) {
756
+ eC ti;
751
757
 
752
758
 
753
759
  vec3 p0t = tri.p0 - o;
@@ -766,9 +772,9 @@ p2t = p2t.zxy;
766
772
  }
767
773
 
768
774
 
769
- p0t.xy += gL.xy * p0t.z;
770
- p1t.xy += gL.xy * p1t.z;
771
- p2t.xy += gL.xy * p2t.z;
775
+ p0t.xy += gP.xy * p0t.z;
776
+ p1t.xy += gP.xy * p1t.z;
777
+ p2t.xy += gP.xy * p2t.z;
772
778
 
773
779
 
774
780
  vec3 e = vec3(
@@ -778,9 +784,9 @@ p0t.x * p1t.y - p0t.y * p1t.x
778
784
  );
779
785
 
780
786
  #ifdef DEPTH_QUERY_MODE
781
- vec3 rt = abs(vec3(p1t.x * p2t.y, p2t.x * p0t.y, p0t.x * p1t.y))
787
+ vec3 rE = abs(vec3(p1t.x * p2t.y, p2t.x * p0t.y, p0t.x * p1t.y))
782
788
  + abs(vec3(p1t.y * p2t.x, p2t.y * p0t.x, p0t.y * p1t.x));
783
- e = mix(e, vec3(0.0), lessThanEqual(abs(e), rt * 1e-6));
789
+ e = mix(e, vec3(0.0), lessThanEqual(abs(e), rE * 1e-6));
784
790
  #endif
785
791
 
786
792
 
@@ -793,19 +799,19 @@ float det = e.x + e.y + e.z;
793
799
  if (det == 0.0) return ti;
794
800
  #endif
795
801
 
796
- p0t.z *= gL.z;
797
- p1t.z *= gL.z;
798
- p2t.z *= gL.z;
799
- float rd = (e.x * p0t.z + e.y * p1t.z + e.z * p2t.z);
802
+ p0t.z *= gP.z;
803
+ p1t.z *= gP.z;
804
+ p2t.z *= gP.z;
805
+ float rn = (e.x * p0t.z + e.y * p1t.z + e.z * p2t.z);
800
806
 
801
807
 
802
- if (abs(rd) > abs(tMax * det)) {
808
+ if (abs(rn) > abs(tMax * det)) {
803
809
  return ti;
804
810
  }
805
811
 
806
- float sm = 1. / det;
807
- ti.t = rd * sm;
808
- ti.barycentric = e * sm;
812
+ float sw = 1. / det;
813
+ ti.t = rn * sw;
814
+ ti.barycentric = e * sw;
809
815
 
810
816
  return ti;
811
817
  }
@@ -816,7 +822,7 @@ vec3 max;
816
822
  };
817
823
 
818
824
 
819
- vec3 eX(vec3 d) {
825
+ vec3 fb(vec3 d) {
820
826
  #ifdef DEPTH_QUERY_MODE
821
827
  vec3 ap = mix(d, mix(vec3(1e-20), vec3(-1e-20), lessThan(d, vec3(0.0))), lessThan(abs(d), vec3(1e-20)));
822
828
  return 1.0 / ap;
@@ -825,9 +831,9 @@ return 1.0 / d;
825
831
  #endif
826
832
  }
827
833
 
828
- vec3 eV(vec3 gx, vec3 o) {
834
+ vec3 eZ(vec3 gC, vec3 o) {
829
835
  #ifdef DEPTH_QUERY_MODE
830
- return abs(gx) * max(vec3(1.0), abs(o)) * 1e-6;
836
+ return abs(gC) * max(vec3(1.0), abs(o)) * 1e-6;
831
837
  #else
832
838
  return vec3(0.0);
833
839
  #endif
@@ -835,21 +841,21 @@ return vec3(0.0);
835
841
 
836
842
 
837
843
 
838
- float cM(vec3 o, vec3 d, vec3 vD, vec3 vC, float tMax) {
844
+ float cM(vec3 o, vec3 d, vec3 vK, vec3 vJ, float tMax) {
839
845
  #ifdef DEPTH_QUERY_MODE
840
- vec3 gx = eX(d);
841
- vec3 uK = (vD - o) * gx;
842
- vec3 uL = (vC - o) * gx;
843
- vec3 bJ = eV(gx, o);
846
+ vec3 gC = fb(d);
847
+ vec3 uR = (vK - o) * gC;
848
+ vec3 uS = (vJ - o) * gC;
849
+ vec3 bJ = eZ(gC, o);
844
850
  #else
845
- vec3 uK = (vD - o) / d;
846
- vec3 uL = (vC - o) / d;
851
+ vec3 uR = (vK - o) / d;
852
+ vec3 uS = (vJ - o) / d;
847
853
  vec3 bJ = vec3(0.0);
848
854
  #endif
849
- vec3 mB = min(uK, uL) - bJ;
850
- vec3 rM = max(uK, uL) + bJ;
851
- float t0 = max(mB.x, max(mB.y, mB.z));
852
- float t1 = min(rM.x, min(rM.y, rM.z));
855
+ vec3 mL = min(uR, uS) - bJ;
856
+ vec3 rU = max(uR, uS) + bJ;
857
+ float t0 = max(mL.x, max(mL.y, mL.z));
858
+ float t1 = min(rU.x, min(rU.y, rU.z));
853
859
 
854
860
  return (t0 > t1 || t0 > tMax) ? -1.0 : (t0 > 0.0 ? t0 : t1);
855
861
  }
@@ -858,7 +864,7 @@ int maxDimension(vec3 v) {
858
864
  return v.x > v.y ? (v.x > v.z ? 0 : 2) : (v.y > v.z ? 1 : 2);
859
865
  }
860
866
 
861
- vec3 mj(vec3 d, int ey) {
867
+ vec3 mv(vec3 d, int ey) {
862
868
 
863
869
 
864
870
  if (ey == 0) {
@@ -871,7 +877,7 @@ return vec3(-d.x, -d.y, 1.0) / d.z;
871
877
  }
872
878
 
873
879
 
874
- void cY(in Ray ray, inout ad si, bool doubleSided) {
880
+ void cZ(in Ray ray, inout ad si, bool doubleSided) {
875
881
  si.hit = false;
876
882
 
877
883
  if (isEmptyScene) {
@@ -879,24 +885,24 @@ return;
879
885
  }
880
886
 
881
887
  int ey = maxDimension(abs(ray.d));
882
- vec3 gL = mj(ray.d, ey);
888
+ vec3 gP = mv(ray.d, ey);
883
889
  int ao;
884
890
 
885
891
  ${getBVHTraverseCode(glsl `
886
892
  si.triangleIndex = triangleIndex;
887
- lp = tri;
888
- hx = faceNormal;
893
+ lC = tri;
894
+ hB = faceNormal;
889
895
  aB = hit.barycentric;
890
- hs = index;
891
- qT = true;
896
+ hw = index;
897
+ rb = true;
892
898
  ao = cf;
893
899
  `)}
894
900
 
895
- if (qT) {
901
+ if (rb) {
896
902
  si.instanceIndex = ao;
897
903
  si.materialIndex = int(ae(floatBitsToInt(bv(ao * ${INSTANCE_VEC4_STRIDE}).z)).x);
898
904
 
899
- hp(si, lp, aB, hs);
905
+ ht(si, lC, aB, hw);
900
906
  mat4 l2w = mat4(
901
907
  bv(ao * ${INSTANCE_VEC4_STRIDE} + 5),
902
908
  bv(ao * ${INSTANCE_VEC4_STRIDE} + 6),
@@ -910,7 +916,7 @@ bv(ao * ${INSTANCE_VEC4_STRIDE} + 3),
910
916
  bv(ao * ${INSTANCE_VEC4_STRIDE} + 4)
911
917
  );
912
918
  mat3 aD = transpose(mat3(w2l));
913
- si.faceNormal = normalize(aD * hx);
919
+ si.faceNormal = normalize(aD * hB);
914
920
  si.vertexNormal = normalize(aD * si.vertexNormal);
915
921
  si.normal = normalize(aD * si.normal);
916
922
  #ifdef NUM_COAT_NORMAL_MAPS
@@ -931,7 +937,7 @@ si.position = (l2w * vec4(si.position, 1.0)).xyz;
931
937
  }
932
938
 
933
939
 
934
- void iH(in Ray ray, inout ad si, int instanceIndex, float maxDistance) {
940
+ void iM(in Ray ray, inout ad si, int instanceIndex, float maxDistance) {
935
941
  si.hit = false;
936
942
 
937
943
  if (isEmptyScene) {
@@ -940,16 +946,16 @@ return;
940
946
 
941
947
  bool doubleSided = true;
942
948
  int ey = maxDimension(abs(ray.d));
943
- vec3 gL = mj(ray.d, ey);
949
+ vec3 gP = mv(ray.d, ey);
944
950
  int ao;
945
951
 
946
952
  ${getBVHTraverseCode(glsl `
947
953
  si.triangleIndex = triangleIndex;
948
- lp = tri;
949
- hx = faceNormal;
954
+ lC = tri;
955
+ hB = faceNormal;
950
956
  aB = hit.barycentric;
951
- hs = index;
952
- qT = true;
957
+ hw = index;
958
+ rb = true;
953
959
  ao = cf;
954
960
  `, glsl `
955
961
  if (cf != instanceIndex) {
@@ -957,10 +963,10 @@ continue;
957
963
  }
958
964
  `, 'maxDistance')}
959
965
 
960
- if (qT) {
966
+ if (rb) {
961
967
  si.instanceIndex = ao;
962
968
  si.materialIndex = int(ae(floatBitsToInt(bv(ao * ${INSTANCE_VEC4_STRIDE}).z)).x);
963
- hp(si, lp, aB, hs);
969
+ ht(si, lC, aB, hw);
964
970
  mat4 l2w = mat4(
965
971
  bv(ao * ${INSTANCE_VEC4_STRIDE} + 5),
966
972
  bv(ao * ${INSTANCE_VEC4_STRIDE} + 6),
@@ -974,7 +980,7 @@ bv(ao * ${INSTANCE_VEC4_STRIDE} + 3),
974
980
  bv(ao * ${INSTANCE_VEC4_STRIDE} + 4)
975
981
  );
976
982
  mat3 aD = transpose(mat3(w2l));
977
- si.faceNormal = normalize(aD * hx);
983
+ si.faceNormal = normalize(aD * hB);
978
984
  si.vertexNormal = normalize(aD * si.vertexNormal);
979
985
  si.normal = normalize(aD * si.normal);
980
986
  #ifdef NUM_COAT_NORMAL_MAPS
@@ -994,7 +1000,7 @@ si.position = (l2w * vec4(si.position, 1.0)).xyz;
994
1000
  }
995
1001
  }
996
1002
 
997
- bool ex(in Ray ray, float lightDistance, int jG) {
1003
+ bool ex(in Ray ray, float lightDistance, int jL) {
998
1004
 
999
1005
  if (isEmptyScene) {
1000
1006
  return false;
@@ -1002,27 +1008,27 @@ return false;
1002
1008
 
1003
1009
  bool doubleSided = true;
1004
1010
  int ey = maxDimension(abs(ray.d));
1005
- vec3 gL = mj(ray.d, ey);
1011
+ vec3 gP = mv(ray.d, ey);
1006
1012
 
1007
1013
  ${getBVHTraverseCode(glsl `
1008
1014
 
1009
1015
 
1010
- bool jn = true;
1016
+ bool jt = true;
1011
1017
  vec3 barycentric = hit.barycentric;
1012
1018
  vec3 position = barycentric.x * tri.p0 + barycentric.y * tri.p1 + barycentric.z * tri.p2;
1013
1019
 
1014
- if (jn) {
1020
+ if (jt) {
1015
1021
  #ifdef HAS_ALPHA
1016
1022
  int materialIndex = int(ae(floatBitsToInt(bv(cf * ${INSTANCE_VEC4_STRIDE}).z)).x);
1017
- ivec2 i0 = gM(index.x, vertexColumns);
1018
- ivec2 i1 = gM(index.y, vertexColumns);
1019
- ivec2 i2 = gM(index.z, vertexColumns);
1023
+ ivec2 i0 = gQ(index.x, vertexColumns);
1024
+ ivec2 i1 = gQ(index.y, vertexColumns);
1025
+ ivec2 i2 = gQ(index.z, vertexColumns);
1020
1026
  ivec4 m0 = ivec4(texelFetch(materialIndexBuffer, i0, 0));
1021
1027
  ivec4 m1 = ivec4(texelFetch(materialIndexBuffer, i1, 0));
1022
1028
  ivec4 m2 = ivec4(texelFetch(materialIndexBuffer, i2, 0));
1023
1029
 
1024
1030
  if (m0.x > 0 || m1.x > 0 || m2.x > 0) {
1025
- materialIndex = fj(m0, m1, m2, barycentric);
1031
+ materialIndex = fm(m0, m1, m2, barycentric);
1026
1032
  }
1027
1033
 
1028
1034
  int ii = materialIndex * MAT_DATA_SIZE;
@@ -1036,12 +1042,12 @@ vec2 uv0 = texelFetch(uvBuffer, i0, 0).xy;
1036
1042
  vec2 uv1 = texelFetch(uvBuffer, i1, 0).xy;
1037
1043
  vec2 uv2 = texelFetch(uvBuffer, i2, 0).xy;
1038
1044
  vec2 uv = barycentric.x * uv0 + barycentric.y * uv1 + barycentric.z * uv2;
1039
- vec4 lC = fetchMatData(ii + MAT_ROW_UV);
1040
- int uvProjection = int(lC.r);
1045
+ vec4 lM = fetchMatData(ii + MAT_ROW_UV);
1046
+ int uvProjection = int(lM.r);
1041
1047
  if (uvProjection > 0) {
1042
- uv = gC(uvProjection, position, hx, lC.zw);
1048
+ uv = gH(uvProjection, position, hB, lM.zw);
1043
1049
  } else {
1044
- uv *= lC.zw;
1050
+ uv *= lM.zw;
1045
1051
  }
1046
1052
 
1047
1053
  alpha *= sampleMap(diffuseMapIndex, uv).a;
@@ -1055,32 +1061,32 @@ vec2 uv0 = texelFetch(uvBuffer, i0, 0).xy;
1055
1061
  vec2 uv1 = texelFetch(uvBuffer, i1, 0).xy;
1056
1062
  vec2 uv2 = texelFetch(uvBuffer, i2, 0).xy;
1057
1063
  vec2 uv = barycentric.x * uv0 + barycentric.y * uv1 + barycentric.z * uv2;
1058
- vec4 lC = fetchMatData(ii + MAT_ROW_UV);
1059
- int uvProjection = int(lC.r);
1064
+ vec4 lM = fetchMatData(ii + MAT_ROW_UV);
1065
+ int uvProjection = int(lM.r);
1060
1066
  if (uvProjection > 0) {
1061
- uv = gC(uvProjection, position, hx, lC.zw);
1067
+ uv = gH(uvProjection, position, hB, lM.zw);
1062
1068
  } else {
1063
- uv *= lC.zw;
1069
+ uv *= lM.zw;
1064
1070
  }
1065
1071
  alpha *= sampleMap(alphaMapIndex, uv).g;
1066
1072
  }
1067
1073
  #endif
1068
1074
  float alphaCutoff = fetchMatData(ii + MAT_ROW_STANDALONE_MAPS).a;
1069
- alpha = lg(
1075
+ alpha = lr(
1070
1076
  alpha, int(fetchMatData(ii + MAT_ROW_ALPHA).w), alphaCutoff
1071
1077
  );
1072
1078
  if (eo(0u) > alpha) {
1073
1079
 
1074
1080
  tMax = min(max(lightDistance, 0.0), RAY_MAX_DISTANCE);
1075
- jn = false;
1081
+ jt = false;
1076
1082
  }
1077
1083
  #endif
1078
1084
  }
1079
- if (jn) {
1085
+ if (jt) {
1080
1086
  return true;
1081
1087
  }
1082
1088
  `, glsl `
1083
- if (triangleIndex == jG) {
1089
+ if (triangleIndex == jL) {
1084
1090
  continue;
1085
1091
  }
1086
1092
  `, 'min(max(lightDistance, 0.0), RAY_MAX_DISTANCE)')}