@galacean/engine 0.0.0-experimental-2.0-game.2 → 0.0.0-experimental-2.0-game.3

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/browser.js CHANGED
@@ -845,16 +845,20 @@
845
845
  * @param matrix - The transform to apply to the bounding box
846
846
  * @param out - The transformed bounding box
847
847
  */ BoundingBox.transform = function transform(source, matrix, out) {
848
- // Arvo's min/max method: for each matrix element, positive values multiply min for new min (max for new max),
849
- // negative values multiply max for new min (min for new max), then add translation.
850
- // Zero check avoids 0 * Infinity = NaN
851
- var _source_min = source.min, minX = _source_min.x, minY = _source_min.y, minZ = _source_min.z;
852
- var _source_max = source.max, maxX = _source_max.x, maxY = _source_max.y, maxZ = _source_max.z;
848
+ // https://zeux.io/2010/10/17/aabb-from-obb-with-component-wise-abs/
849
+ var center = BoundingBox._tempVec30;
850
+ var extent = BoundingBox._tempVec31;
851
+ source.getCenter(center);
852
+ source.getExtent(extent);
853
+ Vector3.transformCoordinate(center, matrix, center);
854
+ var x = extent.x, y = extent.y, z = extent.z;
853
855
  var e = matrix.elements;
854
856
  // prettier-ignore
855
857
  var e0 = e[0], e1 = e[1], e2 = e[2], e4 = e[4], e5 = e[5], e6 = e[6], e8 = e[8], e9 = e[9], e10 = e[10];
856
- out.min.set((e0 > 0 ? e0 * minX : e0 < 0 ? e0 * maxX : 0) + (e4 > 0 ? e4 * minY : e4 < 0 ? e4 * maxY : 0) + (e8 > 0 ? e8 * minZ : e8 < 0 ? e8 * maxZ : 0) + e[12], (e1 > 0 ? e1 * minX : e1 < 0 ? e1 * maxX : 0) + (e5 > 0 ? e5 * minY : e5 < 0 ? e5 * maxY : 0) + (e9 > 0 ? e9 * minZ : e9 < 0 ? e9 * maxZ : 0) + e[13], (e2 > 0 ? e2 * minX : e2 < 0 ? e2 * maxX : 0) + (e6 > 0 ? e6 * minY : e6 < 0 ? e6 * maxY : 0) + (e10 > 0 ? e10 * minZ : e10 < 0 ? e10 * maxZ : 0) + e[14]);
857
- out.max.set((e0 > 0 ? e0 * maxX : e0 < 0 ? e0 * minX : 0) + (e4 > 0 ? e4 * maxY : e4 < 0 ? e4 * minY : 0) + (e8 > 0 ? e8 * maxZ : e8 < 0 ? e8 * minZ : 0) + e[12], (e1 > 0 ? e1 * maxX : e1 < 0 ? e1 * minX : 0) + (e5 > 0 ? e5 * maxY : e5 < 0 ? e5 * minY : 0) + (e9 > 0 ? e9 * maxZ : e9 < 0 ? e9 * minZ : 0) + e[13], (e2 > 0 ? e2 * maxX : e2 < 0 ? e2 * minX : 0) + (e6 > 0 ? e6 * maxY : e6 < 0 ? e6 * minY : 0) + (e10 > 0 ? e10 * maxZ : e10 < 0 ? e10 * minZ : 0) + e[14]);
858
+ extent.set((e0 === 0 ? 0 : Math.abs(x * e0)) + (e4 === 0 ? 0 : Math.abs(y * e4)) + (e8 === 0 ? 0 : Math.abs(z * e8)), (e1 === 0 ? 0 : Math.abs(x * e1)) + (e5 === 0 ? 0 : Math.abs(y * e5)) + (e9 === 0 ? 0 : Math.abs(z * e9)), (e2 === 0 ? 0 : Math.abs(x * e2)) + (e6 === 0 ? 0 : Math.abs(y * e6)) + (e10 === 0 ? 0 : Math.abs(z * e10)));
859
+ // set min、max
860
+ Vector3.subtract(center, extent, out.min);
861
+ Vector3.add(center, extent, out.max);
858
862
  };
859
863
  /**
860
864
  * Calculate a bounding box that is as large as the total combined area of the two specified boxes.
@@ -869,6 +873,8 @@
869
873
  };
870
874
  return BoundingBox;
871
875
  }();
876
+ BoundingBox._tempVec30 = new Vector3();
877
+ BoundingBox._tempVec31 = new Vector3();
872
878
  /**
873
879
  * Contains static methods to help in determining intersections, containment, etc.
874
880
  */ var CollisionUtil = /*#__PURE__*/ function() {
@@ -6481,12 +6487,6 @@
6481
6487
  case TextureFormat.ETC2_RGB:
6482
6488
  case TextureFormat.ETC2_RGBA8:
6483
6489
  case TextureFormat.ASTC_4x4:
6484
- case TextureFormat.ASTC_5x5:
6485
- case TextureFormat.ASTC_6x6:
6486
- case TextureFormat.ASTC_8x8:
6487
- case TextureFormat.ASTC_10x10:
6488
- case TextureFormat.ASTC_12x12:
6489
- case TextureFormat.ETC2_RGBA5:
6490
6490
  return true;
6491
6491
  default:
6492
6492
  return false;
@@ -7020,7 +7020,7 @@
7020
7020
  _this = ReferResource.call(this, engine) || this, _this._charInfoMap = {}, _this._space = 1, _this._curX = 1, _this._curY = 1, _this._nextY = 1;
7021
7021
  _this.isGCIgnored = true;
7022
7022
  var format = engine._hardwareRenderer.isWebGL2 ? TextureFormat.R8 : TextureFormat.Alpha8;
7023
- var texture = new Texture2D(engine, 512, 512, format, false, false);
7023
+ var texture = new Texture2D(engine, 512, 512, format, false);
7024
7024
  texture.filterMode = TextureFilterMode.Bilinear;
7025
7025
  texture.isGCIgnored = true;
7026
7026
  _this.texture = texture;
@@ -9513,7 +9513,7 @@
9513
9513
  sprite.name === name && outSprites.push(sprite);
9514
9514
  }
9515
9515
  } else {
9516
- console.warn("The name of the sprite you want to find is not exit in SpriteAtlas.");
9516
+ console.warn("There is no sprite named " + name + " in the atlas.");
9517
9517
  }
9518
9518
  return outSprites;
9519
9519
  };
@@ -10437,13 +10437,27 @@
10437
10437
  var begin_mobile_frag = " vec4 ambient = vec4(0.0);\n vec4 emission = material_EmissiveColor;\n vec4 diffuse = material_BaseColor;\n vec4 specular = material_SpecularColor;\n\n \n\n #ifdef MATERIAL_HAS_EMISSIVETEXTURE\n emission *= texture2DSRGB(material_EmissiveTexture, v_uv);\n #endif\n\n #ifdef MATERIAL_HAS_BASETEXTURE\n diffuse *= texture2DSRGB(material_BaseTexture, v_uv);\n #endif\n\n #ifdef RENDERER_ENABLE_VERTEXCOLOR\n diffuse *= v_color;\n #endif\n\n #ifdef MATERIAL_HAS_SPECULAR_TEXTURE\n specular *= texture2DSRGB(material_SpecularTexture, v_uv);\n #endif\n\n ambient = vec4(scene_EnvMapLight.diffuse * scene_EnvMapLight.diffuseIntensity, 1.0) * diffuse;"; // eslint-disable-line
10438
10438
  var begin_viewdir_frag = "#ifdef CAMERA_ORTHOGRAPHIC\n vec3 V = -camera_Forward;\n#else\n #ifdef MATERIAL_NEED_WORLD_POS\n vec3 V = normalize( camera_Position - v_pos );\n #endif\n#endif"; // eslint-disable-line
10439
10439
  var mobile_blinnphong_frag = " #ifdef MATERIAL_HAS_NORMALTEXTURE\n mat3 tbn = getTBN(gl_FrontFacing);\n vec3 N = getNormalByNormalTexture(tbn, material_NormalTexture, material_NormalIntensity, v_uv, gl_FrontFacing);\n #else\n vec3 N = getNormal(gl_FrontFacing);\n #endif\n\n vec3 lightDiffuse = vec3( 0.0, 0.0, 0.0 );\n vec3 lightSpecular = vec3( 0.0, 0.0, 0.0 );\n float shadowAttenuation = 1.0;\n\n #ifdef SCENE_DIRECT_LIGHT_COUNT\n shadowAttenuation = 1.0;\n #ifdef SCENE_IS_CALCULATE_SHADOWS\n shadowAttenuation *= sampleShadowMap();\n #endif\n\n DirectLight directionalLight;\n for( int i = 0; i < SCENE_DIRECT_LIGHT_COUNT; i++ ) {\n if(!isRendererCulledByLight(renderer_Layer.xy, scene_DirectLightCullingMask[i])){\n directionalLight.color = scene_DirectLightColor[i];\n #ifdef SCENE_IS_CALCULATE_SHADOWS\n if (i == 0) { // Sun light index is always 0\n directionalLight.color *= shadowAttenuation;\n }\n #endif\n directionalLight.direction = scene_DirectLightDirection[i];\n \n float d = max(dot(N, -directionalLight.direction), 0.0);\n lightDiffuse += directionalLight.color * d;\n \n vec3 halfDir = normalize( V - directionalLight.direction );\n float s = pow( clamp( dot( N, halfDir ), 0.0, 1.0 ), material_Shininess );\n lightSpecular += directionalLight.color * s;\n }\n }\n\n #endif\n\n #ifdef SCENE_POINT_LIGHT_COUNT\n PointLight pointLight;\n for( int i = 0; i < SCENE_POINT_LIGHT_COUNT; i++ ) {\n if(!isRendererCulledByLight(renderer_Layer.xy, scene_PointLightCullingMask[i])){\n pointLight.color = scene_PointLightColor[i];\n pointLight.position = scene_PointLightPosition[i];\n pointLight.distance = scene_PointLightDistance[i];\n\n vec3 direction = v_pos - pointLight.position;\n float dist = length( direction );\n direction /= dist;\n float decay = clamp(1.0 - pow(dist / pointLight.distance, 4.0), 0.0, 1.0);\n\n float d = max( dot( N, -direction ), 0.0 ) * decay;\n lightDiffuse += pointLight.color * d;\n\n vec3 halfDir = normalize( V - direction );\n float s = pow( clamp( dot( N, halfDir ), 0.0, 1.0 ), material_Shininess ) * decay;\n lightSpecular += pointLight.color * s;\n }\n }\n\n #endif\n\n #ifdef SCENE_SPOT_LIGHT_COUNT\n SpotLight spotLight;\n for( int i = 0; i < SCENE_SPOT_LIGHT_COUNT; i++) {\n if(!isRendererCulledByLight(renderer_Layer.xy, scene_SpotLightCullingMask[i])){\n spotLight.color = scene_SpotLightColor[i];\n spotLight.position = scene_SpotLightPosition[i];\n spotLight.direction = scene_SpotLightDirection[i];\n spotLight.distance = scene_SpotLightDistance[i];\n spotLight.angleCos = scene_SpotLightAngleCos[i];\n spotLight.penumbraCos = scene_SpotLightPenumbraCos[i];\n\n vec3 direction = spotLight.position - v_pos;\n float lightDistance = length( direction );\n direction /= lightDistance;\n float angleCos = dot( direction, -spotLight.direction );\n float decay = clamp(1.0 - pow(lightDistance/spotLight.distance, 4.0), 0.0, 1.0);\n float spotEffect = smoothstep( spotLight.penumbraCos, spotLight.angleCos, angleCos );\n float decayTotal = decay * spotEffect;\n float d = max( dot( N, direction ), 0.0 ) * decayTotal;\n lightDiffuse += spotLight.color * d;\n\n vec3 halfDir = normalize( V + direction );\n float s = pow( clamp( dot( N, halfDir ), 0.0, 1.0 ), material_Shininess ) * decayTotal;\n lightSpecular += spotLight.color * s;\n }\n }\n\n #endif\n\n diffuse *= vec4( lightDiffuse, 1.0 );\n specular *= vec4( lightSpecular, 1.0 );\n\n #ifdef MATERIAL_IS_ALPHA_CUTOFF\n if( diffuse.a < material_AlphaCutoff ) {\n discard;\n }\n #endif\n"; // eslint-disable-line
10440
- var noise_common = "// Common helper functions for simplex noise.\n// Algorithm: Ken Perlin, \"Noise hardware\" (2001) — simplex lattice improvement over classic Perlin noise (1985).\n// GLSL implementation: Ian McEwan, Ashima Arts (MIT License) — https://github.com/ashima/webgl-noise\n\n// Modulo 289 without a division (only multiplications)\nvec4 mod289( vec4 x ) {\n\n return x - floor( x * ( 1.0 / 289.0 ) ) * 289.0;\n\n}\n\nvec3 mod289( vec3 x ) {\n\n return x - floor( x * ( 1.0 / 289.0 ) ) * 289.0;\n\n}\n\nvec2 mod289( vec2 x ) {\n\n return x - floor( x * ( 1.0 / 289.0 ) ) * 289.0;\n\n}\n\nfloat mod289( float x ) {\n\n return x - floor( x * ( 1.0 / 289.0 ) ) * 289.0;\n\n}\n\n// Modulo 7 without a division\nvec4 mod7( vec4 x ) {\n\n return x - floor( x * ( 1.0 / 7.0 ) ) * 7.0;\n\n}\n\nvec3 mod7( vec3 x ) {\n\n return x - floor( x * ( 1.0 / 7.0 ) ) * 7.0;\n\n}\n\n// Permutation polynomial: (34x^2 + x) mod 289\nvec4 permute( vec4 x ) {\n\n return mod289( ( 34.0 * x + 1.0 ) * x);\n\n}\n\nvec3 permute( vec3 x ) {\n\n return mod289( ( 34.0 * x + 1.0 ) * x );\n\n}\n\nfloat permute( float x ) {\n\n return mod289( ( ( x * 34.0 ) + 1.0 ) * x );\n\n}\n\nvec4 taylorInvSqrt( vec4 r ) {\n\n return 1.79284291400159 - 0.85373472095314 * r;\n\n}\n\nfloat taylorInvSqrt( float r ) {\n\n return 1.79284291400159 - 0.85373472095314 * r;\n\n}\n\nvec4 fade( vec4 t ) {\n\n return t * t * t * ( t * ( t * 6.0 - 15.0 ) + 10.0 );\n\n}\n\nvec3 fade( vec3 t ) {\n\n return t * t * t * ( t * ( t * 6.0 - 15.0 ) + 10.0 );\n\n}\n\nvec2 fade( vec2 t ) {\n\n return t * t * t * ( t * ( t * 6.0 - 15.0 ) + 10.0 );\n\n}\n\n#define K 0.142857142857 // 1/7\n#define Ko 0.428571428571 // 1/2-K/2\n#define K2 0.020408163265306 // 1/(7*7)\n#define Kd2 0.0714285714285 // K/2\n#define Kz 0.166666666667 // 1/6\n#define Kzo 0.416666666667 // 1/2-1/6*2\n#define jitter 1.0 // smaller jitter gives more regular pattern\n#define jitter1 0.8 // smaller jitter gives less errors in F1 F2\n"; // eslint-disable-line
10441
- var noise_simplex_3D_grad = "// 3D simplex noise analytical gradient.\n// Algorithm: Ken Perlin, \"Noise hardware\" (2001) simplex lattice improvement over classic Perlin noise (1985).\n// Curl noise: Robert Bridson et al., \"Curl-noise for procedural fluid flow\" (2007).\n// GLSL implementation: Ian McEwan, Ashima Arts (MIT License) — https://github.com/ashima/webgl-noise\n\nvec3 simplexGrad( vec3 v ) {\n\n const vec2 C = vec2( 1.0 / 6.0, 1.0 / 3.0 );\n const vec4 D = vec4( 0.0, 0.5, 1.0, 2.0 );\n\n // First corner\n vec3 i = floor( v + dot( v, C.yyy ) );\n vec3 x0 = v - i + dot( i, C.xxx ) ;\n\n // Other corners\n vec3 g = step( x0.yzx, x0.xyz );\n vec3 l = 1.0 - g;\n vec3 i1 = min( g.xyz, l.zxy );\n vec3 i2 = max( g.xyz, l.zxy );\n\n vec3 x1 = x0 - i1 + C.xxx;\n vec3 x2 = x0 - i2 + C.yyy; // 2.0*C.x = 1/3 = C.y\n vec3 x3 = x0 - D.yyy; // -1.0+3.0*C.x = -0.5 = -D.y\n\n // Permutations\n i = mod289( i );\n vec4 p = permute( permute( permute(\n i.z + vec4( 0.0, i1.z, i2.z, 1.0 ) )\n + i.y + vec4( 0.0, i1.y, i2.y, 1.0 ) )\n + i.x + vec4( 0.0, i1.x, i2.x, 1.0 ) );\n\n // Gradients: 7x7 points over a square, mapped onto an octahedron.\n // The ring size 17*17 = 289 is close to a multiple of 49 (49*6 = 294)\n float n_ = 0.142857142857; // 1.0/7.0\n vec3 ns = n_ * D.wyz - D.xzx;\n\n vec4 j = p - 49.0 * floor(p * ns.z * ns.z); // mod(p,7*7)\n\n vec4 x_ = floor(j * ns.z);\n vec4 y_ = floor(j - 7.0 * x_ ); // mod(j,N)\n\n vec4 x = x_ * ns.x + ns.yyyy;\n vec4 y = y_ * ns.x + ns.yyyy;\n vec4 h = 1.0 - abs( x ) - abs( y );\n\n vec4 b0 = vec4( x.xy, y.xy );\n vec4 b1 = vec4( x.zw, y.zw );\n\n vec4 s0 = floor( b0 ) * 2.0 + 1.0;\n vec4 s1 = floor( b1 ) * 2.0 + 1.0;\n vec4 sh = - step( h, vec4( 0.0 ) );\n\n vec4 a0 = b0.xzyw + s0.xzyw * sh.xxyy ;\n vec4 a1 = b1.xzyw + s1.xzyw * sh.zzww ;\n\n vec3 p0 = vec3( a0.xy, h.x );\n vec3 p1 = vec3( a0.zw, h.y );\n vec3 p2 = vec3( a1.xy, h.z );\n vec3 p3 = vec3( a1.zw, h.w );\n\n //Normalise gradients\n vec4 norm = taylorInvSqrt( vec4( dot( p0, p0 ), dot( p1, p1 ), dot( p2, p2 ), dot( p3, p3 ) ) );\n p0 *= norm.x;\n p1 *= norm.y;\n p2 *= norm.z;\n p3 *= norm.w;\n\n // Mix final noise value\n vec4 m = max( 0.6 - vec4( dot( x0, x0 ), dot( x1, x1 ), dot( x2, x2 ), dot( x3, x3 ) ), 0.0 );\n vec4 m2 = m * m;\n vec4 m4 = m2 * m2;\n vec4 pdotx = vec4( dot( p0, x0 ), dot( p1, x1 ), dot( p2, x2 ), dot( p3, x3 ) );\n\n // Compute and return noise gradient\n vec4 temp = m2 * m * pdotx;\n vec3 grad = - 8.0 * ( temp.x * x0 + temp.y * x1 + temp.z * x2 + temp.w * x3 );\n grad += m4.x * p0 + m4.y * p1 + m4.z * p2 + m4.w * p3;\n return grad * 42.0;\n\n}\n"; // eslint-disable-line
10440
+ var noise_cellular = "#include <noise_cellular_2D>\n#include <noise_cellular_3D>\n#include <noise_cellular_2x2>\n#include <noise_cellular_2x2x2>\n"; // eslint-disable-line
10441
+ var noise_cellular_2D = "\n// Cellular noise (\"Worley noise\") in 2D in GLSL.\n// Copyright (c) Stefan Gustavson 2011-04-19. All rights reserved.\n// This code is released under the conditions of the MIT license.\n// See LICENSE file for details.\n// https://github.com/stegu/webgl-noise\n\n// Cellular noise, returning F1 and F2 in a vec2.\n// Standard 3x3 search window for good F1 and F2 values\nvec2 cellular( vec2 P ) {\n\n\tvec2 Pi = mod289( floor( P ) );\n \tvec2 Pf = fract( P );\n\tvec3 oi = vec3( -1.0, 0.0, 1.0);\n\tvec3 of = vec3( -0.5, 0.5, 1.5);\n\tvec3 px = permute( Pi.x + oi );\n\tvec3 p = permute( px.x + Pi.y + oi ); // p11, p12, p13\n\tvec3 ox = fract( p * K ) - Ko;\n\tvec3 oy = mod7( floor( p * K ) ) * K - Ko;\n\tvec3 dx = Pf.x + 0.5 + jitter * ox;\n\tvec3 dy = Pf.y - of + jitter * oy;\n\tvec3 d1 = dx * dx + dy * dy; // d11, d12 and d13, squared\n\tp = permute( px.y + Pi.y + oi ); // p21, p22, p23\n\tox = fract( p * K ) - Ko;\n\toy = mod7( floor( p * K ) ) * K - Ko;\n\tdx = Pf.x - 0.5 + jitter * ox;\n\tdy = Pf.y - of + jitter * oy;\n\tvec3 d2 = dx * dx + dy * dy; // d21, d22 and d23, squared\n\tp = permute( px.z + Pi.y + oi ); // p31, p32, p33\n\tox = fract( p * K ) - Ko;\n\toy = mod7( floor( p * K ) ) * K - Ko;\n\tdx = Pf.x - 1.5 + jitter * ox;\n\tdy = Pf.y - of + jitter * oy;\n\tvec3 d3 = dx * dx + dy * dy; // d31, d32 and d33, squared\n\t// Sort out the two smallest distances (F1, F2)\n\tvec3 d1a = min( d1, d2 );\n\td2 = max( d1, d2 ); // Swap to keep candidates for F2\n\td2 = min( d2, d3 ); // neither F1 nor F2 are now in d3\n\td1 = min( d1a, d2 ); // F1 is now in d1\n\td2 = max( d1a, d2 ); // Swap to keep candidates for F2\n\td1.xy = ( d1.x < d1.y ) ? d1.xy : d1.yx; // Swap if smaller\n\td1.xz = ( d1.x < d1.z ) ? d1.xz : d1.zx; // F1 is in d1.x\n\td1.yz = min( d1.yz, d2.yz ); // F2 is now not in d2.yz\n\td1.y = min( d1.y, d1.z ); // nor in d1.z\n\td1.y = min( d1.y, d2.x ); // F2 is in d1.y, we're done.\n\treturn sqrt( d1.xy );\n\n}\n"; // eslint-disable-line
10442
+ var noise_cellular_2x2 = "\n// Cellular noise (\"Worley noise\") in 2D in GLSL.\n// Copyright (c) Stefan Gustavson 2011-04-19. All rights reserved.\n// This code is released under the conditions of the MIT license.\n// See LICENSE file for details.\n// https://github.com/stegu/webgl-noise\n\n// Cellular noise, returning F1 and F2 in a vec2.\n// Speeded up by using 2x2 search window instead of 3x3,\n// at the expense of some strong pattern artifacts.\n// F2 is often wrong and has sharp discontinuities.\n// If you need a smooth F2, use the slower 3x3 version.\n// F1 is sometimes wrong, too, but OK for most purposes.\nvec2 cellular2x2( vec2 P ) {\n\n\tvec2 Pi = mod289( floor( P ) );\n \tvec2 Pf = fract( P );\n\tvec4 Pfx = Pf.x + vec4( -0.5, -1.5, -0.5, -1.5 );\n\tvec4 Pfy = Pf.y + vec4( -0.5, -0.5, -1.5, -1.5 );\n\tvec4 p = permute( Pi.x + vec4( 0.0, 1.0, 0.0, 1.0 ) );\n\tp = permute( p + Pi.y + vec4( 0.0, 0.0, 1.0, 1.0 ) );\n\tvec4 ox = mod7( p ) * K + Kd2;\n\tvec4 oy = mod7( floor( p * K ) ) * K + Kd2;\n\tvec4 dx = Pfx + jitter1 * ox;\n\tvec4 dy = Pfy + jitter1 * oy;\n\tvec4 d = dx * dx + dy * dy; // d11, d12, d21 and d22, squared\n\n\t// Do it right and find both F1 and F2\n\td.xy = ( d.x < d.y ) ? d.xy : d.yx; // Swap if smaller\n\td.xz = ( d.x < d.z ) ? d.xz : d.zx;\n\td.xw = ( d.x < d.w ) ? d.xw : d.wx;\n\td.y = min( d.y, d.z );\n\td.y = min( d.y, d.w );\n\treturn sqrt( d.xy );\n\n}\n"; // eslint-disable-line
10443
+ var noise_cellular_2x2x2 = "\n// Cellular noise (\"Worley noise\") in 3D in GLSL.\n// Copyright (c) Stefan Gustavson 2011-04-19. All rights reserved.\n// This code is released under the conditions of the MIT license.\n// See LICENSE file for details.\n// https://github.com/stegu/webgl-noise\n\n// Cellular noise, returning F1 and F2 in a vec2.\n// Speeded up by using 2x2x2 search window instead of 3x3x3,\n// at the expense of some pattern artifacts.\n// F2 is often wrong and has sharp discontinuities.\n// If you need a good F2, use the slower 3x3x3 version.\nvec2 cellular2x2x2(vec3 P) {\n\n\tvec3 Pi = mod289( floor( P ) );\n \tvec3 Pf = fract( P );\n\tvec4 Pfx = Pf.x + vec4( 0.0, -1.0, 0.0, -1.0 );\n\tvec4 Pfy = Pf.y + vec4( 0.0, 0.0, -1.0, -1.0 );\n\tvec4 p = permute( Pi.x + vec4( 0.0, 1.0, 0.0, 1.0 ) );\n\tp = permute( p + Pi.y + vec4( 0.0, 0.0, 1.0, 1.0 ) );\n\tvec4 p1 = permute( p + Pi.z ); // z+0\n\tvec4 p2 = permute( p + Pi.z + vec4( 1.0 ) ); // z+1\n\tvec4 ox1 = fract( p1 * K ) - Ko;\n\tvec4 oy1 = mod7( floor( p1 * K ) ) * K - Ko;\n\tvec4 oz1 = floor( p1 * K2 ) * Kz - Kzo; // p1 < 289 guaranteed\n\tvec4 ox2 = fract( p2 * K ) - Ko;\n\tvec4 oy2 = mod7( floor( p2 * K ) ) * K - Ko;\n\tvec4 oz2 = floor( p2 * K2 ) * Kz - Kzo;\n\tvec4 dx1 = Pfx + jitter1 * ox1;\n\tvec4 dy1 = Pfy + jitter1 * oy1;\n\tvec4 dz1 = Pf.z + jitter1 * oz1;\n\tvec4 dx2 = Pfx + jitter1 * ox2;\n\tvec4 dy2 = Pfy + jitter1 * oy2;\n\tvec4 dz2 = Pf.z - 1.0 + jitter1 * oz2;\n\tvec4 d1 = dx1 * dx1 + dy1 * dy1 + dz1 * dz1; // z+0\n\tvec4 d2 = dx2 * dx2 + dy2 * dy2 + dz2 * dz2; // z+1\n\n\t// Do it right and sort out both F1 and F2\n\tvec4 d = min( d1, d2 ); // F1 is now in d\n\td2 = max( d1, d2 ); // Make sure we keep all candidates for F2\n\td.xy = ( d.x < d.y ) ? d.xy : d.yx; // Swap smallest to d.x\n\td.xz = ( d.x < d.z ) ? d.xz : d.zx;\n\td.xw = ( d.x < d.w ) ? d.xw : d.wx; // F1 is now in d.x\n\td.yzw = min( d.yzw, d2.yzw ); // F2 now not in d2.yzw\n\td.y = min( d.y, d.z ); // nor in d.z\n\td.y = min( d.y, d.w ); // nor in d.w\n\td.y = min( d.y, d2.x ); // F2 is now in d.y\n\treturn sqrt( d.xy ); // F1 and F2\n\n}\n"; // eslint-disable-line
10444
+ var noise_cellular_3D = "\n// Cellular noise (\"Worley noise\") in 3D in GLSL.\n// Copyright (c) Stefan Gustavson 2011-04-19. All rights reserved.\n// This code is released under the conditions of the MIT license.\n// See LICENSE file for details.\n// https://github.com/stegu/webgl-noise\n\n// Cellular noise, returning F1 and F2 in a vec2.\n// 3x3x3 search region for good F2 everywhere, but a lot\n// slower than the 2x2x2 version.\n// The code below is a bit scary even to its author,\n// but it has at least half decent performance on a\n// modern GPU. In any case, it beats any software\n// implementation of Worley noise hands down.\n\nvec2 cellular( vec3 P ) {\n\n\tvec3 Pi = mod289( floor( P ) );\n \tvec3 Pf = fract( P ) - 0.5;\n\n\tvec3 Pfx = Pf.x + vec3( 1.0, 0.0, -1.0 );\n\tvec3 Pfy = Pf.y + vec3( 1.0, 0.0, -1.0 );\n\tvec3 Pfz = Pf.z + vec3( 1.0, 0.0, -1.0 );\n\n\tvec3 p = permute( Pi.x + vec3( -1.0, 0.0, 1.0 ) );\n\tvec3 p1 = permute( p + Pi.y - 1.0 );\n\tvec3 p2 = permute( p + Pi.y );\n\tvec3 p3 = permute( p + Pi.y + 1.0 );\n\n\tvec3 p11 = permute( p1 + Pi.z - 1.0 );\n\tvec3 p12 = permute( p1 + Pi.z );\n\tvec3 p13 = permute( p1 + Pi.z + 1.0 );\n\n\tvec3 p21 = permute( p2 + Pi.z - 1.0 );\n\tvec3 p22 = permute( p2 + Pi.z );\n\tvec3 p23 = permute( p2 + Pi.z + 1.0 );\n\n\tvec3 p31 = permute( p3 + Pi.z - 1.0 );\n\tvec3 p32 = permute( p3 + Pi.z );\n\tvec3 p33 = permute( p3 + Pi.z + 1.0 );\n\n\tvec3 ox11 = fract( p11 * K ) - Ko;\n\tvec3 oy11 = mod7( floor( p11 * K ) ) * K - Ko;\n\tvec3 oz11 = floor( p11 * K2 ) * Kz - Kzo; // p11 < 289 guaranteed\n\n\tvec3 ox12 = fract( p12 * K ) - Ko;\n\tvec3 oy12 = mod7( floor( p12 * K ) ) * K - Ko;\n\tvec3 oz12 = floor( p12 * K2 ) * Kz - Kzo;\n\n\tvec3 ox13 = fract( p13 * K ) - Ko;\n\tvec3 oy13 = mod7( floor( p13 * K ) ) * K - Ko;\n\tvec3 oz13 = floor( p13 * K2 ) * Kz - Kzo;\n\n\tvec3 ox21 = fract( p21 * K ) - Ko;\n\tvec3 oy21 = mod7( floor( p21 * K ) ) * K - Ko;\n\tvec3 oz21 = floor( p21 * K2 ) * Kz - Kzo;\n\n\tvec3 ox22 = fract( p22 * K ) - Ko;\n\tvec3 oy22 = mod7( floor( p22 * K ) ) * K - Ko;\n\tvec3 oz22 = floor( p22 * K2 ) * Kz - Kzo;\n\n\tvec3 ox23 = fract( p23 * K ) - Ko;\n\tvec3 oy23 = mod7( floor( p23 * K ) ) * K - Ko;\n\tvec3 oz23 = floor( p23 * K2 ) * Kz - Kzo;\n\n\tvec3 ox31 = fract( p31 * K ) - Ko;\n\tvec3 oy31 = mod7( floor( p31 * K ) ) * K - Ko;\n\tvec3 oz31 = floor( p31 * K2 ) * Kz - Kzo;\n\n\tvec3 ox32 = fract( p32 * K ) - Ko;\n\tvec3 oy32 = mod7( floor( p32 * K ) ) * K - Ko;\n\tvec3 oz32 = floor( p32 * K2 ) * Kz - Kzo;\n\n\tvec3 ox33 = fract( p33 * K ) - Ko;\n\tvec3 oy33 = mod7( floor( p33 * K ) ) * K - Ko;\n\tvec3 oz33 = floor( p33 * K2 ) * Kz - Kzo;\n\n\tvec3 dx11 = Pfx + jitter * ox11;\n\tvec3 dy11 = Pfy.x + jitter * oy11;\n\tvec3 dz11 = Pfz.x + jitter * oz11;\n\n\tvec3 dx12 = Pfx + jitter * ox12;\n\tvec3 dy12 = Pfy.x + jitter * oy12;\n\tvec3 dz12 = Pfz.y + jitter * oz12;\n\n\tvec3 dx13 = Pfx + jitter * ox13;\n\tvec3 dy13 = Pfy.x + jitter * oy13;\n\tvec3 dz13 = Pfz.z + jitter * oz13;\n\n\tvec3 dx21 = Pfx + jitter * ox21;\n\tvec3 dy21 = Pfy.y + jitter * oy21;\n\tvec3 dz21 = Pfz.x + jitter * oz21;\n\n\tvec3 dx22 = Pfx + jitter * ox22;\n\tvec3 dy22 = Pfy.y + jitter * oy22;\n\tvec3 dz22 = Pfz.y + jitter * oz22;\n\n\tvec3 dx23 = Pfx + jitter * ox23;\n\tvec3 dy23 = Pfy.y + jitter * oy23;\n\tvec3 dz23 = Pfz.z + jitter * oz23;\n\n\tvec3 dx31 = Pfx + jitter * ox31;\n\tvec3 dy31 = Pfy.z + jitter * oy31;\n\tvec3 dz31 = Pfz.x + jitter * oz31;\n\n\tvec3 dx32 = Pfx + jitter * ox32;\n\tvec3 dy32 = Pfy.z + jitter * oy32;\n\tvec3 dz32 = Pfz.y + jitter * oz32;\n\n\tvec3 dx33 = Pfx + jitter * ox33;\n\tvec3 dy33 = Pfy.z + jitter * oy33;\n\tvec3 dz33 = Pfz.z + jitter * oz33;\n\n\tvec3 d11 = dx11 * dx11 + dy11 * dy11 + dz11 * dz11;\n\tvec3 d12 = dx12 * dx12 + dy12 * dy12 + dz12 * dz12;\n\tvec3 d13 = dx13 * dx13 + dy13 * dy13 + dz13 * dz13;\n\tvec3 d21 = dx21 * dx21 + dy21 * dy21 + dz21 * dz21;\n\tvec3 d22 = dx22 * dx22 + dy22 * dy22 + dz22 * dz22;\n\tvec3 d23 = dx23 * dx23 + dy23 * dy23 + dz23 * dz23;\n\tvec3 d31 = dx31 * dx31 + dy31 * dy31 + dz31 * dz31;\n\tvec3 d32 = dx32 * dx32 + dy32 * dy32 + dz32 * dz32;\n\tvec3 d33 = dx33 * dx33 + dy33 * dy33 + dz33 * dz33;\n\n\t// Do it right and sort out both F1 and F2\n\tvec3 d1a = min( d11, d12 );\n\td12 = max( d11, d12 );\n\td11 = min( d1a, d13 ); // Smallest now not in d12 or d13\n\td13 = max( d1a, d13 );\n\td12 = min( d12, d13 ); // 2nd smallest now not in d13\n\tvec3 d2a = min( d21, d22 );\n\td22 = max( d21, d22 );\n\td21 = min( d2a, d23 ); // Smallest now not in d22 or d23\n\td23 = max( d2a, d23 );\n\td22 = min( d22, d23 ); // 2nd smallest now not in d23\n\tvec3 d3a = min( d31, d32 );\n\td32 = max( d31, d32 );\n\td31 = min( d3a, d33 ); // Smallest now not in d32 or d33\n\td33 = max( d3a, d33 );\n\td32 = min( d32, d33 ); // 2nd smallest now not in d33\n\tvec3 da = min( d11, d21 );\n\td21 = max( d11, d21 );\n\td11 = min( da, d31 ); // Smallest now in d11\n\td31 = max( da, d31 ); // 2nd smallest now not in d31\n\td11.xy = ( d11.x < d11.y ) ? d11.xy : d11.yx;\n\td11.xz = ( d11.x < d11.z ) ? d11.xz : d11.zx; // d11.x now smallest\n\td12 = min( d12, d21 ); // 2nd smallest now not in d21\n\td12 = min( d12, d22 ); // nor in d22\n\td12 = min( d12, d31 ); // nor in d31\n\td12 = min( d12, d32 ); // nor in d32\n\td11.yz = min( d11.yz, d12.xy ); // nor in d12.yz\n\td11.y = min( d11.y, d12.z ); // Only two more to go\n\td11.y = min( d11.y, d11.z ); // Done! (Phew! )\n\treturn sqrt( d11.xy ); // F1, F2\n\n}\n"; // eslint-disable-line
10445
+ var noise_common = "// Modulo 289 without a division (only multiplications)\nvec4 mod289( vec4 x ) {\n\n return x - floor( x * ( 1.0 / 289.0 ) ) * 289.0;\n\n}\n\nvec3 mod289( vec3 x ) {\n\n return x - floor( x * ( 1.0 / 289.0 ) ) * 289.0;\n\n}\n\nvec2 mod289( vec2 x ) {\n\n return x - floor( x * ( 1.0 / 289.0 ) ) * 289.0;\n\n}\n\nfloat mod289( float x ) {\n\n return x - floor( x * ( 1.0 / 289.0 ) ) * 289.0;\n\n}\n\n// Modulo 7 without a division\nvec4 mod7( vec4 x ) {\n\n return x - floor( x * ( 1.0 / 7.0 ) ) * 7.0;\n\n}\n\nvec3 mod7( vec3 x ) {\n\n return x - floor( x * ( 1.0 / 7.0 ) ) * 7.0;\n\n}\n\n// Permutation polynomial: (34x^2 + x) mod 289\nvec4 permute( vec4 x ) {\n\n return mod289( ( 34.0 * x + 1.0 ) * x);\n\n}\n\nvec3 permute( vec3 x ) {\n\n return mod289( ( 34.0 * x + 1.0 ) * x );\n\n}\n\nfloat permute( float x ) {\n\n return mod289( ( ( x * 34.0 ) + 1.0 ) * x );\n\n}\n\nvec4 taylorInvSqrt( vec4 r ) {\n\n return 1.79284291400159 - 0.85373472095314 * r;\n\n}\n\nfloat taylorInvSqrt( float r ) {\n\n return 1.79284291400159 - 0.85373472095314 * r;\n\n}\n\nvec4 fade( vec4 t ) {\n\n return t * t * t * ( t * ( t * 6.0 - 15.0 ) + 10.0 );\n\n}\n\nvec3 fade( vec3 t ) {\n\n return t * t * t * ( t * ( t * 6.0 - 15.0 ) + 10.0 );\n\n}\n\nvec2 fade( vec2 t ) {\n\n return t * t * t * ( t * ( t * 6.0 - 15.0 ) + 10.0 );\n\n}\n\n#define K 0.142857142857 // 1/7\n#define Ko 0.428571428571 // 1/2-K/2\n#define K2 0.020408163265306 // 1/(7*7)\n#define Kd2 0.0714285714285 // K/2\n#define Kz 0.166666666667 // 1/6\n#define Kzo 0.416666666667 // 1/2-1/6*2\n#define jitter 1.0 // smaller jitter gives more regular pattern\n#define jitter1 0.8 // smaller jitter gives less errors in F1 F2\n"; // eslint-disable-line
10446
+ var noise_perlin = "#include <noise_perlin_2D>\n#include <noise_perlin_3D>\n#include <noise_perlin_4D>\n"; // eslint-disable-line
10447
+ var noise_perlin_2D = "//\n// GLSL textureless classic 2D noise \"cnoise\",\n// with an RSL-style periodic variant \"pnoise\".\n// Author: Stefan Gustavson (stefan.gustavson@liu.se)\n// Version: 2011-08-22\n//\n// Many thanks to Ian McEwan of Ashima Arts for the\n// ideas for permutation and gradient selection.\n//\n// Copyright (c) 2011 Stefan Gustavson. All rights reserved.\n// Distributed under the MIT license. See LICENSE file.\n// https://github.com/stegu/webgl-noise\n//\n\n// Classic Perlin noise\nfloat perlin( vec2 P ) {\n\n vec4 Pi = floor(P.xyxy) + vec4(0.0, 0.0, 1.0, 1.0);\n vec4 Pf = fract(P.xyxy) - vec4(0.0, 0.0, 1.0, 1.0);\n Pi = mod289(Pi); // To avoid truncation effects in permutation\n vec4 ix = Pi.xzxz;\n vec4 iy = Pi.yyww;\n vec4 fx = Pf.xzxz;\n vec4 fy = Pf.yyww;\n\n vec4 i = permute(permute(ix) + iy);\n\n vec4 gx = fract(i * (1.0 / 41.0)) * 2.0 - 1.0 ;\n vec4 gy = abs(gx) - 0.5 ;\n vec4 tx = floor(gx + 0.5);\n gx = gx - tx;\n\n vec2 g00 = vec2(gx.x,gy.x);\n vec2 g10 = vec2(gx.y,gy.y);\n vec2 g01 = vec2(gx.z,gy.z);\n vec2 g11 = vec2(gx.w,gy.w);\n\n vec4 norm = taylorInvSqrt(vec4(dot(g00, g00), dot(g01, g01), dot(g10, g10), dot(g11, g11)));\n g00 *= norm.x;\n g01 *= norm.y;\n g10 *= norm.z;\n g11 *= norm.w;\n\n float n00 = dot(g00, vec2(fx.x, fy.x));\n float n10 = dot(g10, vec2(fx.y, fy.y));\n float n01 = dot(g01, vec2(fx.z, fy.z));\n float n11 = dot(g11, vec2(fx.w, fy.w));\n\n vec2 fade_xy = fade(Pf.xy);\n vec2 n_x = mix(vec2(n00, n01), vec2(n10, n11), fade_xy.x);\n float n_xy = mix(n_x.x, n_x.y, fade_xy.y);\n return 2.3 * n_xy;\n\n}\n\n// Classic Perlin noise, periodic variant\nfloat perlin( vec2 P, vec2 rep ) {\n\n vec4 Pi = floor(P.xyxy) + vec4(0.0, 0.0, 1.0, 1.0);\n vec4 Pf = fract(P.xyxy) - vec4(0.0, 0.0, 1.0, 1.0);\n Pi = mod(Pi, rep.xyxy); // To create noise with explicit period\n Pi = mod289(Pi); // To avoid truncation effects in permutation\n vec4 ix = Pi.xzxz;\n vec4 iy = Pi.yyww;\n vec4 fx = Pf.xzxz;\n vec4 fy = Pf.yyww;\n\n vec4 i = permute(permute(ix) + iy);\n\n vec4 gx = fract(i * (1.0 / 41.0)) * 2.0 - 1.0 ;\n vec4 gy = abs(gx) - 0.5 ;\n vec4 tx = floor(gx + 0.5);\n gx = gx - tx;\n\n vec2 g00 = vec2(gx.x,gy.x);\n vec2 g10 = vec2(gx.y,gy.y);\n vec2 g01 = vec2(gx.z,gy.z);\n vec2 g11 = vec2(gx.w,gy.w);\n\n vec4 norm = taylorInvSqrt(vec4(dot(g00, g00), dot(g01, g01), dot(g10, g10), dot(g11, g11)));\n g00 *= norm.x;\n g01 *= norm.y;\n g10 *= norm.z;\n g11 *= norm.w;\n\n float n00 = dot(g00, vec2(fx.x, fy.x));\n float n10 = dot(g10, vec2(fx.y, fy.y));\n float n01 = dot(g01, vec2(fx.z, fy.z));\n float n11 = dot(g11, vec2(fx.w, fy.w));\n\n vec2 fade_xy = fade(Pf.xy);\n vec2 n_x = mix(vec2(n00, n01), vec2(n10, n11), fade_xy.x);\n float n_xy = mix(n_x.x, n_x.y, fade_xy.y);\n return 2.3 * n_xy;\n\n}\n"; // eslint-disable-line
10448
+ var noise_perlin_3D = "//\n// GLSL textureless classic 3D noise \"cnoise\",\n// with an RSL-style periodic variant \"pnoise\".\n// Author: Stefan Gustavson (stefan.gustavson@liu.se)\n// Version: 2011-10-11\n//\n// Many thanks to Ian McEwan of Ashima Arts for the\n// ideas for permutation and gradient selection.\n//\n// Copyright (c) 2011 Stefan Gustavson. All rights reserved.\n// Distributed under the MIT license. See LICENSE file.\n// https://github.com/stegu/webgl-noise\n//\n\n// Classic Perlin noise\nfloat perlin( vec3 P ) {\n\n vec3 Pi0 = floor(P); // Integer part for indexing\n vec3 Pi1 = Pi0 + vec3(1.0); // Integer part + 1\n Pi0 = mod289(Pi0);\n Pi1 = mod289(Pi1);\n vec3 Pf0 = fract(P); // Fractional part for interpolation\n vec3 Pf1 = Pf0 - vec3(1.0); // Fractional part - 1.0\n vec4 ix = vec4(Pi0.x, Pi1.x, Pi0.x, Pi1.x);\n vec4 iy = vec4(Pi0.yy, Pi1.yy);\n vec4 iz0 = Pi0.zzzz;\n vec4 iz1 = Pi1.zzzz;\n\n vec4 ixy = permute(permute(ix) + iy);\n vec4 ixy0 = permute(ixy + iz0);\n vec4 ixy1 = permute(ixy + iz1);\n\n vec4 gx0 = ixy0 * (1.0 / 7.0);\n vec4 gy0 = fract(floor(gx0) * (1.0 / 7.0)) - 0.5;\n gx0 = fract(gx0);\n vec4 gz0 = vec4(0.5) - abs(gx0) - abs(gy0);\n vec4 sz0 = step(gz0, vec4(0.0));\n gx0 -= sz0 * (step(0.0, gx0) - 0.5);\n gy0 -= sz0 * (step(0.0, gy0) - 0.5);\n\n vec4 gx1 = ixy1 * (1.0 / 7.0);\n vec4 gy1 = fract(floor(gx1) * (1.0 / 7.0)) - 0.5;\n gx1 = fract(gx1);\n vec4 gz1 = vec4(0.5) - abs(gx1) - abs(gy1);\n vec4 sz1 = step(gz1, vec4(0.0));\n gx1 -= sz1 * (step(0.0, gx1) - 0.5);\n gy1 -= sz1 * (step(0.0, gy1) - 0.5);\n\n vec3 g000 = vec3(gx0.x,gy0.x,gz0.x);\n vec3 g100 = vec3(gx0.y,gy0.y,gz0.y);\n vec3 g010 = vec3(gx0.z,gy0.z,gz0.z);\n vec3 g110 = vec3(gx0.w,gy0.w,gz0.w);\n vec3 g001 = vec3(gx1.x,gy1.x,gz1.x);\n vec3 g101 = vec3(gx1.y,gy1.y,gz1.y);\n vec3 g011 = vec3(gx1.z,gy1.z,gz1.z);\n vec3 g111 = vec3(gx1.w,gy1.w,gz1.w);\n\n vec4 norm0 = taylorInvSqrt(vec4(dot(g000, g000), dot(g010, g010), dot(g100, g100), dot(g110, g110)));\n g000 *= norm0.x;\n g010 *= norm0.y;\n g100 *= norm0.z;\n g110 *= norm0.w;\n vec4 norm1 = taylorInvSqrt(vec4(dot(g001, g001), dot(g011, g011), dot(g101, g101), dot(g111, g111)));\n g001 *= norm1.x;\n g011 *= norm1.y;\n g101 *= norm1.z;\n g111 *= norm1.w;\n\n float n000 = dot(g000, Pf0);\n float n100 = dot(g100, vec3(Pf1.x, Pf0.yz));\n float n010 = dot(g010, vec3(Pf0.x, Pf1.y, Pf0.z));\n float n110 = dot(g110, vec3(Pf1.xy, Pf0.z));\n float n001 = dot(g001, vec3(Pf0.xy, Pf1.z));\n float n101 = dot(g101, vec3(Pf1.x, Pf0.y, Pf1.z));\n float n011 = dot(g011, vec3(Pf0.x, Pf1.yz));\n float n111 = dot(g111, Pf1);\n\n vec3 fade_xyz = fade(Pf0);\n vec4 n_z = mix(vec4(n000, n100, n010, n110), vec4(n001, n101, n011, n111), fade_xyz.z);\n vec2 n_yz = mix(n_z.xy, n_z.zw, fade_xyz.y);\n float n_xyz = mix(n_yz.x, n_yz.y, fade_xyz.x);\n return 2.2 * n_xyz;\n\n}\n\n// Classic Perlin noise, periodic variant\nfloat perlin( vec3 P, vec3 rep ) {\n\n vec3 Pi0 = mod(floor(P), rep); // Integer part, modulo period\n vec3 Pi1 = mod(Pi0 + vec3(1.0), rep); // Integer part + 1, mod period\n Pi0 = mod289(Pi0);\n Pi1 = mod289(Pi1);\n vec3 Pf0 = fract(P); // Fractional part for interpolation\n vec3 Pf1 = Pf0 - vec3(1.0); // Fractional part - 1.0\n vec4 ix = vec4(Pi0.x, Pi1.x, Pi0.x, Pi1.x);\n vec4 iy = vec4(Pi0.yy, Pi1.yy);\n vec4 iz0 = Pi0.zzzz;\n vec4 iz1 = Pi1.zzzz;\n\n vec4 ixy = permute(permute(ix) + iy);\n vec4 ixy0 = permute(ixy + iz0);\n vec4 ixy1 = permute(ixy + iz1);\n\n vec4 gx0 = ixy0 * (1.0 / 7.0);\n vec4 gy0 = fract(floor(gx0) * (1.0 / 7.0)) - 0.5;\n gx0 = fract(gx0);\n vec4 gz0 = vec4(0.5) - abs(gx0) - abs(gy0);\n vec4 sz0 = step(gz0, vec4(0.0));\n gx0 -= sz0 * (step(0.0, gx0) - 0.5);\n gy0 -= sz0 * (step(0.0, gy0) - 0.5);\n\n vec4 gx1 = ixy1 * (1.0 / 7.0);\n vec4 gy1 = fract(floor(gx1) * (1.0 / 7.0)) - 0.5;\n gx1 = fract(gx1);\n vec4 gz1 = vec4(0.5) - abs(gx1) - abs(gy1);\n vec4 sz1 = step(gz1, vec4(0.0));\n gx1 -= sz1 * (step(0.0, gx1) - 0.5);\n gy1 -= sz1 * (step(0.0, gy1) - 0.5);\n\n vec3 g000 = vec3(gx0.x,gy0.x,gz0.x);\n vec3 g100 = vec3(gx0.y,gy0.y,gz0.y);\n vec3 g010 = vec3(gx0.z,gy0.z,gz0.z);\n vec3 g110 = vec3(gx0.w,gy0.w,gz0.w);\n vec3 g001 = vec3(gx1.x,gy1.x,gz1.x);\n vec3 g101 = vec3(gx1.y,gy1.y,gz1.y);\n vec3 g011 = vec3(gx1.z,gy1.z,gz1.z);\n vec3 g111 = vec3(gx1.w,gy1.w,gz1.w);\n\n vec4 norm0 = taylorInvSqrt(vec4(dot(g000, g000), dot(g010, g010), dot(g100, g100), dot(g110, g110)));\n g000 *= norm0.x;\n g010 *= norm0.y;\n g100 *= norm0.z;\n g110 *= norm0.w;\n vec4 norm1 = taylorInvSqrt(vec4(dot(g001, g001), dot(g011, g011), dot(g101, g101), dot(g111, g111)));\n g001 *= norm1.x;\n g011 *= norm1.y;\n g101 *= norm1.z;\n g111 *= norm1.w;\n\n float n000 = dot(g000, Pf0);\n float n100 = dot(g100, vec3(Pf1.x, Pf0.yz));\n float n010 = dot(g010, vec3(Pf0.x, Pf1.y, Pf0.z));\n float n110 = dot(g110, vec3(Pf1.xy, Pf0.z));\n float n001 = dot(g001, vec3(Pf0.xy, Pf1.z));\n float n101 = dot(g101, vec3(Pf1.x, Pf0.y, Pf1.z));\n float n011 = dot(g011, vec3(Pf0.x, Pf1.yz));\n float n111 = dot(g111, Pf1);\n\n vec3 fade_xyz = fade(Pf0);\n vec4 n_z = mix(vec4(n000, n100, n010, n110), vec4(n001, n101, n011, n111), fade_xyz.z);\n vec2 n_yz = mix(n_z.xy, n_z.zw, fade_xyz.y);\n float n_xyz = mix(n_yz.x, n_yz.y, fade_xyz.x);\n return 2.2 * n_xyz;\n\n}\n"; // eslint-disable-line
10449
+ var noise_perlin_4D = "//\n// GLSL textureless classic 4D noise \"cnoise\",\n// with an RSL-style periodic variant \"pnoise\".\n// Author: Stefan Gustavson (stefan.gustavson@liu.se)\n// Version: 2011-08-22\n//\n// Many thanks to Ian McEwan of Ashima Arts for the\n// ideas for permutation and gradient selection.\n//\n// Copyright (c) 2011 Stefan Gustavson. All rights reserved.\n// Distributed under the MIT license. See LICENSE file.\n// https://github.com/stegu/webgl-noise\n//\n\n// Classic Perlin noise\nfloat perlin( vec4 P ) {\n\n vec4 Pi0 = floor(P); // Integer part for indexing\n vec4 Pi1 = Pi0 + 1.0; // Integer part + 1\n Pi0 = mod289(Pi0);\n Pi1 = mod289(Pi1);\n vec4 Pf0 = fract(P); // Fractional part for interpolation\n vec4 Pf1 = Pf0 - 1.0; // Fractional part - 1.0\n vec4 ix = vec4(Pi0.x, Pi1.x, Pi0.x, Pi1.x);\n vec4 iy = vec4(Pi0.yy, Pi1.yy);\n vec4 iz0 = vec4(Pi0.zzzz);\n vec4 iz1 = vec4(Pi1.zzzz);\n vec4 iw0 = vec4(Pi0.wwww);\n vec4 iw1 = vec4(Pi1.wwww);\n\n vec4 ixy = permute(permute(ix) + iy);\n vec4 ixy0 = permute(ixy + iz0);\n vec4 ixy1 = permute(ixy + iz1);\n vec4 ixy00 = permute(ixy0 + iw0);\n vec4 ixy01 = permute(ixy0 + iw1);\n vec4 ixy10 = permute(ixy1 + iw0);\n vec4 ixy11 = permute(ixy1 + iw1);\n\n vec4 gx00 = ixy00 * (1.0 / 7.0);\n vec4 gy00 = floor(gx00) * (1.0 / 7.0);\n vec4 gz00 = floor(gy00) * (1.0 / 6.0);\n gx00 = fract(gx00) - 0.5;\n gy00 = fract(gy00) - 0.5;\n gz00 = fract(gz00) - 0.5;\n vec4 gw00 = vec4(0.75) - abs(gx00) - abs(gy00) - abs(gz00);\n vec4 sw00 = step(gw00, vec4(0.0));\n gx00 -= sw00 * (step(0.0, gx00) - 0.5);\n gy00 -= sw00 * (step(0.0, gy00) - 0.5);\n\n vec4 gx01 = ixy01 * (1.0 / 7.0);\n vec4 gy01 = floor(gx01) * (1.0 / 7.0);\n vec4 gz01 = floor(gy01) * (1.0 / 6.0);\n gx01 = fract(gx01) - 0.5;\n gy01 = fract(gy01) - 0.5;\n gz01 = fract(gz01) - 0.5;\n vec4 gw01 = vec4(0.75) - abs(gx01) - abs(gy01) - abs(gz01);\n vec4 sw01 = step(gw01, vec4(0.0));\n gx01 -= sw01 * (step(0.0, gx01) - 0.5);\n gy01 -= sw01 * (step(0.0, gy01) - 0.5);\n\n vec4 gx10 = ixy10 * (1.0 / 7.0);\n vec4 gy10 = floor(gx10) * (1.0 / 7.0);\n vec4 gz10 = floor(gy10) * (1.0 / 6.0);\n gx10 = fract(gx10) - 0.5;\n gy10 = fract(gy10) - 0.5;\n gz10 = fract(gz10) - 0.5;\n vec4 gw10 = vec4(0.75) - abs(gx10) - abs(gy10) - abs(gz10);\n vec4 sw10 = step(gw10, vec4(0.0));\n gx10 -= sw10 * (step(0.0, gx10) - 0.5);\n gy10 -= sw10 * (step(0.0, gy10) - 0.5);\n\n vec4 gx11 = ixy11 * (1.0 / 7.0);\n vec4 gy11 = floor(gx11) * (1.0 / 7.0);\n vec4 gz11 = floor(gy11) * (1.0 / 6.0);\n gx11 = fract(gx11) - 0.5;\n gy11 = fract(gy11) - 0.5;\n gz11 = fract(gz11) - 0.5;\n vec4 gw11 = vec4(0.75) - abs(gx11) - abs(gy11) - abs(gz11);\n vec4 sw11 = step(gw11, vec4(0.0));\n gx11 -= sw11 * (step(0.0, gx11) - 0.5);\n gy11 -= sw11 * (step(0.0, gy11) - 0.5);\n\n vec4 g0000 = vec4(gx00.x,gy00.x,gz00.x,gw00.x);\n vec4 g1000 = vec4(gx00.y,gy00.y,gz00.y,gw00.y);\n vec4 g0100 = vec4(gx00.z,gy00.z,gz00.z,gw00.z);\n vec4 g1100 = vec4(gx00.w,gy00.w,gz00.w,gw00.w);\n vec4 g0010 = vec4(gx10.x,gy10.x,gz10.x,gw10.x);\n vec4 g1010 = vec4(gx10.y,gy10.y,gz10.y,gw10.y);\n vec4 g0110 = vec4(gx10.z,gy10.z,gz10.z,gw10.z);\n vec4 g1110 = vec4(gx10.w,gy10.w,gz10.w,gw10.w);\n vec4 g0001 = vec4(gx01.x,gy01.x,gz01.x,gw01.x);\n vec4 g1001 = vec4(gx01.y,gy01.y,gz01.y,gw01.y);\n vec4 g0101 = vec4(gx01.z,gy01.z,gz01.z,gw01.z);\n vec4 g1101 = vec4(gx01.w,gy01.w,gz01.w,gw01.w);\n vec4 g0011 = vec4(gx11.x,gy11.x,gz11.x,gw11.x);\n vec4 g1011 = vec4(gx11.y,gy11.y,gz11.y,gw11.y);\n vec4 g0111 = vec4(gx11.z,gy11.z,gz11.z,gw11.z);\n vec4 g1111 = vec4(gx11.w,gy11.w,gz11.w,gw11.w);\n\n vec4 norm00 = taylorInvSqrt(vec4(dot(g0000, g0000), dot(g0100, g0100), dot(g1000, g1000), dot(g1100, g1100)));\n g0000 *= norm00.x;\n g0100 *= norm00.y;\n g1000 *= norm00.z;\n g1100 *= norm00.w;\n\n vec4 norm01 = taylorInvSqrt(vec4(dot(g0001, g0001), dot(g0101, g0101), dot(g1001, g1001), dot(g1101, g1101)));\n g0001 *= norm01.x;\n g0101 *= norm01.y;\n g1001 *= norm01.z;\n g1101 *= norm01.w;\n\n vec4 norm10 = taylorInvSqrt(vec4(dot(g0010, g0010), dot(g0110, g0110), dot(g1010, g1010), dot(g1110, g1110)));\n g0010 *= norm10.x;\n g0110 *= norm10.y;\n g1010 *= norm10.z;\n g1110 *= norm10.w;\n\n vec4 norm11 = taylorInvSqrt(vec4(dot(g0011, g0011), dot(g0111, g0111), dot(g1011, g1011), dot(g1111, g1111)));\n g0011 *= norm11.x;\n g0111 *= norm11.y;\n g1011 *= norm11.z;\n g1111 *= norm11.w;\n\n float n0000 = dot(g0000, Pf0);\n float n1000 = dot(g1000, vec4(Pf1.x, Pf0.yzw));\n float n0100 = dot(g0100, vec4(Pf0.x, Pf1.y, Pf0.zw));\n float n1100 = dot(g1100, vec4(Pf1.xy, Pf0.zw));\n float n0010 = dot(g0010, vec4(Pf0.xy, Pf1.z, Pf0.w));\n float n1010 = dot(g1010, vec4(Pf1.x, Pf0.y, Pf1.z, Pf0.w));\n float n0110 = dot(g0110, vec4(Pf0.x, Pf1.yz, Pf0.w));\n float n1110 = dot(g1110, vec4(Pf1.xyz, Pf0.w));\n float n0001 = dot(g0001, vec4(Pf0.xyz, Pf1.w));\n float n1001 = dot(g1001, vec4(Pf1.x, Pf0.yz, Pf1.w));\n float n0101 = dot(g0101, vec4(Pf0.x, Pf1.y, Pf0.z, Pf1.w));\n float n1101 = dot(g1101, vec4(Pf1.xy, Pf0.z, Pf1.w));\n float n0011 = dot(g0011, vec4(Pf0.xy, Pf1.zw));\n float n1011 = dot(g1011, vec4(Pf1.x, Pf0.y, Pf1.zw));\n float n0111 = dot(g0111, vec4(Pf0.x, Pf1.yzw));\n float n1111 = dot(g1111, Pf1);\n\n vec4 fade_xyzw = fade(Pf0);\n vec4 n_0w = mix(vec4(n0000, n1000, n0100, n1100), vec4(n0001, n1001, n0101, n1101), fade_xyzw.w);\n vec4 n_1w = mix(vec4(n0010, n1010, n0110, n1110), vec4(n0011, n1011, n0111, n1111), fade_xyzw.w);\n vec4 n_zw = mix(n_0w, n_1w, fade_xyzw.z);\n vec2 n_yzw = mix(n_zw.xy, n_zw.zw, fade_xyzw.y);\n float n_xyzw = mix(n_yzw.x, n_yzw.y, fade_xyzw.x);\n return 2.2 * n_xyzw;\n\n}\n\n// Classic Perlin noise, periodic version\nfloat perlin( vec4 P, vec4 rep ) {\n\n vec4 Pi0 = mod(floor(P), rep); // Integer part modulo rep\n vec4 Pi1 = mod(Pi0 + 1.0, rep); // Integer part + 1 mod rep\n Pi0 = mod289(Pi0);\n Pi1 = mod289(Pi1);\n vec4 Pf0 = fract(P); // Fractional part for interpolation\n vec4 Pf1 = Pf0 - 1.0; // Fractional part - 1.0\n vec4 ix = vec4(Pi0.x, Pi1.x, Pi0.x, Pi1.x);\n vec4 iy = vec4(Pi0.yy, Pi1.yy);\n vec4 iz0 = vec4(Pi0.zzzz);\n vec4 iz1 = vec4(Pi1.zzzz);\n vec4 iw0 = vec4(Pi0.wwww);\n vec4 iw1 = vec4(Pi1.wwww);\n\n vec4 ixy = permute(permute(ix) + iy);\n vec4 ixy0 = permute(ixy + iz0);\n vec4 ixy1 = permute(ixy + iz1);\n vec4 ixy00 = permute(ixy0 + iw0);\n vec4 ixy01 = permute(ixy0 + iw1);\n vec4 ixy10 = permute(ixy1 + iw0);\n vec4 ixy11 = permute(ixy1 + iw1);\n\n vec4 gx00 = ixy00 * (1.0 / 7.0);\n vec4 gy00 = floor(gx00) * (1.0 / 7.0);\n vec4 gz00 = floor(gy00) * (1.0 / 6.0);\n gx00 = fract(gx00) - 0.5;\n gy00 = fract(gy00) - 0.5;\n gz00 = fract(gz00) - 0.5;\n vec4 gw00 = vec4(0.75) - abs(gx00) - abs(gy00) - abs(gz00);\n vec4 sw00 = step(gw00, vec4(0.0));\n gx00 -= sw00 * (step(0.0, gx00) - 0.5);\n gy00 -= sw00 * (step(0.0, gy00) - 0.5);\n\n vec4 gx01 = ixy01 * (1.0 / 7.0);\n vec4 gy01 = floor(gx01) * (1.0 / 7.0);\n vec4 gz01 = floor(gy01) * (1.0 / 6.0);\n gx01 = fract(gx01) - 0.5;\n gy01 = fract(gy01) - 0.5;\n gz01 = fract(gz01) - 0.5;\n vec4 gw01 = vec4(0.75) - abs(gx01) - abs(gy01) - abs(gz01);\n vec4 sw01 = step(gw01, vec4(0.0));\n gx01 -= sw01 * (step(0.0, gx01) - 0.5);\n gy01 -= sw01 * (step(0.0, gy01) - 0.5);\n\n vec4 gx10 = ixy10 * (1.0 / 7.0);\n vec4 gy10 = floor(gx10) * (1.0 / 7.0);\n vec4 gz10 = floor(gy10) * (1.0 / 6.0);\n gx10 = fract(gx10) - 0.5;\n gy10 = fract(gy10) - 0.5;\n gz10 = fract(gz10) - 0.5;\n vec4 gw10 = vec4(0.75) - abs(gx10) - abs(gy10) - abs(gz10);\n vec4 sw10 = step(gw10, vec4(0.0));\n gx10 -= sw10 * (step(0.0, gx10) - 0.5);\n gy10 -= sw10 * (step(0.0, gy10) - 0.5);\n\n vec4 gx11 = ixy11 * (1.0 / 7.0);\n vec4 gy11 = floor(gx11) * (1.0 / 7.0);\n vec4 gz11 = floor(gy11) * (1.0 / 6.0);\n gx11 = fract(gx11) - 0.5;\n gy11 = fract(gy11) - 0.5;\n gz11 = fract(gz11) - 0.5;\n vec4 gw11 = vec4(0.75) - abs(gx11) - abs(gy11) - abs(gz11);\n vec4 sw11 = step(gw11, vec4(0.0));\n gx11 -= sw11 * (step(0.0, gx11) - 0.5);\n gy11 -= sw11 * (step(0.0, gy11) - 0.5);\n\n vec4 g0000 = vec4(gx00.x,gy00.x,gz00.x,gw00.x);\n vec4 g1000 = vec4(gx00.y,gy00.y,gz00.y,gw00.y);\n vec4 g0100 = vec4(gx00.z,gy00.z,gz00.z,gw00.z);\n vec4 g1100 = vec4(gx00.w,gy00.w,gz00.w,gw00.w);\n vec4 g0010 = vec4(gx10.x,gy10.x,gz10.x,gw10.x);\n vec4 g1010 = vec4(gx10.y,gy10.y,gz10.y,gw10.y);\n vec4 g0110 = vec4(gx10.z,gy10.z,gz10.z,gw10.z);\n vec4 g1110 = vec4(gx10.w,gy10.w,gz10.w,gw10.w);\n vec4 g0001 = vec4(gx01.x,gy01.x,gz01.x,gw01.x);\n vec4 g1001 = vec4(gx01.y,gy01.y,gz01.y,gw01.y);\n vec4 g0101 = vec4(gx01.z,gy01.z,gz01.z,gw01.z);\n vec4 g1101 = vec4(gx01.w,gy01.w,gz01.w,gw01.w);\n vec4 g0011 = vec4(gx11.x,gy11.x,gz11.x,gw11.x);\n vec4 g1011 = vec4(gx11.y,gy11.y,gz11.y,gw11.y);\n vec4 g0111 = vec4(gx11.z,gy11.z,gz11.z,gw11.z);\n vec4 g1111 = vec4(gx11.w,gy11.w,gz11.w,gw11.w);\n\n vec4 norm00 = taylorInvSqrt(vec4(dot(g0000, g0000), dot(g0100, g0100), dot(g1000, g1000), dot(g1100, g1100)));\n g0000 *= norm00.x;\n g0100 *= norm00.y;\n g1000 *= norm00.z;\n g1100 *= norm00.w;\n\n vec4 norm01 = taylorInvSqrt(vec4(dot(g0001, g0001), dot(g0101, g0101), dot(g1001, g1001), dot(g1101, g1101)));\n g0001 *= norm01.x;\n g0101 *= norm01.y;\n g1001 *= norm01.z;\n g1101 *= norm01.w;\n\n vec4 norm10 = taylorInvSqrt(vec4(dot(g0010, g0010), dot(g0110, g0110), dot(g1010, g1010), dot(g1110, g1110)));\n g0010 *= norm10.x;\n g0110 *= norm10.y;\n g1010 *= norm10.z;\n g1110 *= norm10.w;\n\n vec4 norm11 = taylorInvSqrt(vec4(dot(g0011, g0011), dot(g0111, g0111), dot(g1011, g1011), dot(g1111, g1111)));\n g0011 *= norm11.x;\n g0111 *= norm11.y;\n g1011 *= norm11.z;\n g1111 *= norm11.w;\n\n float n0000 = dot(g0000, Pf0);\n float n1000 = dot(g1000, vec4(Pf1.x, Pf0.yzw));\n float n0100 = dot(g0100, vec4(Pf0.x, Pf1.y, Pf0.zw));\n float n1100 = dot(g1100, vec4(Pf1.xy, Pf0.zw));\n float n0010 = dot(g0010, vec4(Pf0.xy, Pf1.z, Pf0.w));\n float n1010 = dot(g1010, vec4(Pf1.x, Pf0.y, Pf1.z, Pf0.w));\n float n0110 = dot(g0110, vec4(Pf0.x, Pf1.yz, Pf0.w));\n float n1110 = dot(g1110, vec4(Pf1.xyz, Pf0.w));\n float n0001 = dot(g0001, vec4(Pf0.xyz, Pf1.w));\n float n1001 = dot(g1001, vec4(Pf1.x, Pf0.yz, Pf1.w));\n float n0101 = dot(g0101, vec4(Pf0.x, Pf1.y, Pf0.z, Pf1.w));\n float n1101 = dot(g1101, vec4(Pf1.xy, Pf0.z, Pf1.w));\n float n0011 = dot(g0011, vec4(Pf0.xy, Pf1.zw));\n float n1011 = dot(g1011, vec4(Pf1.x, Pf0.y, Pf1.zw));\n float n0111 = dot(g0111, vec4(Pf0.x, Pf1.yzw));\n float n1111 = dot(g1111, Pf1);\n\n vec4 fade_xyzw = fade(Pf0);\n vec4 n_0w = mix(vec4(n0000, n1000, n0100, n1100), vec4(n0001, n1001, n0101, n1101), fade_xyzw.w);\n vec4 n_1w = mix(vec4(n0010, n1010, n0110, n1110), vec4(n0011, n1011, n0111, n1111), fade_xyzw.w);\n vec4 n_zw = mix(n_0w, n_1w, fade_xyzw.z);\n vec2 n_yzw = mix(n_zw.xy, n_zw.zw, fade_xyzw.y);\n float n_xyzw = mix(n_yzw.x, n_yzw.y, fade_xyzw.x);\n return 2.2 * n_xyzw;\n\n}\n"; // eslint-disable-line
10450
+ var noise_psrd_2D = "// Periodic (tiling) 2-D simplex noise (hexagonal lattice gradient noise)\n// with rotating gradients and analytic derivatives.\n// Variants also without the derivative (no \"d\" in the name), without\n// the tiling property (no \"p\" in the name) and without the rotating\n// gradients (no \"r\" in the name).\n//\n// This is (yet) another variation on simplex noise. It's similar to the\n// version presented by Ken Perlin, but the grid is axis-aligned and\n// slightly stretched in the y direction to permit rectangular tiling.\n//\n// The noise can be made to tile seamlessly to any integer period in x and\n// any even integer period in y. Odd periods may be specified for y, but\n// then the actual tiling period will be twice that number.\n//\n// The rotating gradients give the appearance of a swirling motion, and can\n// serve a similar purpose for animation as motion along z in 3-D noise.\n// The rotating gradients in conjunction with the analytic derivatives\n// can make \"flow noise\" effects as presented by Perlin and Neyret.\n//\n// vec3 {p}s{r}dnoise(vec2 pos {, vec2 per} {, float rot})\n// \"pos\" is the input (x,y) coordinate\n// \"per\" is the x and y period, where per.x is a positive integer\n// and per.y is a positive even integer\n// \"rot\" is the angle to rotate the gradients (any float value,\n// where 0.0 is no rotation and 1.0 is one full turn)\n// The first component of the 3-element return vector is the noise value.\n// The second and third components are the x and y partial derivatives.\n//\n// float {p}s{r}noise(vec2 pos {, vec2 per} {, float rot})\n// \"pos\" is the input (x,y) coordinate\n// \"per\" is the x and y period, where per.x is a positive integer\n// and per.y is a positive even integer\n// \"rot\" is the angle to rotate the gradients (any float value,\n// where 0.0 is no rotation and 1.0 is one full turn)\n// The return value is the noise value.\n// Partial derivatives are not computed, making these functions faster.\n//\n// Author: Stefan Gustavson (stefan.gustavson@gmail.com)\n// Version 2016-05-10.\n//\n// Many thanks to Ian McEwan of Ashima Arts for the\n// idea of using a permutation polynomial.\n//\n// Copyright (c) 2016 Stefan Gustavson. All rights reserved.\n// Distributed under the MIT license. See LICENSE file.\n// https://github.com/stegu/webgl-noise\n//\n\n// Hashed 2-D gradients with an extra rotation.\n// (The constant 0.0243902439 is 1/41)\nvec2 rgrad2( vec2 p, float rot ) {\n\n // For more isotropic gradients, sin/cos can be used instead.\n float u = permute( permute( p.x ) + p.y ) * 0.0243902439 + rot; // Rotate by shift\n u = fract( u ) * 6.28318530718; // 2*pi\n return vec2( cos( u ), sin( u ));\n\n}\n\n//\n// 2-D tiling simplex noise with rotating gradients and analytical derivative.\n// The first component of the 3-element return vector is the noise value,\n// and the second and third components are the x and y partial derivatives.\n//\nvec3 psrdnoise(vec2 pos, vec2 per, float rot) {\n // Hack: offset y slightly to hide some rare artifacts\n pos.y += 0.01;\n // Skew to hexagonal grid\n vec2 uv = vec2(pos.x + pos.y*0.5, pos.y);\n\n vec2 i0 = floor(uv);\n vec2 f0 = fract(uv);\n // Traversal order\n vec2 i1 = (f0.x > f0.y) ? vec2(1.0, 0.0) : vec2(0.0, 1.0);\n\n // Unskewed grid points in (x,y) space\n vec2 p0 = vec2(i0.x - i0.y * 0.5, i0.y);\n vec2 p1 = vec2(p0.x + i1.x - i1.y * 0.5, p0.y + i1.y);\n vec2 p2 = vec2(p0.x + 0.5, p0.y + 1.0);\n\n // Integer grid point indices in (u,v) space\n i1 = i0 + i1;\n vec2 i2 = i0 + vec2(1.0, 1.0);\n\n // Vectors in unskewed (x,y) coordinates from\n // each of the simplex corners to the evaluation point\n vec2 d0 = pos - p0;\n vec2 d1 = pos - p1;\n vec2 d2 = pos - p2;\n\n // Wrap i0, i1 and i2 to the desired period before gradient hashing:\n // wrap points in (x,y), map to (u,v)\n vec3 xw = mod(vec3(p0.x, p1.x, p2.x), per.x);\n vec3 yw = mod(vec3(p0.y, p1.y, p2.y), per.y);\n vec3 iuw = xw + 0.5 * yw;\n vec3 ivw = yw;\n\n // Create gradients from indices\n vec2 g0 = rgrad2(vec2(iuw.x, ivw.x), rot);\n vec2 g1 = rgrad2(vec2(iuw.y, ivw.y), rot);\n vec2 g2 = rgrad2(vec2(iuw.z, ivw.z), rot);\n\n // Gradients dot vectors to corresponding corners\n // (The derivatives of this are simply the gradients)\n vec3 w = vec3(dot(g0, d0), dot(g1, d1), dot(g2, d2));\n\n // Radial weights from corners\n // 0.8 is the square of 2/sqrt(5), the distance from\n // a grid point to the nearest simplex boundary\n vec3 t = 0.8 - vec3(dot(d0, d0), dot(d1, d1), dot(d2, d2));\n\n // Partial derivatives for analytical gradient computation\n vec3 dtdx = -2.0 * vec3(d0.x, d1.x, d2.x);\n vec3 dtdy = -2.0 * vec3(d0.y, d1.y, d2.y);\n\n // Set influence of each surflet to zero outside radius sqrt(0.8)\n if (t.x < 0.0) {\n dtdx.x = 0.0;\n dtdy.x = 0.0;\n\tt.x = 0.0;\n }\n if (t.y < 0.0) {\n dtdx.y = 0.0;\n dtdy.y = 0.0;\n\tt.y = 0.0;\n }\n if (t.z < 0.0) {\n dtdx.z = 0.0;\n dtdy.z = 0.0;\n\tt.z = 0.0;\n }\n\n // Fourth power of t (and third power for derivative)\n vec3 t2 = t * t;\n vec3 t4 = t2 * t2;\n vec3 t3 = t2 * t;\n\n // Final noise value is:\n // sum of ((radial weights) times (gradient dot vector from corner))\n float n = dot(t4, w);\n\n // Final analytical derivative (gradient of a sum of scalar products)\n vec2 dt0 = vec2(dtdx.x, dtdy.x) * 4.0 * t3.x;\n vec2 dn0 = t4.x * g0 + dt0 * w.x;\n vec2 dt1 = vec2(dtdx.y, dtdy.y) * 4.0 * t3.y;\n vec2 dn1 = t4.y * g1 + dt1 * w.y;\n vec2 dt2 = vec2(dtdx.z, dtdy.z) * 4.0 * t3.z;\n vec2 dn2 = t4.z * g2 + dt2 * w.z;\n\n return 11.0*vec3(n, dn0 + dn1 + dn2);\n}\n\n//\n// 2-D tiling simplex noise with fixed gradients\n// and analytical derivative.\n// This function is implemented as a wrapper to \"psrdnoise\",\n// at the minimal cost of three extra additions.\n//\nvec3 psdnoise(vec2 pos, vec2 per) {\n return psrdnoise(pos, per, 0.0);\n}\n\n//\n// 2-D tiling simplex noise with rotating gradients,\n// but without the analytical derivative.\n//\nfloat psrnoise(vec2 pos, vec2 per, float rot) {\n // Offset y slightly to hide some rare artifacts\n pos.y += 0.001;\n // Skew to hexagonal grid\n vec2 uv = vec2(pos.x + pos.y*0.5, pos.y);\n\n vec2 i0 = floor(uv);\n vec2 f0 = fract(uv);\n // Traversal order\n vec2 i1 = (f0.x > f0.y) ? vec2(1.0, 0.0) : vec2(0.0, 1.0);\n\n // Unskewed grid points in (x,y) space\n vec2 p0 = vec2(i0.x - i0.y * 0.5, i0.y);\n vec2 p1 = vec2(p0.x + i1.x - i1.y * 0.5, p0.y + i1.y);\n vec2 p2 = vec2(p0.x + 0.5, p0.y + 1.0);\n\n // Integer grid point indices in (u,v) space\n i1 = i0 + i1;\n vec2 i2 = i0 + vec2(1.0, 1.0);\n\n // Vectors in unskewed (x,y) coordinates from\n // each of the simplex corners to the evaluation point\n vec2 d0 = pos - p0;\n vec2 d1 = pos - p1;\n vec2 d2 = pos - p2;\n\n // Wrap i0, i1 and i2 to the desired period before gradient hashing:\n // wrap points in (x,y), map to (u,v)\n vec3 xw = mod(vec3(p0.x, p1.x, p2.x), per.x);\n vec3 yw = mod(vec3(p0.y, p1.y, p2.y), per.y);\n vec3 iuw = xw + 0.5 * yw;\n vec3 ivw = yw;\n\n // Create gradients from indices\n vec2 g0 = rgrad2(vec2(iuw.x, ivw.x), rot);\n vec2 g1 = rgrad2(vec2(iuw.y, ivw.y), rot);\n vec2 g2 = rgrad2(vec2(iuw.z, ivw.z), rot);\n\n // Gradients dot vectors to corresponding corners\n // (The derivatives of this are simply the gradients)\n vec3 w = vec3(dot(g0, d0), dot(g1, d1), dot(g2, d2));\n\n // Radial weights from corners\n // 0.8 is the square of 2/sqrt(5), the distance from\n // a grid point to the nearest simplex boundary\n vec3 t = 0.8 - vec3(dot(d0, d0), dot(d1, d1), dot(d2, d2));\n\n // Set influence of each surflet to zero outside radius sqrt(0.8)\n t = max(t, 0.0);\n\n // Fourth power of t\n vec3 t2 = t * t;\n vec3 t4 = t2 * t2;\n\n // Final noise value is:\n // sum of ((radial weights) times (gradient dot vector from corner))\n float n = dot(t4, w);\n\n // Rescale to cover the range [-1,1] reasonably well\n return 11.0*n;\n}\n\n//\n// 2-D tiling simplex noise with fixed gradients,\n// without the analytical derivative.\n// This function is implemented as a wrapper to \"psrnoise\",\n// at the minimal cost of three extra additions.\n//\nfloat psnoise(vec2 pos, vec2 per) {\n return psrnoise(pos, per, 0.0);\n}\n\n//\n// 2-D non-tiling simplex noise with rotating gradients and analytical derivative.\n// The first component of the 3-element return vector is the noise value,\n// and the second and third components are the x and y partial derivatives.\n//\nvec3 srdnoise(vec2 pos, float rot) {\n // Offset y slightly to hide some rare artifacts\n pos.y += 0.001;\n // Skew to hexagonal grid\n vec2 uv = vec2(pos.x + pos.y*0.5, pos.y);\n\n vec2 i0 = floor(uv);\n vec2 f0 = fract(uv);\n // Traversal order\n vec2 i1 = (f0.x > f0.y) ? vec2(1.0, 0.0) : vec2(0.0, 1.0);\n\n // Unskewed grid points in (x,y) space\n vec2 p0 = vec2(i0.x - i0.y * 0.5, i0.y);\n vec2 p1 = vec2(p0.x + i1.x - i1.y * 0.5, p0.y + i1.y);\n vec2 p2 = vec2(p0.x + 0.5, p0.y + 1.0);\n\n // Integer grid point indices in (u,v) space\n i1 = i0 + i1;\n vec2 i2 = i0 + vec2(1.0, 1.0);\n\n // Vectors in unskewed (x,y) coordinates from\n // each of the simplex corners to the evaluation point\n vec2 d0 = pos - p0;\n vec2 d1 = pos - p1;\n vec2 d2 = pos - p2;\n\n vec3 x = vec3(p0.x, p1.x, p2.x);\n vec3 y = vec3(p0.y, p1.y, p2.y);\n vec3 iuw = x + 0.5 * y;\n vec3 ivw = y;\n\n // Avoid precision issues in permutation\n iuw = mod289(iuw);\n ivw = mod289(ivw);\n\n // Create gradients from indices\n vec2 g0 = rgrad2(vec2(iuw.x, ivw.x), rot);\n vec2 g1 = rgrad2(vec2(iuw.y, ivw.y), rot);\n vec2 g2 = rgrad2(vec2(iuw.z, ivw.z), rot);\n\n // Gradients dot vectors to corresponding corners\n // (The derivatives of this are simply the gradients)\n vec3 w = vec3(dot(g0, d0), dot(g1, d1), dot(g2, d2));\n\n // Radial weights from corners\n // 0.8 is the square of 2/sqrt(5), the distance from\n // a grid point to the nearest simplex boundary\n vec3 t = 0.8 - vec3(dot(d0, d0), dot(d1, d1), dot(d2, d2));\n\n // Partial derivatives for analytical gradient computation\n vec3 dtdx = -2.0 * vec3(d0.x, d1.x, d2.x);\n vec3 dtdy = -2.0 * vec3(d0.y, d1.y, d2.y);\n\n // Set influence of each surflet to zero outside radius sqrt(0.8)\n if (t.x < 0.0) {\n dtdx.x = 0.0;\n dtdy.x = 0.0;\n\tt.x = 0.0;\n }\n if (t.y < 0.0) {\n dtdx.y = 0.0;\n dtdy.y = 0.0;\n\tt.y = 0.0;\n }\n if (t.z < 0.0) {\n dtdx.z = 0.0;\n dtdy.z = 0.0;\n\tt.z = 0.0;\n }\n\n // Fourth power of t (and third power for derivative)\n vec3 t2 = t * t;\n vec3 t4 = t2 * t2;\n vec3 t3 = t2 * t;\n\n // Final noise value is:\n // sum of ((radial weights) times (gradient dot vector from corner))\n float n = dot(t4, w);\n\n // Final analytical derivative (gradient of a sum of scalar products)\n vec2 dt0 = vec2(dtdx.x, dtdy.x) * 4.0 * t3.x;\n vec2 dn0 = t4.x * g0 + dt0 * w.x;\n vec2 dt1 = vec2(dtdx.y, dtdy.y) * 4.0 * t3.y;\n vec2 dn1 = t4.y * g1 + dt1 * w.y;\n vec2 dt2 = vec2(dtdx.z, dtdy.z) * 4.0 * t3.z;\n vec2 dn2 = t4.z * g2 + dt2 * w.z;\n\n return 11.0*vec3(n, dn0 + dn1 + dn2);\n}\n\n//\n// 2-D non-tiling simplex noise with fixed gradients and analytical derivative.\n// This function is implemented as a wrapper to \"srdnoise\",\n// at the minimal cost of three extra additions.\n//\nvec3 sdnoise(vec2 pos) {\n return srdnoise(pos, 0.0);\n}\n\n//\n// 2-D non-tiling simplex noise with rotating gradients,\n// without the analytical derivative.\n//\nfloat srnoise(vec2 pos, float rot) {\n // Offset y slightly to hide some rare artifacts\n pos.y += 0.001;\n // Skew to hexagonal grid\n vec2 uv = vec2(pos.x + pos.y*0.5, pos.y);\n\n vec2 i0 = floor(uv);\n vec2 f0 = fract(uv);\n // Traversal order\n vec2 i1 = (f0.x > f0.y) ? vec2(1.0, 0.0) : vec2(0.0, 1.0);\n\n // Unskewed grid points in (x,y) space\n vec2 p0 = vec2(i0.x - i0.y * 0.5, i0.y);\n vec2 p1 = vec2(p0.x + i1.x - i1.y * 0.5, p0.y + i1.y);\n vec2 p2 = vec2(p0.x + 0.5, p0.y + 1.0);\n\n // Integer grid point indices in (u,v) space\n i1 = i0 + i1;\n vec2 i2 = i0 + vec2(1.0, 1.0);\n\n // Vectors in unskewed (x,y) coordinates from\n // each of the simplex corners to the evaluation point\n vec2 d0 = pos - p0;\n vec2 d1 = pos - p1;\n vec2 d2 = pos - p2;\n\n // Wrap i0, i1 and i2 to the desired period before gradient hashing:\n // wrap points in (x,y), map to (u,v)\n vec3 x = vec3(p0.x, p1.x, p2.x);\n vec3 y = vec3(p0.y, p1.y, p2.y);\n vec3 iuw = x + 0.5 * y;\n vec3 ivw = y;\n\n // Avoid precision issues in permutation\n iuw = mod289(iuw);\n ivw = mod289(ivw);\n\n // Create gradients from indices\n vec2 g0 = rgrad2(vec2(iuw.x, ivw.x), rot);\n vec2 g1 = rgrad2(vec2(iuw.y, ivw.y), rot);\n vec2 g2 = rgrad2(vec2(iuw.z, ivw.z), rot);\n\n // Gradients dot vectors to corresponding corners\n // (The derivatives of this are simply the gradients)\n vec3 w = vec3(dot(g0, d0), dot(g1, d1), dot(g2, d2));\n\n // Radial weights from corners\n // 0.8 is the square of 2/sqrt(5), the distance from\n // a grid point to the nearest simplex boundary\n vec3 t = 0.8 - vec3(dot(d0, d0), dot(d1, d1), dot(d2, d2));\n\n // Set influence of each surflet to zero outside radius sqrt(0.8)\n t = max(t, 0.0);\n\n // Fourth power of t\n vec3 t2 = t * t;\n vec3 t4 = t2 * t2;\n\n // Final noise value is:\n // sum of ((radial weights) times (gradient dot vector from corner))\n float n = dot(t4, w);\n\n // Rescale to cover the range [-1,1] reasonably well\n return 11.0*n;\n}\n\n//\n// 2-D non-tiling simplex noise with fixed gradients,\n// without the analytical derivative.\n// This function is implemented as a wrapper to \"srnoise\",\n// at the minimal cost of three extra additions.\n// Note: if this kind of noise is all you want, there are faster\n// GLSL implementations of non-tiling simplex noise out there.\n// This one is included mainly for completeness and compatibility\n// with the other functions in the file.\n//\nfloat snoise(vec2 pos) {\n return srnoise(pos, 0.0);\n}\n"; // eslint-disable-line
10451
+ var noise_simplex = "#include <noise_simplex_2D>\n#include <noise_simplex_3D>\n#include <noise_simplex_3D_grad>\n#include <noise_simplex_4D>\n"; // eslint-disable-line
10452
+ var noise_simplex_2D = "//\n// Description : Array and textureless GLSL 2D simplex noise function.\n// Author : Ian McEwan, Ashima Arts.\n// Maintainer : stegu\n// Lastmod : 20110822 (ijm)\n// License : Copyright (C) 2011 Ashima Arts. All rights reserved.\n// Distributed under the MIT License. See LICENSE file.\n// https://github.com/ashima/webgl-noise\n// https://github.com/stegu/webgl-noise\n//\n\nfloat simplex( vec2 v ) {\n\n const vec4 C = vec4( 0.211324865405187, // (3.0-sqrt(3.0))/6.0\n 0.366025403784439, // 0.5*(sqrt(3.0)-1.0)\n -0.577350269189626, // -1.0 + 2.0 * C.x\n 0.024390243902439 ); // 1.0 / 41.0\n // First corner\n vec2 i = floor( v + dot( v, C.yy ) );\n vec2 x0 = v - i + dot( i, C.xx );\n\n // Other corners\n vec2 i1;\n //i1.x = step( x0.y, x0.x ); // x0.x > x0.y ? 1.0 : 0.0\n //i1.y = 1.0 - i1.x;\n i1 = ( x0.x > x0.y ) ? vec2( 1.0, 0.0 ) : vec2( 0.0, 1.0 );\n // x0 = x0 - 0.0 + 0.0 * C.xx ;\n // x1 = x0 - i1 + 1.0 * C.xx ;\n // x2 = x0 - 1.0 + 2.0 * C.xx ;\n vec4 x12 = x0.xyxy + C.xxzz;\n x12.xy -= i1;\n\n // Permutations\n i = mod289( i ); // Avoid truncation effects in permutation\n vec3 p = permute( permute( i.y + vec3( 0.0, i1.y, 1.0 ) )\n + i.x + vec3( 0.0, i1.x, 1.0 ) );\n\n vec3 m = max( 0.5 - vec3( dot( x0, x0 ), dot( x12.xy, x12.xy ), dot( x12.zw, x12.zw ) ), 0.0 );\n m = m*m ;\n m = m*m ;\n\n // Gradients: 41 points uniformly over a line, mapped onto a diamond.\n // The ring size 17*17 = 289 is close to a multiple of 41 (41*7 = 287)\n\n vec3 x = 2.0 * fract( p * C.www ) - 1.0;\n vec3 h = abs( x ) - 0.5;\n vec3 ox = floor( x + 0.5 );\n vec3 a0 = x - ox;\n\n // Normalise gradients implicitly by scaling m\n // Approximation of: m *= inversesqrt( a0*a0 + h*h );\n m *= 1.79284291400159 - 0.85373472095314 * ( a0 * a0 + h * h );\n\n // Compute final noise value at P\n vec3 g;\n g.x = a0.x * x0.x + h.x * x0.y;\n g.yz = a0.yz * x12.xz + h.yz * x12.yw;\n return 130.0 * dot( m, g );\n\n}\n"; // eslint-disable-line
10453
+ var noise_simplex_3D = "//\n// Description : Array and textureless GLSL 2D/3D/4D simplex\n// noise functions.\n// Author : Ian McEwan, Ashima Arts.\n// Maintainer : stegu\n// Lastmod : 20110822 (ijm)\n// License : Copyright (C) 2011 Ashima Arts. All rights reserved.\n// Distributed under the MIT License. See LICENSE file.\n// https://github.com/ashima/webgl-noise\n// https://github.com/stegu/webgl-noise\n//\n\nfloat simplex( vec3 v ) {\n\n const vec2 C = vec2( 1.0 / 6.0, 1.0 / 3.0 );\n const vec4 D = vec4( 0.0, 0.5, 1.0, 2.0 );\n\n // First corner\n vec3 i = floor( v + dot( v, C.yyy ) );\n vec3 x0 = v - i + dot( i, C.xxx );\n\n // Other corners\n vec3 g = step( x0.yzx, x0.xyz );\n vec3 l = 1.0 - g;\n vec3 i1 = min( g.xyz, l.zxy );\n vec3 i2 = max( g.xyz, l.zxy );\n\n vec3 x1 = x0 - i1 + C.xxx;\n vec3 x2 = x0 - i2 + C.yyy; // 2.0*C.x = 1/3 = C.y\n vec3 x3 = x0 - D.yyy; // -1.0+3.0*C.x = -0.5 = -D.y\n\n // Permutations\n i = mod289( i );\n vec4 p = permute( permute( permute(\n i.z + vec4(0.0, i1.z, i2.z, 1.0 ))\n + i.y + vec4(0.0, i1.y, i2.y, 1.0 ))\n + i.x + vec4(0.0, i1.x, i2.x, 1.0 ));\n\n // Gradients: 7x7 points over a square, mapped onto an octahedron.\n // The ring size 17*17 = 289 is close to a multiple of 49 (49*6 = 294)\n float n_ = 0.142857142857; // 1.0/7.0\n vec3 ns = n_ * D.wyz - D.xzx;\n\n vec4 j = p - 49.0 * floor( p * ns.z * ns.z ); // mod(p,7*7)\n\n vec4 x_ = floor(j * ns.z);\n vec4 y_ = floor(j - 7.0 * x_ ); // mod(j,N)\n\n vec4 x = x_ *ns.x + ns.yyyy;\n vec4 y = y_ *ns.x + ns.yyyy;\n vec4 h = 1.0 - abs( x ) - abs( y );\n\n vec4 b0 = vec4( x.xy, y.xy );\n vec4 b1 = vec4( x.zw, y.zw );\n\n vec4 s0 = floor( b0 ) * 2.0 + 1.0;\n vec4 s1 = floor( b1 ) * 2.0 + 1.0;\n vec4 sh = - step( h, vec4( 0.0 ) );\n\n vec4 a0 = b0.xzyw + s0.xzyw * sh.xxyy ;\n vec4 a1 = b1.xzyw + s1.xzyw * sh.zzww ;\n\n vec3 p0 = vec3( a0.xy, h.x );\n vec3 p1 = vec3( a0.zw, h.y );\n vec3 p2 = vec3( a1.xy, h.z );\n vec3 p3 = vec3( a1.zw, h.w );\n\n //Normalise gradients\n vec4 norm = taylorInvSqrt( vec4( dot( p0, p0 ), dot( p1, p1 ), dot( p2, p2 ), dot( p3, p3 ) ) );\n p0 *= norm.x;\n p1 *= norm.y;\n p2 *= norm.z;\n p3 *= norm.w;\n\n // Mix final noise value\n vec4 m = max( 0.6 - vec4( dot( x0, x0 ), dot( x1, x1 ), dot( x2, x2 ), dot( x3, x3 ) ), 0.0 );\n m = m * m;\n return 42.0 * dot( m*m, vec4( dot( p0, x0 ), dot( p1, x1 ),\n dot( p2, x2 ), dot( p3, x3 ) ) );\n\n}\n"; // eslint-disable-line
10454
+ var noise_simplex_3D_grad = "//\n// Description : Array and textureless GLSL 2D/3D/4D simplex\n// noise functions.\n// Author : Ian McEwan, Ashima Arts.\n// Maintainer : stegu\n// Lastmod : 20150104 (JcBernack)\n// License : Copyright (C) 2011 Ashima Arts. All rights reserved.\n// Distributed under the MIT License. See LICENSE file.\n// https://github.com/ashima/webgl-noise\n// https://github.com/stegu/webgl-noise\n//\n\nfloat simplex( vec3 v, out vec3 gradient ) {\n\n const vec2 C = vec2( 1.0 / 6.0, 1.0 / 3.0 );\n const vec4 D = vec4( 0.0, 0.5, 1.0, 2.0 );\n\n // First corner\n vec3 i = floor( v + dot( v, C.yyy ) );\n vec3 x0 = v - i + dot( i, C.xxx ) ;\n\n // Other corners\n vec3 g = step( x0.yzx, x0.xyz );\n vec3 l = 1.0 - g;\n vec3 i1 = min( g.xyz, l.zxy );\n vec3 i2 = max( g.xyz, l.zxy );\n\n vec3 x1 = x0 - i1 + C.xxx;\n vec3 x2 = x0 - i2 + C.yyy; // 2.0*C.x = 1/3 = C.y\n vec3 x3 = x0 - D.yyy; // -1.0+3.0*C.x = -0.5 = -D.y\n\n // Permutations\n i = mod289( i );\n vec4 p = permute( permute( permute(\n i.z + vec4( 0.0, i1.z, i2.z, 1.0 ) )\n + i.y + vec4( 0.0, i1.y, i2.y, 1.0 ) )\n + i.x + vec4( 0.0, i1.x, i2.x, 1.0 ) );\n\n // Gradients: 7x7 points over a square, mapped onto an octahedron.\n // The ring size 17*17 = 289 is close to a multiple of 49 (49*6 = 294)\n float n_ = 0.142857142857; // 1.0/7.0\n vec3 ns = n_ * D.wyz - D.xzx;\n\n vec4 j = p - 49.0 * floor(p * ns.z * ns.z); // mod(p,7*7)\n\n vec4 x_ = floor(j * ns.z);\n vec4 y_ = floor(j - 7.0 * x_ ); // mod(j,N)\n\n vec4 x = x_ * ns.x + ns.yyyy;\n vec4 y = y_ * ns.x + ns.yyyy;\n vec4 h = 1.0 - abs( x ) - abs( y );\n\n vec4 b0 = vec4( x.xy, y.xy );\n vec4 b1 = vec4( x.zw, y.zw );\n\n vec4 s0 = floor( b0 ) * 2.0 + 1.0;\n vec4 s1 = floor( b1 ) * 2.0 + 1.0;\n vec4 sh = - step( h, vec4( 0.0 ) );\n\n vec4 a0 = b0.xzyw + s0.xzyw * sh.xxyy ;\n vec4 a1 = b1.xzyw + s1.xzyw * sh.zzww ;\n\n vec3 p0 = vec3( a0.xy, h.x );\n vec3 p1 = vec3( a0.zw, h.y );\n vec3 p2 = vec3( a1.xy, h.z );\n vec3 p3 = vec3( a1.zw, h.w );\n\n //Normalise gradients\n vec4 norm = taylorInvSqrt( vec4( dot( p0, p0 ), dot( p1, p1 ), dot( p2, p2 ), dot( p3, p3 ) ) );\n p0 *= norm.x;\n p1 *= norm.y;\n p2 *= norm.z;\n p3 *= norm.w;\n\n // Mix final noise value\n vec4 m = max( 0.6 - vec4( dot( x0, x0 ), dot( x1, x1 ), dot( x2, x2 ), dot( x3, x3 ) ), 0.0 );\n vec4 m2 = m * m;\n vec4 m4 = m2 * m2;\n vec4 pdotx = vec4( dot( p0, x0 ), dot( p1, x1 ), dot( p2, x2 ), dot( p3, x3 ) );\n\n // Determine noise gradient\n vec4 temp = m2 * m * pdotx;\n gradient = - 8.0 * ( temp.x * x0 + temp.y * x1 + temp.z * x2 + temp.w * x3 );\n gradient += m4.x * p0 + m4.y * p1 + m4.z * p2 + m4.w * p3;\n gradient *= 42.0;\n\n return 42.0 * dot( m4, pdotx );\n\n}\n"; // eslint-disable-line
10455
+ var noise_simplex_4D = "//\n// Description : Array and textureless GLSL 2D/3D/4D simplex\n// noise functions.\n// Author : Ian McEwan, Ashima Arts.\n// Maintainer : stegu\n// Lastmod : 20110822 (ijm)\n// License : Copyright (C) 2011 Ashima Arts. All rights reserved.\n// Distributed under the MIT License. See LICENSE file.\n// https://github.com/ashima/webgl-noise\n// https://github.com/stegu/webgl-noise\n//\n\nvec4 grad4( float j, vec4 ip ) {\n\n const vec4 ones = vec4( 1.0, 1.0, 1.0, -1.0 );\n vec4 p, s;\n\n p.xyz = floor( fract( vec3( j ) * ip.xyz ) * 7.0 ) * ip.z - 1.0;\n p.w = 1.5 - dot( abs( p.xyz ), ones.xyz );\n s = vec4( lessThan( p, vec4( 0.0 ) ) );\n p.xyz = p.xyz + ( s.xyz * 2.0 - 1.0 ) * s.www;\n\n return p;\n\n}\n\n// (sqrt(5) - 1)/4 = F4, used once below\n#define F4 0.309016994374947451\n\nfloat simplex(vec4 v) {\n\n const vec4 C = vec4( 0.138196601125011, // (5 - sqrt(5))/20 G4\n 0.276393202250021, // 2 * G4\n 0.414589803375032, // 3 * G4\n -0.447213595499958); // -1 + 4 * G4\n\n // First corner\n vec4 i = floor( v + dot( v, vec4( F4 ) ) );\n vec4 x0 = v - i + dot( i, C.xxxx );\n\n // Other corners\n\n // Rank sorting originally contributed by Bill Licea-Kane, AMD (formerly ATI)\n vec4 i0;\n vec3 isX = step( x0.yzw, x0.xxx );\n vec3 isYZ = step( x0.zww, x0.yyz );\n i0.x = isX.x + isX.y + isX.z;\n i0.yzw = 1.0 - isX;\n i0.y += isYZ.x + isYZ.y;\n i0.zw += 1.0 - isYZ.xy;\n i0.z += isYZ.z;\n i0.w += 1.0 - isYZ.z;\n\n vec4 i3 = clamp( i0, 0.0, 1.0 );\n vec4 i2 = clamp( i0 - 1.0, 0.0, 1.0 );\n vec4 i1 = clamp( i0 - 2.0, 0.0, 1.0 );\n\n vec4 x1 = x0 - i1 + C.xxxx;\n vec4 x2 = x0 - i2 + C.yyyy;\n vec4 x3 = x0 - i3 + C.zzzz;\n vec4 x4 = x0 + C.wwww;\n\n // Permutations\n i = mod289( i );\n float j0 = permute( permute( permute( permute( i.w ) + i.z ) + i.y ) + i.x );\n vec4 j1 = permute( permute( permute( permute (\n i.w + vec4(i1.w, i2.w, i3.w, 1.0 ))\n + i.z + vec4(i1.z, i2.z, i3.z, 1.0 ))\n + i.y + vec4(i1.y, i2.y, i3.y, 1.0 ))\n + i.x + vec4(i1.x, i2.x, i3.x, 1.0 ));\n\n // Gradients: 7x7x6 points over a cube, mapped onto a 4-cross polytope\n // 7*7*6 = 294, which is close to the ring size 17*17 = 289.\n vec4 ip = vec4( 1.0 / 294.0, 1.0 / 49.0, 1.0 / 7.0, 0.0 );\n\n vec4 p0 = grad4(j0, ip);\n vec4 p1 = grad4(j1.x, ip);\n vec4 p2 = grad4(j1.y, ip);\n vec4 p3 = grad4(j1.z, ip);\n vec4 p4 = grad4(j1.w, ip);\n\n // Normalise gradients\n vec4 norm = taylorInvSqrt( vec4( dot( p0, p0 ), dot( p1, p1 ), dot( p2, p2 ), dot( p3, p3 ) ) );\n p0 *= norm.x;\n p1 *= norm.y;\n p2 *= norm.z;\n p3 *= norm.w;\n p4 *= taylorInvSqrt( dot( p4, p4 ) );\n\n // Mix contributions from the five corners\n vec3 m0 = max( 0.6 - vec3( dot( x0, x0 ), dot( x1, x1 ), dot( x2, x2 ) ), 0.0 );\n vec2 m1 = max( 0.6 - vec2( dot( x3, x3 ), dot( x4, x4 ) ), 0.0 );\n m0 = m0 * m0;\n m1 = m1 * m1;\n return 49.0 * ( dot(m0*m0, vec3( dot( p0, x0 ), dot( p1, x1 ), dot( p2, x2 )))\n + dot(m1*m1, vec2( dot( p3, x3 ), dot( p4, x4 ) ) ) ) ;\n\n}\n"; // eslint-disable-line
10442
10456
  var pbr_frag_define = "#define MIN_PERCEPTUAL_ROUGHNESS 0.045\n#define MIN_ROUGHNESS 0.002025\n\nuniform float material_AlphaCutoff;\nuniform vec4 material_BaseColor;\nuniform float material_Metal;\nuniform float material_Roughness;\nuniform float material_IOR;\nuniform vec3 material_EmissiveColor;\nuniform float material_NormalIntensity;\nuniform float material_OcclusionIntensity;\nuniform float material_OcclusionTextureCoord;\nuniform float material_SpecularIntensity;\nuniform vec3 material_SpecularColor;\n\n#ifdef MATERIAL_ENABLE_CLEAR_COAT\n uniform float material_ClearCoat;\n uniform float material_ClearCoatRoughness;\n\n #ifdef MATERIAL_HAS_CLEAR_COAT_TEXTURE\n uniform sampler2D material_ClearCoatTexture;\n #endif\n\n #ifdef MATERIAL_HAS_CLEAR_COAT_ROUGHNESS_TEXTURE\n uniform sampler2D material_ClearCoatRoughnessTexture;\n #endif\n\n #ifdef MATERIAL_HAS_CLEAR_COAT_NORMAL_TEXTURE\n uniform sampler2D material_ClearCoatNormalTexture;\n #endif\n#endif\n\n#ifdef MATERIAL_ENABLE_ANISOTROPY\n uniform vec3 material_AnisotropyInfo;\n #ifdef MATERIAL_HAS_ANISOTROPY_TEXTURE\n uniform sampler2D material_AnisotropyTexture;\n #endif\n#endif\n\n// Texture\n#ifdef MATERIAL_HAS_BASETEXTURE\n uniform sampler2D material_BaseTexture;\n#endif\n\n#ifdef MATERIAL_HAS_NORMALTEXTURE\n uniform sampler2D material_NormalTexture;\n#endif\n\n#ifdef MATERIAL_HAS_EMISSIVETEXTURE\n uniform sampler2D material_EmissiveTexture;\n#endif\n\n#ifdef MATERIAL_HAS_ROUGHNESS_METALLIC_TEXTURE\n uniform sampler2D material_RoughnessMetallicTexture;\n#endif\n\n#ifdef MATERIAL_HAS_SPECULAR_TEXTURE\n uniform sampler2D material_SpecularIntensityTexture;\n#endif\n\n#ifdef MATERIAL_HAS_SPECULAR_COLOR_TEXTURE\n uniform sampler2D material_SpecularColorTexture;\n#endif\n\n#ifdef MATERIAL_HAS_OCCLUSION_TEXTURE\n uniform sampler2D material_OcclusionTexture;\n#endif\n\n\n#ifdef MATERIAL_ENABLE_SHEEN\n uniform float material_SheenRoughness;\n uniform vec3 material_SheenColor;\n #ifdef MATERIAL_HAS_SHEEN_TEXTURE\n uniform sampler2D material_SheenTexture;\n #endif\n\n #ifdef MATERIAL_HAS_SHEEN_ROUGHNESS_TEXTURE\n uniform sampler2D material_SheenRoughnessTexture;\n #endif\n#endif\n\n\n#ifdef MATERIAL_ENABLE_IRIDESCENCE\n uniform vec4 material_IridescenceInfo;\n #ifdef MATERIAL_HAS_IRIDESCENCE_THICKNESS_TEXTURE\n uniform sampler2D material_IridescenceThicknessTexture;\n #endif\n\n #ifdef MATERIAL_HAS_IRIDESCENCE_TEXTURE\n uniform sampler2D material_IridescenceTexture;\n #endif\n#endif\n\n#ifdef MATERIAL_ENABLE_TRANSMISSION\n uniform float material_Transmission;\n #ifdef MATERIAL_HAS_TRANSMISSION_TEXTURE\n uniform sampler2D material_TransmissionTexture;\n #endif\n\n #ifdef MATERIAL_HAS_THICKNESS\n uniform vec3 material_AttenuationColor;\n uniform float material_AttenuationDistance;\n uniform float material_Thickness;\n\n #ifdef MATERIAL_HAS_THICKNESS_TEXTURE\n uniform sampler2D material_ThicknessTexture;\n #endif\n #endif\n#endif\n\n// Runtime\nstruct ReflectedLight {\n vec3 directDiffuse;\n vec3 directSpecular;\n vec3 indirectDiffuse;\n vec3 indirectSpecular;\n};\n\nstruct Geometry {\n vec3 position;\n vec3 normal;\n vec3 viewDir;\n float dotNV;\n \n #ifdef MATERIAL_ENABLE_CLEAR_COAT\n vec3 clearCoatNormal;\n float clearCoatDotNV;\n #endif\n\n #ifdef MATERIAL_ENABLE_ANISOTROPY\n vec3 anisotropicT;\n vec3 anisotropicB;\n vec3 anisotropicN;\n float anisotropy;\n #endif\n};\n\nstruct Material {\n vec3 diffuseColor;\n float roughness;\n vec3 specularF0;\n vec3 resolvedSpecularF0;\n float specularF90;\n float specularIntensity;\n vec3 specularColor;\n float opacity;\n float diffuseAO;\n float specularAO;\n vec3 envSpecularDFG;\n vec3 energyCompensation; // Multi-scattering energy compensation factor\n float IOR;\n\n #ifdef MATERIAL_ENABLE_CLEAR_COAT\n float clearCoat;\n float clearCoatRoughness;\n #endif\n\n #ifdef MATERIAL_ENABLE_IRIDESCENCE\n float iridescenceIOR;\n float iridescenceFactor;\n float iridescenceThickness;\n vec3 iridescenceSpecularColor;\n #endif\n\n #ifdef MATERIAL_ENABLE_SHEEN\n float sheenRoughness;\n vec3 sheenColor;\n float sheenScaling;\n float approxIBLSheenDG;\n #endif\n\n #ifdef MATERIAL_ENABLE_TRANSMISSION \n vec3 absorptionCoefficient;\n float transmission;\n float thickness;\n #endif\n};\n"; // eslint-disable-line
10443
10457
  var pbr_helper = "#include <normal_get>\n#include <brdf>\n#include <btdf>\n\n// direct + indirect\n#include <direct_irradiance_frag_define>\n#include <ibl_frag_define>\n\nuniform sampler2D camera_AOTexture;\n\nfloat evaluateAmbientOcclusion(vec2 uv)\n{\n #ifdef MATERIAL_IS_TRANSPARENT\n return 1.0;\n #else\n return texture2D(camera_AOTexture, uv).r;\n #endif\n}\n\n\nfloat computeSpecularOcclusion(float ambientOcclusion, float roughness, float dotNV ) {\n return saturate( pow( dotNV + ambientOcclusion, exp2( - 16.0 * roughness - 1.0 ) ) - 1.0 + ambientOcclusion );\n}\n\nfloat getAARoughnessFactor(vec3 normal) {\n // Kaplanyan 2016, \"Stable specular highlights\"\n // Tokuyoshi 2017, \"Error Reduction and Simplification for Shading Anti-Aliasing\"\n // Tokuyoshi and Kaplanyan 2019, \"Improved Geometric Specular Antialiasing\"\n #ifdef HAS_DERIVATIVES\n vec3 dxy = max( abs(dFdx(normal)), abs(dFdy(normal)) );\n return max( max(dxy.x, dxy.y), dxy.z );\n #else\n return 0.0;\n #endif\n}\n\n#ifdef MATERIAL_ENABLE_ANISOTROPY\n // Aniso Bent Normals\n // Mc Alley https://www.gdcvault.com/play/1022235/Rendering-the-World-of-Far \n vec3 getAnisotropicBentNormal(Geometry geometry, vec3 n, float roughness) {\n vec3 anisotropyDirection = geometry.anisotropy >= 0.0 ? geometry.anisotropicB : geometry.anisotropicT;\n vec3 anisotropicTangent = cross(anisotropyDirection, geometry.viewDir);\n vec3 anisotropicNormal = cross(anisotropicTangent, anisotropyDirection);\n // reduce stretching for (roughness < 0.2), refer to https://advances.realtimerendering.com/s2018/Siggraph%202018%20HDRP%20talk_with%20notes.pdf 80\n vec3 bentNormal = normalize( mix(n, anisotropicNormal, abs(geometry.anisotropy) * saturate( 5.0 * roughness)) );\n\n return bentNormal;\n }\n#endif\n\nvoid initGeometry(out Geometry geometry, bool isFrontFacing){\n geometry.position = v_pos;\n #ifdef CAMERA_ORTHOGRAPHIC\n geometry.viewDir = -camera_Forward;\n #else\n geometry.viewDir = normalize(camera_Position - v_pos);\n #endif\n #if defined(MATERIAL_HAS_NORMALTEXTURE) || defined(MATERIAL_HAS_CLEAR_COAT_NORMAL_TEXTURE) || defined(MATERIAL_ENABLE_ANISOTROPY)\n mat3 tbn = getTBN(isFrontFacing);\n #endif\n\n #ifdef MATERIAL_HAS_NORMALTEXTURE\n geometry.normal = getNormalByNormalTexture(tbn, material_NormalTexture, material_NormalIntensity, v_uv, isFrontFacing);\n #else\n geometry.normal = getNormal(isFrontFacing);\n #endif\n\n geometry.dotNV = saturate( dot(geometry.normal, geometry.viewDir) );\n\n\n #ifdef MATERIAL_ENABLE_CLEAR_COAT\n #ifdef MATERIAL_HAS_CLEAR_COAT_NORMAL_TEXTURE\n geometry.clearCoatNormal = getNormalByNormalTexture(tbn, material_ClearCoatNormalTexture, material_NormalIntensity, v_uv, isFrontFacing);\n #else\n geometry.clearCoatNormal = getNormal(isFrontFacing);\n #endif\n geometry.clearCoatDotNV = saturate( dot(geometry.clearCoatNormal, geometry.viewDir) );\n #endif\n\n #ifdef MATERIAL_ENABLE_ANISOTROPY\n float anisotropy = material_AnisotropyInfo.z;\n vec3 anisotropicDirection = vec3(material_AnisotropyInfo.xy, 0.0);\n #ifdef MATERIAL_HAS_ANISOTROPY_TEXTURE\n vec3 anisotropyTextureInfo = texture2D( material_AnisotropyTexture, v_uv ).rgb;\n anisotropy *= anisotropyTextureInfo.b;\n anisotropicDirection.xy *= anisotropyTextureInfo.rg * 2.0 - 1.0;\n #endif\n\n geometry.anisotropy = anisotropy;\n geometry.anisotropicT = normalize(tbn * anisotropicDirection);\n geometry.anisotropicB = normalize(cross(geometry.normal, geometry.anisotropicT));\n #endif\n}\n\nvoid initMaterial(out Material material, inout Geometry geometry){\n vec4 baseColor = material_BaseColor;\n float metal = material_Metal;\n float roughness = material_Roughness;\n float alphaCutoff = material_AlphaCutoff;\n material.IOR = material_IOR;\n\n #ifdef MATERIAL_HAS_BASETEXTURE\n baseColor *= texture2DSRGB(material_BaseTexture, v_uv);\n #endif\n\n #ifdef RENDERER_ENABLE_VERTEXCOLOR\n baseColor *= v_color;\n #endif\n\n\n #ifdef MATERIAL_IS_ALPHA_CUTOFF\n if( baseColor.a < alphaCutoff ) {\n discard;\n }\n #endif\n\n #ifdef MATERIAL_HAS_ROUGHNESS_METALLIC_TEXTURE\n vec4 metalRoughMapColor = texture2D( material_RoughnessMetallicTexture, v_uv );\n roughness *= metalRoughMapColor.g;\n metal *= metalRoughMapColor.b;\n #endif\n\n // Specular\n material.specularIntensity = material_SpecularIntensity;\n material.specularColor = material_SpecularColor;\n #ifdef MATERIAL_HAS_SPECULAR_TEXTURE\n material.specularIntensity *= texture2D( material_SpecularIntensityTexture, v_uv ).a;\n #endif\n\n #ifdef MATERIAL_ENABLE_CLEAR_COAT\n material.clearCoat = material_ClearCoat;\n material.clearCoatRoughness = material_ClearCoatRoughness;\n #ifdef MATERIAL_HAS_CLEAR_COAT_TEXTURE\n material.clearCoat *= texture2D( material_ClearCoatTexture, v_uv ).r;\n #endif\n #ifdef MATERIAL_HAS_CLEAR_COAT_ROUGHNESS_TEXTURE\n material.clearCoatRoughness *= texture2D( material_ClearCoatRoughnessTexture, v_uv ).g;\n #endif\n material.clearCoat = saturate( material.clearCoat );\n material.clearCoatRoughness = max(MIN_PERCEPTUAL_ROUGHNESS, min(material.clearCoatRoughness + getAARoughnessFactor(geometry.clearCoatNormal), 1.0));\n #endif\n\n #ifdef MATERIAL_IS_TRANSPARENT\n material.opacity = baseColor.a;\n #else\n material.opacity = 1.0;\n #endif\n\n material.roughness = max(MIN_PERCEPTUAL_ROUGHNESS, min(roughness + getAARoughnessFactor(geometry.normal), 1.0));\n\n #ifdef MATERIAL_ENABLE_ANISOTROPY\n geometry.anisotropicN = getAnisotropicBentNormal(geometry, geometry.normal, material.roughness);\n #endif\n\n vec3 dielectricBaseF0 = vec3(pow2( (material.IOR - 1.0) / (material.IOR + 1.0) ));\n vec3 dielectricF0 = min(dielectricBaseF0 * material.specularColor , vec3(1.0)) * material.specularIntensity;\n float dielectricF90 = material.specularIntensity; \n\n material.specularF0 = mix(dielectricF0, baseColor.rgb, metal);\n material.specularF90 = mix(dielectricF90, 1.0, metal);\n material.resolvedSpecularF0 = material.specularF0;\n\n // Simplify: albedoColor * mix((1.0 - max(max(dielectricF0.r,dielectricF0.g),dielectricF0.b)), 0.0, metallic);\n material.diffuseColor = baseColor.rgb * (1.0 - metal) * (1.0 - max(max(dielectricF0.r,dielectricF0.g),dielectricF0.b));\n // Environment BRDF\n vec2 dfg = envDFGApprox(material.roughness, geometry.dotNV);\n\n // AO\n float diffuseAO = 1.0;\n float specularAO = 1.0;\n\n #ifdef MATERIAL_HAS_OCCLUSION_TEXTURE\n vec2 aoUV = v_uv;\n #ifdef RENDERER_HAS_UV1\n if(material_OcclusionTextureCoord == 1.0){\n aoUV = v_uv1;\n }\n #endif\n diffuseAO = ((texture2D(material_OcclusionTexture, aoUV)).r - 1.0) * material_OcclusionIntensity + 1.0;\n #endif\n\n #ifdef SCENE_ENABLE_AMBIENT_OCCLUSION\n float ambientAO = evaluateAmbientOcclusion((v_PositionCS.xy / v_PositionCS.w) * 0.5 + 0.5);\n diffuseAO = min(diffuseAO, ambientAO);\n #endif\n\n #if (defined(MATERIAL_HAS_OCCLUSION_TEXTURE) || defined(SCENE_ENABLE_AMBIENT_OCCLUSION))&& defined(SCENE_USE_SPECULAR_ENV) \n specularAO = saturate( pow( geometry.dotNV + diffuseAO, exp2( - 16.0 * material.roughness - 1.0 ) ) - 1.0 + diffuseAO );\n #endif\n\n material.diffuseAO = diffuseAO;\n material.specularAO = specularAO;\n\n // Sheen\n #ifdef MATERIAL_ENABLE_SHEEN\n vec3 sheenColor = material_SheenColor;\n #ifdef MATERIAL_HAS_SHEEN_TEXTURE\n sheenColor *= texture2DSRGB(material_SheenTexture, v_uv).rgb;\n #endif\n material.sheenColor = sheenColor;\n\n material.sheenRoughness = material_SheenRoughness;\n #ifdef MATERIAL_HAS_SHEEN_ROUGHNESS_TEXTURE\n material.sheenRoughness *= texture2D(material_SheenRoughnessTexture, v_uv).a;\n #endif\n\n material.sheenRoughness = max(MIN_PERCEPTUAL_ROUGHNESS, min(material.sheenRoughness + getAARoughnessFactor(geometry.normal), 1.0));\n material.approxIBLSheenDG = prefilteredSheenDFG(geometry.dotNV, material.sheenRoughness);\n material.sheenScaling = 1.0 - material.approxIBLSheenDG * max(max(material.sheenColor.r, material.sheenColor.g), material.sheenColor.b);\n #endif\n\n // Iridescence\n #ifdef MATERIAL_ENABLE_IRIDESCENCE\n material.iridescenceFactor = material_IridescenceInfo.x;\n material.iridescenceIOR = material_IridescenceInfo.y;\n\n #ifdef MATERIAL_HAS_IRIDESCENCE_THICKNESS_TEXTURE\n float iridescenceThicknessWeight = texture2D( material_IridescenceThicknessTexture, v_uv).g;\n material.iridescenceThickness = mix(material_IridescenceInfo.z, material_IridescenceInfo.w, iridescenceThicknessWeight);\n #else\n material.iridescenceThickness = material_IridescenceInfo.w;\n #endif\n\n #ifdef MATERIAL_HAS_IRIDESCENCE_TEXTURE\n material.iridescenceFactor *= texture2D( material_IridescenceTexture, v_uv).r;\n #endif\n \n #ifdef MATERIAL_ENABLE_IRIDESCENCE\n float topIOR = 1.0;\n material.iridescenceSpecularColor = evalIridescenceSpecular(topIOR, geometry.dotNV, material.iridescenceIOR, material.specularF0, material.specularF90, material.iridescenceThickness);\n material.resolvedSpecularF0 = mix(material.resolvedSpecularF0, material.iridescenceSpecularColor, material.iridescenceFactor);\n #endif\n #endif\n\n material.envSpecularDFG = material.resolvedSpecularF0 * dfg.x + material.specularF90 * dfg.y;\n\n // Multi-scattering energy compensation\n // Ref: Kulla & Conty 2017, \"Revisiting Physically Based Shading at Imageworks\"\n // Ref: Lagarde & Golubev 2018, simplified multiplier approach\n material.energyCompensation = 1.0 + material.resolvedSpecularF0 * (1.0 / max(dfg.x + dfg.y, EPSILON) - 1.0);\n\n // Transmission\n #ifdef MATERIAL_ENABLE_TRANSMISSION \n material.transmission = material_Transmission;\n #ifdef MATERIAL_HAS_TRANSMISSION_TEXTURE\n material.transmission *= texture2D(material_TransmissionTexture, v_uv).r;\n #endif\n\n #ifdef MATERIAL_HAS_THICKNESS\n material.absorptionCoefficient = -log(material_AttenuationColor + HALF_EPS) / max(HALF_EPS, material_AttenuationDistance);\n material.thickness = max(material_Thickness, 0.0001);\n #ifdef MATERIAL_HAS_THICKNESS_TEXTURE\n material.thickness *= texture2D( material_ThicknessTexture, v_uv).g;\n #endif\n #endif \n #endif\n}\n\n"; // eslint-disable-line
10444
10458
  var brdf = "\n#ifdef MATERIAL_ENABLE_SHEEN\n uniform sampler2D scene_PrefilteredDFG;\n#endif\n\nfloat F_Schlick(float f0, float f90, float dotLH) {\n\treturn f0 + (f90 - f0) * (pow(1.0 - dotLH, 5.0));\n}\n\nvec3 F_Schlick(vec3 f0, float f90, float dotLH ) {\n\n\t// Original approximation by Christophe Schlick '94\n\t// float fresnel = pow( 1.0 - dotLH, 5.0 );\n\n\t// Optimized variant (presented by Epic at SIGGRAPH '13)\n\t// https://cdn2.unrealengine.com/Resources/files/2013SiggraphPresentationsNotes-26915738.pdf\n\tfloat fresnel = exp2( ( -5.55473 * dotLH - 6.98316 ) * dotLH );\n\n\treturn (f90 - f0 ) * fresnel + f0;\n\n}\n\n// Moving Frostbite to Physically Based Rendering 3.0 - page 12, listing 2\n// https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf\nfloat G_GGX_SmithCorrelated(float alpha, float dotNL, float dotNV ) {\n\n\tfloat a2 = pow2( alpha );\n\n\t// dotNL and dotNV are explicitly swapped. This is not a mistake.\n\tfloat gv = dotNL * sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNV ) );\n\tfloat gl = dotNV * sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNL ) );\n\n\treturn 0.5 / max( gv + gl, EPSILON );\n\n}\n\n#ifdef MATERIAL_ENABLE_ANISOTROPY\n // Heitz 2014, \"Understanding the Masking-Shadowing Function in Microfacet-Based BRDFs\"\n // Heitz http://jcgt.org/published/0003/02/03/paper.pdf\n float G_GGX_SmithCorrelated_Anisotropic(float at, float ab, float ToV, float BoV, float ToL, float BoL, float NoV, float NoL) {\n float lambdaV = NoL * length(vec3(at * ToV, ab * BoV, NoV));\n float lambdaL = NoV * length(vec3(at * ToL, ab * BoL, NoL));\n return 0.5 / max(lambdaV + lambdaL, EPSILON);\n }\n#endif\n\n// Microfacet Models for Refraction through Rough Surfaces - equation (33)\n// http://graphicrants.blogspot.com/2013/08/specular-brdf-reference.html\n// alpha is \"roughness squared\" in Disney’s reparameterization\nfloat D_GGX(float alpha, float dotNH ) {\n\n\tfloat a2 = pow2( alpha );\n\n\tfloat denom = pow2( dotNH ) * ( a2 - 1.0 ) + 1.0; // avoid alpha = 0 with dotNH = 1\n\n\treturn RECIPROCAL_PI * a2 / pow2( denom );\n\n}\n\n#ifdef MATERIAL_ENABLE_SHEEN\n // http://www.aconty.com/pdf/s2017_pbs_imageworks_sheen.pdf\n float D_Charlie(float roughness, float dotNH) {\n float invAlpha = 1.0 / roughness;\n float cos2h = dotNH * dotNH;\n float sin2h = max(1.0 - cos2h, 0.0078125); // 2^(-14/2), so sin2h^2 > 0 in fp16\n return (2.0 + invAlpha) * pow(sin2h, invAlpha * 0.5) / (2.0 * PI);\n }\n\n // Neubelt and Pettineo 2013, \"Crafting a Next-gen Material Pipeline for The Order: 1886\".\n float V_Neubelt(float NoV, float NoL) {\n return saturate(1.0 / (4.0 * (NoL + NoV - NoL * NoV)));\n }\n\n vec3 sheenBRDF(vec3 incidentDirection, Geometry geometry, vec3 sheenColor, float sheenRoughness) {\n vec3 halfDir = normalize(incidentDirection + geometry.viewDir);\n float dotNL = saturate(dot(geometry.normal, incidentDirection));\n float dotNH = saturate(dot(geometry.normal, halfDir));\n float D = D_Charlie(sheenRoughness, dotNH);\n float V = V_Neubelt(geometry.dotNV, dotNL);\n vec3 F = sheenColor;\n return D * V * F;\n }\n\n float prefilteredSheenDFG(float dotNV, float sheenRoughness) {\n #ifdef HAS_TEX_LOD\n return texture2DLodEXT(scene_PrefilteredDFG, vec2(dotNV, sheenRoughness), 0.0).b;\n #else\n return texture2D(scene_PrefilteredDFG, vec2(dotNV, sheenRoughness),0.0).b;\n #endif \n }\n#endif\n\n#ifdef MATERIAL_ENABLE_ANISOTROPY\n // GGX Distribution Anisotropic\n // https://blog.selfshadow.com/publications/s2012-shading-course/burley/s2012_pbs_disney_brdf_notes_v3.pdf Addenda\n float D_GGX_Anisotropic(float at, float ab, float ToH, float BoH, float NoH) {\n float a2 = at * ab;\n vec3 d = vec3(ab * ToH, at * BoH, a2 * NoH);\n float d2 = dot(d, d);\n float b2 = a2 / d2;\n return a2 * b2 * b2 * RECIPROCAL_PI;\n }\n#endif\n\nfloat DG_GGX(float alpha, float dotNV, float dotNL, float dotNH) {\n\tfloat D = D_GGX( alpha, dotNH );\n\tfloat G = G_GGX_SmithCorrelated( alpha, dotNL, dotNV );\n return G * D;\n}\n\n#ifdef MATERIAL_ENABLE_ANISOTROPY\n float DG_GGX_anisotropic(vec3 h, vec3 l, Geometry geometry, float alpha, float dotNV, float dotNL, float dotNH) {\n vec3 t = geometry.anisotropicT;\n vec3 b = geometry.anisotropicB;\n vec3 v = geometry.viewDir;\n\n float dotTV = dot(t, v);\n float dotBV = dot(b, v);\n float dotTL = dot(t, l);\n float dotBL = dot(b, l);\n float dotTH = dot(t, h);\n float dotBH = dot(b, h);\n\n // Aniso parameter remapping\n // https://blog.selfshadow.com/publications/s2017-shading-course/imageworks/s2017_pbs_imageworks_slides_v2.pdf page 24\n float at = max(alpha * (1.0 + geometry.anisotropy), MIN_ROUGHNESS);\n float ab = max(alpha * (1.0 - geometry.anisotropy), MIN_ROUGHNESS);\n\n // specular anisotropic BRDF\n float D = D_GGX_Anisotropic(at, ab, dotTH, dotBH, dotNH);\n float G = G_GGX_SmithCorrelated_Anisotropic(at, ab, dotTV, dotBV, dotTL, dotBL, dotNV, dotNL);\n\n return G * D;\n }\n#endif\n\n#ifdef MATERIAL_ENABLE_IRIDESCENCE\n vec3 iorToFresnel0(vec3 transmittedIOR, float incidentIOR) {\n return pow((transmittedIOR - incidentIOR) / (transmittedIOR + incidentIOR),vec3(2.0));\n } \n\n float iorToFresnel0(float transmittedIOR, float incidentIOR) {\n return pow((transmittedIOR - incidentIOR) / (transmittedIOR + incidentIOR),2.0);\n } \n\n // Assume air interface for top\n // Note: We don't handle the case fresnel0 == 1\n vec3 fresnelToIOR(vec3 f0){\n vec3 sqrtF0 = sqrt(f0);\n return (vec3(1.0) + sqrtF0) / (vec3(1.0) - sqrtF0);\n }\n\n // Fresnel equations for dielectric/dielectric interfaces.\n // Ref: https://belcour.github.io/blog/research/publication/2017/05/01/brdf-thin-film.html\n // Evaluation XYZ sensitivity curves in Fourier space\n vec3 evalSensitivity(float opd, vec3 shift){\n // Use Gaussian fits, given by 3 parameters: val, pos and var\n float phase = 2.0 * PI * opd * 1.0e-9;\n const vec3 val = vec3(5.4856e-13, 4.4201e-13, 5.2481e-13);\n const vec3 pos = vec3(1.6810e+06, 1.7953e+06, 2.2084e+06);\n const vec3 var = vec3(4.3278e+09, 9.3046e+09, 6.6121e+09);\n vec3 xyz = val * sqrt(2.0 * PI * var) * cos(pos * phase + shift) * exp(-var * pow2(phase));\n xyz.x += 9.7470e-14 * sqrt(2.0 * PI * 4.5282e+09) * cos(2.2399e+06 * phase + shift[0]) * exp(-4.5282e+09 * pow2(phase));\n xyz /= 1.0685e-7;\n // XYZ to RGB color space\n const mat3 XYZ_TO_RGB = mat3( 3.2404542, -0.9692660, 0.0556434,\n -1.5371385, 1.8760108, -0.2040259,\n -0.4985314, 0.0415560, 1.0572252);\n vec3 rgb = XYZ_TO_RGB * xyz;\n return rgb;\n }\n\n vec3 evalIridescenceSpecular(float outsideIOR, float dotNV, float thinIOR, vec3 baseF0, float baseF90, float iridescenceThickness){ \n vec3 iridescence = vec3(1.0);\n // Force iridescenceIOR -> outsideIOR when thinFilmThickness -> 0.0\n float iridescenceIOR = mix( outsideIOR, thinIOR, smoothstep( 0.0, 0.03, iridescenceThickness ) );\n // Evaluate the cosTheta on the base layer (Snell law)\n float sinTheta2Sq = pow( outsideIOR / iridescenceIOR, 2.0) * (1.0 - pow( dotNV, 2.0));\n float cosTheta2Sq = 1.0 - sinTheta2Sq;\n // Handle total internal reflection\n if (cosTheta2Sq < 0.0) {\n return iridescence;\n }\n float cosTheta2 = sqrt(cosTheta2Sq);\n \n // First interface\n float f0 = iorToFresnel0(iridescenceIOR, outsideIOR);\n float reflectance = F_Schlick(f0, baseF90, dotNV);\n float t121 = 1.0 - reflectance;\n float phi12 = 0.0;\n // iridescenceIOR has limited greater than 1.0\n // if (iridescenceIOR < outsideIOR) {phi12 = PI;} \n float phi21 = PI - phi12;\n \n // Second interface\n vec3 baseIOR = fresnelToIOR(clamp(baseF0, 0.0, 0.9999)); // guard against 1.0\n vec3 r1 = iorToFresnel0(baseIOR, iridescenceIOR);\n vec3 r23 = F_Schlick(r1, baseF90, cosTheta2);\n vec3 phi23 =vec3(0.0);\n if (baseIOR[0] < iridescenceIOR) {phi23[0] = PI;}\n if (baseIOR[1] < iridescenceIOR) {phi23[1] = PI;}\n if (baseIOR[2] < iridescenceIOR) {phi23[2] = PI;}\n \n // Phase shift\n float opd = 2.0 * iridescenceIOR * iridescenceThickness * cosTheta2;\n vec3 phi = vec3(phi21) + phi23;\n \n // Compound terms\n vec3 r123 = clamp(reflectance * r23, 1e-5, 0.9999);\n vec3 sr123 = sqrt(r123);\n vec3 rs = pow2(t121) * r23 / (vec3(1.0) - r123);\n // Reflectance term for m = 0 (DC term amplitude)\n vec3 c0 = reflectance + rs;\n iridescence = c0;\n // Reflectance term for m > 0 (pairs of diracs)\n vec3 cm = rs - t121;\n for (int m = 1; m <= 2; ++m) {\n cm *= sr123;\n vec3 sm = 2.0 * evalSensitivity(float(m) * opd, float(m) * phi);\n iridescence += cm * sm;\n }\n return iridescence = max(iridescence, vec3(0.0)); \n }\n#endif\n\n// GGX Distribution, Schlick Fresnel, GGX-Smith Visibility\nvec3 BRDF_Specular_GGX(vec3 incidentDirection, Geometry geometry, Material material, vec3 normal, vec3 specularColor, float roughness ) {\n\n\tfloat alpha = pow2( roughness ); // UE4's roughness\n\n\tvec3 halfDir = normalize( incidentDirection + geometry.viewDir );\n\n\tfloat dotNL = saturate( dot( normal, incidentDirection ) );\n\tfloat dotNV = saturate( dot( normal, geometry.viewDir ) );\n\tfloat dotNH = saturate( dot( normal, halfDir ) );\n\tfloat dotLH = saturate( dot( incidentDirection, halfDir ) );\n\n vec3 F = F_Schlick( specularColor, material.specularF90, dotLH );\n #ifdef MATERIAL_ENABLE_IRIDESCENCE\n F = mix(F, material.iridescenceSpecularColor, material.iridescenceFactor);\n #endif\n\n #ifdef MATERIAL_ENABLE_ANISOTROPY\n float GD = DG_GGX_anisotropic(halfDir, incidentDirection, geometry, alpha, dotNV, dotNL, dotNH);\n #else\n float GD = DG_GGX(alpha, dotNV, dotNL, dotNH);\n #endif\n\n return F * GD;\n}\n\nvec3 BRDF_Diffuse_Lambert(vec3 diffuseColor ) {\n\treturn RECIPROCAL_PI * diffuseColor;\n}\n"; // eslint-disable-line
10445
10459
  var direct_irradiance_frag_define = "#include <ShadowFragmentDeclaration>\n\nvoid sheenLobe(Geometry geometry, Material material, vec3 incidentDirection, vec3 attenuationIrradiance, inout vec3 diffuseColor, inout vec3 specularColor){\n #ifdef MATERIAL_ENABLE_SHEEN\n diffuseColor *= material.sheenScaling;\n specularColor *= material.sheenScaling;\n\n specularColor += attenuationIrradiance * sheenBRDF(incidentDirection, geometry, material.sheenColor, material.sheenRoughness);\n #endif\n}\n\nvoid addDirectRadiance(vec3 incidentDirection, vec3 color, Geometry geometry, Material material, inout ReflectedLight reflectedLight) {\n float attenuation = 1.0;\n\n #ifdef MATERIAL_ENABLE_CLEAR_COAT\n float clearCoatDotNL = saturate( dot( geometry.clearCoatNormal, incidentDirection ) );\n vec3 clearCoatIrradiance = clearCoatDotNL * color;\n\n reflectedLight.directSpecular += material.clearCoat * clearCoatIrradiance * BRDF_Specular_GGX( incidentDirection, geometry, material, geometry.clearCoatNormal, vec3( 0.04 ), material.clearCoatRoughness );\n attenuation -= material.clearCoat * F_Schlick(0.04, 1.0, geometry.clearCoatDotNV);\n #endif\n\n float dotNL = saturate( dot( geometry.normal, incidentDirection ) );\n vec3 irradiance = dotNL * color * PI;\n\n reflectedLight.directSpecular += attenuation * irradiance * BRDF_Specular_GGX( incidentDirection, geometry, material, geometry.normal, material.specularF0, material.roughness) * material.energyCompensation;\n reflectedLight.directDiffuse += attenuation * irradiance * BRDF_Diffuse_Lambert( material.diffuseColor );\n\n // Sheen Lobe\n sheenLobe(geometry, material, incidentDirection, attenuation * irradiance, reflectedLight.directDiffuse, reflectedLight.directSpecular);\n\n}\n\n#ifdef SCENE_DIRECT_LIGHT_COUNT\n\n void addDirectionalDirectLightRadiance(DirectLight directionalLight, Geometry geometry, Material material, inout ReflectedLight reflectedLight) {\n vec3 color = directionalLight.color;\n vec3 direction = -directionalLight.direction;\n\n\t\taddDirectRadiance( direction, color, geometry, material, reflectedLight );\n\n }\n\n#endif\n\n#ifdef SCENE_POINT_LIGHT_COUNT\n\n\tvoid addPointDirectLightRadiance(PointLight pointLight, Geometry geometry, Material material, inout ReflectedLight reflectedLight) {\n\n\t\tvec3 lVector = pointLight.position - geometry.position;\n\t\tvec3 direction = normalize( lVector );\n\n\t\tfloat lightDistance = length( lVector );\n\n\t\tvec3 color = pointLight.color;\n\t\tcolor *= clamp(1.0 - pow(lightDistance/pointLight.distance, 4.0), 0.0, 1.0);\n\n\t\taddDirectRadiance( direction, color, geometry, material, reflectedLight );\n\n\t}\n\n#endif\n\n#ifdef SCENE_SPOT_LIGHT_COUNT\n\n\tvoid addSpotDirectLightRadiance(SpotLight spotLight, Geometry geometry, Material material, inout ReflectedLight reflectedLight) {\n\n\t\tvec3 lVector = spotLight.position - geometry.position;\n\t\tvec3 direction = normalize( lVector );\n\n\t\tfloat lightDistance = length( lVector );\n\t\tfloat angleCos = dot( direction, -spotLight.direction );\n\n\t\tfloat spotEffect = smoothstep( spotLight.penumbraCos, spotLight.angleCos, angleCos );\n\t\tfloat decayEffect = clamp(1.0 - pow(lightDistance/spotLight.distance, 4.0), 0.0, 1.0);\n\n\t\tvec3 color = spotLight.color;\n\t\tcolor *= spotEffect * decayEffect;\n\n\t\taddDirectRadiance( direction, color, geometry, material, reflectedLight );\n\n\t}\n\n\n#endif\n\nvoid addTotalDirectRadiance(Geometry geometry, Material material, inout ReflectedLight reflectedLight){\n float shadowAttenuation = 1.0;\n\n #ifdef SCENE_DIRECT_LIGHT_COUNT\n shadowAttenuation = 1.0;\n #ifdef SCENE_IS_CALCULATE_SHADOWS\n shadowAttenuation *= sampleShadowMap();\n #endif\n\n DirectLight directionalLight;\n for ( int i = 0; i < SCENE_DIRECT_LIGHT_COUNT; i ++ ) {\n // warning: use `continue` syntax may trigger flickering bug in safri 16.1.\n if(!isRendererCulledByLight(renderer_Layer.xy, scene_DirectLightCullingMask[i])){\n directionalLight.color = scene_DirectLightColor[i];\n #ifdef SCENE_IS_CALCULATE_SHADOWS\n if (i == 0) { // Sun light index is always 0\n directionalLight.color *= shadowAttenuation;\n }\n #endif\n directionalLight.direction = scene_DirectLightDirection[i];\n addDirectionalDirectLightRadiance( directionalLight, geometry, material, reflectedLight );\n }\n }\n\n #endif\n\n #ifdef SCENE_POINT_LIGHT_COUNT\n\n PointLight pointLight;\n\n for ( int i = 0; i < SCENE_POINT_LIGHT_COUNT; i ++ ) {\n if(!isRendererCulledByLight(renderer_Layer.xy, scene_PointLightCullingMask[i])){\n pointLight.color = scene_PointLightColor[i];\n pointLight.position = scene_PointLightPosition[i];\n pointLight.distance = scene_PointLightDistance[i];\n\n addPointDirectLightRadiance( pointLight, geometry, material, reflectedLight );\n } \n }\n\n #endif\n\n #ifdef SCENE_SPOT_LIGHT_COUNT\n\n SpotLight spotLight;\n\n for ( int i = 0; i < SCENE_SPOT_LIGHT_COUNT; i ++ ) {\n if(!isRendererCulledByLight(renderer_Layer.xy, scene_SpotLightCullingMask[i])){\n spotLight.color = scene_SpotLightColor[i];\n spotLight.position = scene_SpotLightPosition[i];\n spotLight.direction = scene_SpotLightDirection[i];\n spotLight.distance = scene_SpotLightDistance[i];\n spotLight.angleCos = scene_SpotLightAngleCos[i];\n spotLight.penumbraCos = scene_SpotLightPenumbraCos[i];\n\n addSpotDirectLightRadiance( spotLight, geometry, material, reflectedLight );\n } \n }\n\n #endif\n}"; // eslint-disable-line
10446
- var ibl_frag_define = "// ------------------------Diffuse------------------------\n\n// sh need be pre-scaled in CPU.\nvec3 getLightProbeIrradiance(vec3 sh[9], vec3 normal){\n vec3 result = sh[0] +\n\n sh[1] * (normal.y) +\n sh[2] * (normal.z) +\n sh[3] * (normal.x) +\n\n sh[4] * (normal.y * normal.x) +\n sh[5] * (normal.y * normal.z) +\n sh[6] * (3.0 * normal.z * normal.z - 1.0) +\n sh[7] * (normal.z * normal.x) +\n sh[8] * (normal.x * normal.x - normal.y * normal.y);\n \n return max(result, vec3(0.0));\n\n}\n\n// ------------------------Specular------------------------\n\n// Returns raw DFG approximation coefficients (split-sum LUT approximation)\nvec2 envDFGApprox(float roughness, float dotNV) {\n const vec4 c0 = vec4( - 1, - 0.0275, - 0.572, 0.022 );\n const vec4 c1 = vec4( 1, 0.0425, 1.04, - 0.04 );\n vec4 r = roughness * c0 + c1;\n float a004 = min( r.x * r.x, exp2( - 9.28 * dotNV ) ) * r.x + r.y;\n return vec2( -1.04, 1.04 ) * a004 + r.zw;\n}\n\n// ref: https://www.unrealengine.com/blog/physically-based-shading-on-mobile - environmentBRDF for GGX on mobile\nvec3 envBRDFApprox(vec3 f0, float f90, float roughness, float dotNV ) {\n vec2 AB = envDFGApprox(roughness, dotNV);\n return f0 * AB.x + f90 * AB.y;\n}\n\n\nfloat getSpecularMIPLevel(float roughness, int maxMIPLevel ) {\n return roughness * float(maxMIPLevel);\n}\n\nvec3 getReflectedVector(Geometry geometry, vec3 n) {\n #ifdef MATERIAL_ENABLE_ANISOTROPY\n vec3 r = reflect(-geometry.viewDir, geometry.anisotropicN);\n #else\n vec3 r = reflect(-geometry.viewDir, n);\n #endif\n\n return r;\n}\n\nvec3 getLightProbeRadiance(Geometry geometry, vec3 normal, float roughness, int maxMIPLevel, float specularIntensity) {\n\n #ifndef SCENE_USE_SPECULAR_ENV\n return vec3(0);\n #else\n vec3 reflectVec = getReflectedVector(geometry, normal);\n\n float specularMIPLevel = getSpecularMIPLevel(roughness, maxMIPLevel );\n\n #ifdef HAS_TEX_LOD\n vec4 envMapColor = textureCubeLodEXT( scene_EnvSpecularSampler, reflectVec, specularMIPLevel );\n #else\n vec4 envMapColor = textureCube( scene_EnvSpecularSampler, reflectVec, specularMIPLevel );\n #endif\n\n #ifdef ENGINE_NO_SRGB\n envMapColor = sRGBToLinear(envMapColor);\n #endif\n \n return envMapColor.rgb * specularIntensity;\n\n #endif\n\n}\n\n\nvoid evaluateSheenIBL(Geometry geometry, Material material, float radianceAttenuation, inout vec3 diffuseColor, inout vec3 specularColor){\n #ifdef MATERIAL_ENABLE_SHEEN\n diffuseColor *= material.sheenScaling;\n specularColor *= material.sheenScaling;\n\n vec3 reflectance = material.specularAO * radianceAttenuation * material.approxIBLSheenDG * material.sheenColor;\n specularColor += reflectance;\n #endif\n}"; // eslint-disable-line
10460
+ var ibl_frag_define = "// ------------------------Diffuse------------------------\n\n// sh need be pre-scaled in CPU.\nvec3 getLightProbeIrradiance(vec3 sh[9], vec3 normal){\n normal.x = -normal.x;\n vec3 result = sh[0] +\n\n sh[1] * (normal.y) +\n sh[2] * (normal.z) +\n sh[3] * (normal.x) +\n\n sh[4] * (normal.y * normal.x) +\n sh[5] * (normal.y * normal.z) +\n sh[6] * (3.0 * normal.z * normal.z - 1.0) +\n sh[7] * (normal.z * normal.x) +\n sh[8] * (normal.x * normal.x - normal.y * normal.y);\n \n return max(result, vec3(0.0));\n\n}\n\n// ------------------------Specular------------------------\n\n// Returns raw DFG approximation coefficients (split-sum LUT approximation)\nvec2 envDFGApprox(float roughness, float dotNV) {\n const vec4 c0 = vec4( - 1, - 0.0275, - 0.572, 0.022 );\n const vec4 c1 = vec4( 1, 0.0425, 1.04, - 0.04 );\n vec4 r = roughness * c0 + c1;\n float a004 = min( r.x * r.x, exp2( - 9.28 * dotNV ) ) * r.x + r.y;\n return vec2( -1.04, 1.04 ) * a004 + r.zw;\n}\n\n// ref: https://www.unrealengine.com/blog/physically-based-shading-on-mobile - environmentBRDF for GGX on mobile\nvec3 envBRDFApprox(vec3 f0, float f90, float roughness, float dotNV ) {\n vec2 AB = envDFGApprox(roughness, dotNV);\n return f0 * AB.x + f90 * AB.y;\n}\n\n\nfloat getSpecularMIPLevel(float roughness, int maxMIPLevel ) {\n return roughness * float(maxMIPLevel);\n}\n\nvec3 getReflectedVector(Geometry geometry, vec3 n) {\n #ifdef MATERIAL_ENABLE_ANISOTROPY\n vec3 r = reflect(-geometry.viewDir, geometry.anisotropicN);\n #else\n vec3 r = reflect(-geometry.viewDir, n);\n #endif\n\n return r;\n}\n\nvec3 getLightProbeRadiance(Geometry geometry, vec3 normal, float roughness, int maxMIPLevel, float specularIntensity) {\n\n #ifndef SCENE_USE_SPECULAR_ENV\n return vec3(0);\n #else\n vec3 reflectVec = getReflectedVector(geometry, normal);\n reflectVec.x = -reflectVec.x; // TextureCube is left-hand,so x need inverse\n \n float specularMIPLevel = getSpecularMIPLevel(roughness, maxMIPLevel );\n\n #ifdef HAS_TEX_LOD\n vec4 envMapColor = textureCubeLodEXT( scene_EnvSpecularSampler, reflectVec, specularMIPLevel );\n #else\n vec4 envMapColor = textureCube( scene_EnvSpecularSampler, reflectVec, specularMIPLevel );\n #endif\n\n #ifdef ENGINE_NO_SRGB\n envMapColor = sRGBToLinear(envMapColor);\n #endif\n \n return envMapColor.rgb * specularIntensity;\n\n #endif\n\n}\n\n\nvoid evaluateSheenIBL(Geometry geometry, Material material, float radianceAttenuation, inout vec3 diffuseColor, inout vec3 specularColor){\n #ifdef MATERIAL_ENABLE_SHEEN\n diffuseColor *= material.sheenScaling;\n specularColor *= material.sheenScaling;\n\n vec3 reflectance = material.specularAO * radianceAttenuation * material.approxIBLSheenDG * material.sheenColor;\n specularColor += reflectance;\n #endif\n}"; // eslint-disable-line
10447
10461
  var pbr_frag = "Geometry geometry;\nMaterial material;\nReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );\n\ninitGeometry(geometry, gl_FrontFacing);\ninitMaterial(material, geometry);\n\n// Direct Light\naddTotalDirectRadiance(geometry, material, reflectedLight);\n\n// IBL diffuse\n#ifdef SCENE_USE_SH\n vec3 irradiance = getLightProbeIrradiance(scene_EnvSH, geometry.normal);\n irradiance *= scene_EnvMapLight.diffuseIntensity;\n#else\n vec3 irradiance = scene_EnvMapLight.diffuse * scene_EnvMapLight.diffuseIntensity;\n irradiance *= PI;\n#endif\n\nreflectedLight.indirectDiffuse += material.diffuseAO * irradiance * BRDF_Diffuse_Lambert( material.diffuseColor );\n\n// IBL specular\nvec3 radiance = getLightProbeRadiance(geometry, geometry.normal, material.roughness, int(scene_EnvMapLight.mipMapLevel), scene_EnvMapLight.specularIntensity);\nfloat radianceAttenuation = 1.0;\n\n// IBL Clear Coat\n#ifdef MATERIAL_ENABLE_CLEAR_COAT\n vec3 clearCoatRadiance = getLightProbeRadiance( geometry, geometry.clearCoatNormal, material.clearCoatRoughness, int(scene_EnvMapLight.mipMapLevel), scene_EnvMapLight.specularIntensity );\n\n reflectedLight.indirectSpecular += material.specularAO * clearCoatRadiance * material.clearCoat * envBRDFApprox(vec3( 0.04 ), 1.0, material.clearCoatRoughness, geometry.clearCoatDotNV);\n radianceAttenuation -= material.clearCoat * F_Schlick(0.04, 1.0, geometry.clearCoatDotNV);\n#endif\n\nreflectedLight.indirectSpecular += material.specularAO * radianceAttenuation * radiance * envBRDFApprox(material.resolvedSpecularF0, material.specularF90, material.roughness, geometry.dotNV) * material.energyCompensation;\n\n\n// IBL Sheen\nevaluateSheenIBL(geometry, material, radianceAttenuation, reflectedLight.indirectDiffuse, reflectedLight.indirectSpecular);\n\n\n// Final color\nvec3 totalDiffuseColor = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse;\nvec3 totalSpecularColor = reflectedLight.directSpecular + reflectedLight.indirectSpecular;\n\n#ifdef MATERIAL_ENABLE_TRANSMISSION \n vec3 refractionTransmitted = evaluateTransmission(geometry, material);\n totalDiffuseColor = mix(totalDiffuseColor, refractionTransmitted, material.transmission);\n#endif\n\nvec4 finalColor = vec4(totalDiffuseColor + totalSpecularColor, material.opacity);\n\n\n// Emissive\nvec3 emissiveRadiance = material_EmissiveColor;\n#ifdef MATERIAL_HAS_EMISSIVETEXTURE\n emissiveRadiance *= texture2DSRGB(material_EmissiveTexture, v_uv).rgb;\n#endif\n\nfinalColor.rgb += emissiveRadiance;\n\n\ngl_FragColor = finalColor;\n"; // eslint-disable-line
10448
10462
  var btdf = "#include <refraction>\n\n#ifdef MATERIAL_ENABLE_TRANSMISSION \n uniform sampler2D camera_OpaqueTexture;\n vec3 evaluateTransmission(Geometry geometry, Material material) {\n RefractionModelResult ray;\n #if REFRACTION_MODE == 0 \n // RefractionMode.Sphere\n refractionModelSphere(-geometry.viewDir, geometry.position, geometry.normal, material.IOR, material.thickness, ray);\n #elif REFRACTION_MODE == 1\n // RefractionMode.Planar\n refractionModelPlanar(-geometry.viewDir, geometry.position, geometry.normal, material.IOR, material.thickness, ray);\n #endif\n\n vec3 refractedRayExit = ray.positionExit;\n\n // We calculate the screen space position of the refracted point\n vec4 samplingPositionNDC = camera_ProjMat * camera_ViewMat * vec4( refractedRayExit, 1.0 );\n vec2 refractionCoords = (samplingPositionNDC.xy / samplingPositionNDC.w) * 0.5 + 0.5;\n\n // Sample the opaque texture to get the transmitted light\n vec3 refractionTransmitted = texture2DSRGB(camera_OpaqueTexture, refractionCoords).rgb;\n refractionTransmitted *= material.diffuseColor;\n \n // Use specularFGD as an approximation of the fresnel effect\n // https://blog.selfshadow.com/publications/s2017-shading-course/imageworks/s2017_pbs_imageworks_slides_v2.pdf\n refractionTransmitted *= (1.0 - material.envSpecularDFG);\n\n #ifdef MATERIAL_HAS_THICKNESS\n // Absorption coefficient from Disney: http://blog.selfshadow.com/publications/s2015-shading-course/burley/s2015_pbs_disney_bsdf_notes.pdf\n vec3 transmittance = min(vec3(1.0), exp(-material.absorptionCoefficient * ray.transmissionLength));\n refractionTransmitted *= transmittance;\n #endif\n \n return refractionTransmitted;\n }\n#endif"; // eslint-disable-line
10449
10463
  var refraction = "#ifdef MATERIAL_ENABLE_TRANSMISSION \n\tstruct RefractionModelResult {\n\t float transmissionLength; // length of the transmission during refraction through the shape\n\t vec3 positionExit; // out ray position\n\t // vec3 directionExit; // out ray direction\n\t};\n\n\t//https://docs.unity3d.com/Packages/com.unity.render-pipelines.high-definition@15.0/manual/refraction-models.html\n\t void refractionModelSphere(vec3 V, vec3 positionWS, vec3 normalWS, float ior, float thickness, out RefractionModelResult ray) {\n\t // Refracted ray\n\t vec3 R1 = refract(V, normalWS, 1.0 / ior);\n\t // Center of the tangent sphere\n\t // vec3 C = positionWS - normalWS * thickness * 0.5;\n\n\t // Second refraction (tangent sphere out)\n\t float dist = dot(-normalWS, R1) * thickness;\n\t // Out hit point in the tangent sphere\n\t vec3 P1 = positionWS + R1 * dist;\n\t // Out normal\n\t // vec3 N1 = safeNormalize(C - P1);\n\t // Out refracted ray\n\t // vec3 R2 = refract(R1, N1, ior);\n\n\t ray.transmissionLength = dist;\n\t ray.positionExit = P1;\n\t // ray.directionExit = R2; \n\t}\n\n\tvoid refractionModelPlanar(vec3 V, vec3 positionWS, vec3 normalWS, float ior, float thickness, out RefractionModelResult ray) {\n\t // Refracted ray\n\t vec3 R = refract(V, normalWS, 1.0 / ior);\n\t // Optical depth within the thin plane\n\t float dist = thickness / max(dot(-normalWS, R), 1e-5f);\n\n\t ray.transmissionLength = dist;\n\t ray.positionExit = vec3(positionWS + R * dist);\n\t // ray.directionExit = V;\n\t}\n\n#endif"; // eslint-disable-line
@@ -10477,8 +10491,7 @@
10477
10491
  var texture_sheet_animation_module = "#if defined(RENDERER_TSA_FRAME_CURVE) || defined(RENDERER_TSA_FRAME_RANDOM_CURVES)\n uniform float renderer_TSACycles;\n uniform vec3 renderer_TSATillingParams; // x:subU y:subV z:tileCount\n uniform vec2 renderer_TSAFrameMaxCurve[4]; // x:time y:value\n\n #ifdef RENDERER_TSA_FRAME_RANDOM_CURVES\n uniform vec2 renderer_TSAFrameMinCurve[4]; // x:time y:value\n #endif\n#endif\n\nvec2 computeParticleUV(in vec2 uv, in float normalizedAge) {\n #if defined(RENDERER_TSA_FRAME_CURVE) || defined(RENDERER_TSA_FRAME_RANDOM_CURVES)\n float scaledNormalizedAge = normalizedAge * renderer_TSACycles;\n float cycleNormalizedAge = scaledNormalizedAge - floor(scaledNormalizedAge);\n float normalizedFrame = evaluateParticleCurve(renderer_TSAFrameMaxCurve, cycleNormalizedAge);\n #ifdef RENDERER_TSA_FRAME_RANDOM_CURVES\n normalizedFrame = mix(evaluateParticleCurve(renderer_TSAFrameMinCurve, cycleNormalizedAge), normalizedFrame, a_Random1.x);\n #endif\n\n float frame = floor(normalizedFrame * renderer_TSATillingParams.z);\n\n float tileRow = frame * renderer_TSATillingParams.x;\n float tileRowIndex = floor(tileRow);\n uv.x += tileRow - tileRowIndex;\n uv.y += tileRowIndex * renderer_TSATillingParams.y;\n #endif\n \n return uv;\n}\n"; // eslint-disable-line
10478
10492
  var force_over_lifetime_module = "#if defined(RENDERER_FOL_CONSTANT_MODE) || defined(RENDERER_FOL_CURVE_MODE)\n #define _FOL_MODULE_ENABLED\n#endif\n\n#ifdef _FOL_MODULE_ENABLED\n uniform int renderer_FOLSpace;\n\n #ifdef RENDERER_FOL_CONSTANT_MODE\n uniform vec3 renderer_FOLMaxConst;\n\n #ifdef RENDERER_FOL_IS_RANDOM_TWO\n uniform vec3 renderer_FOLMinConst;\n #endif\n\n #endif\n\n #ifdef RENDERER_FOL_CURVE_MODE\n uniform vec2 renderer_FOLMaxGradientX[4];\n uniform vec2 renderer_FOLMaxGradientY[4];\n uniform vec2 renderer_FOLMaxGradientZ[4];\n\n #ifdef RENDERER_FOL_IS_RANDOM_TWO\n uniform vec2 renderer_FOLMinGradientX[4];\n uniform vec2 renderer_FOLMinGradientY[4];\n uniform vec2 renderer_FOLMinGradientZ[4];\n #endif\n #endif\n\n // (tHat - t1) * (tHat - t1) * (tHat - t1) * (a2 - a1) / ((t2 - t1) * 6.0) + a1 * (tHat - t1) * (tHat - t1) * 0.5 + v1 * (tHat - t1);\n // to = tHat - t1; tr = t2 - t1\n float computeDisplacementIntegral(in float to, in float tr, in float a1, in float a2, in float v1) {\n return to * to * to * (a2 - a1) / (tr * 6.0) + a1 * to * to * 0.5 + v1 * to;\n }\n\n float evaluateForceParticleCurveCumulative(in vec2 keys[4], in float normalizedAge, out float velocityCumulative) {\n float cumulativeValue = 0.0;\n velocityCumulative = 0.0;\n\n for (int i = 1; i < 4; i++){\n vec2 key = keys[i];\n vec2 lastKey = keys[i - 1];\n float timeRange = (key.x - lastKey.x) * a_ShapePositionStartLifeTime.w;\n\n if (key.x >= normalizedAge){\n float timeOffset = (normalizedAge - lastKey.x) * a_ShapePositionStartLifeTime.w;\n cumulativeValue += computeDisplacementIntegral(timeOffset, timeRange, lastKey.y, key.y, velocityCumulative);\n\n float finalAcceleration = mix(lastKey.y, key.y, timeOffset / timeRange);\n velocityCumulative += 0.5 * timeOffset * (finalAcceleration + lastKey.y);\n break;\n } else { \n cumulativeValue += computeDisplacementIntegral(timeRange, timeRange, lastKey.y, key.y, velocityCumulative);\n velocityCumulative += 0.5 * timeRange * (lastKey.y + key.y);\n }\n }\n return cumulativeValue;\n }\n\n vec3 computeForcePositionOffset(in float normalizedAge, in float age, out vec3 velocityOffset) {\n vec3 forcePosition;\n\n #if defined(RENDERER_FOL_CONSTANT_MODE)\n vec3 forceAcceleration = renderer_FOLMaxConst;\n\n #ifdef RENDERER_FOL_IS_RANDOM_TWO\n forceAcceleration = mix(renderer_FOLMinConst, forceAcceleration, vec3(a_Random2.x, a_Random2.y, a_Random2.z));\n #endif\n\n velocityOffset = forceAcceleration * age;\n\n forcePosition = 0.5 * forceAcceleration * age * age;\n #elif defined(RENDERER_FOL_CURVE_MODE)\n forcePosition = vec3(\n evaluateForceParticleCurveCumulative(renderer_FOLMaxGradientX, normalizedAge, velocityOffset.x),\n evaluateForceParticleCurveCumulative(renderer_FOLMaxGradientY, normalizedAge, velocityOffset.y),\n evaluateForceParticleCurveCumulative(renderer_FOLMaxGradientZ, normalizedAge, velocityOffset.z)\n );\n #ifdef RENDERER_FOL_IS_RANDOM_TWO\n vec3 minVelocityOffset;\n\n forcePosition = vec3(\n mix(evaluateForceParticleCurveCumulative(renderer_FOLMinGradientX, normalizedAge, minVelocityOffset.x), forcePosition.x, a_Random2.x),\n mix(evaluateForceParticleCurveCumulative(renderer_FOLMinGradientY, normalizedAge, minVelocityOffset.y), forcePosition.y, a_Random2.y),\n mix(evaluateForceParticleCurveCumulative(renderer_FOLMinGradientZ, normalizedAge, minVelocityOffset.z), forcePosition.z, a_Random2.z)\n );\n\n velocityOffset = mix(minVelocityOffset, velocityOffset, vec3(a_Random2.x, a_Random2.y, a_Random2.z));\n #endif\n #endif\n return forcePosition;\n }\n#endif"; // eslint-disable-line
10479
10493
  var limit_velocity_over_lifetime_module = "#ifdef RENDERER_LVL_MODULE_ENABLED\n uniform int renderer_LVLSpace;\n uniform float renderer_LVLDampen;\n\n // Scalar limit\n #ifndef RENDERER_LVL_SEPARATE_AXES\n #ifdef RENDERER_LVL_SPEED_CONSTANT_MODE\n uniform float renderer_LVLSpeedMaxConst;\n #ifdef RENDERER_LVL_SPEED_IS_RANDOM_TWO\n uniform float renderer_LVLSpeedMinConst;\n #endif\n #endif\n #ifdef RENDERER_LVL_SPEED_CURVE_MODE\n uniform vec2 renderer_LVLSpeedMaxCurve[4];\n #ifdef RENDERER_LVL_SPEED_IS_RANDOM_TWO\n uniform vec2 renderer_LVLSpeedMinCurve[4];\n #endif\n #endif\n #endif\n\n // Per-axis limit\n #ifdef RENDERER_LVL_SEPARATE_AXES\n #ifdef RENDERER_LVL_SPEED_CONSTANT_MODE\n uniform vec3 renderer_LVLSpeedMaxConstVector;\n #ifdef RENDERER_LVL_SPEED_IS_RANDOM_TWO\n uniform vec3 renderer_LVLSpeedMinConstVector;\n #endif\n #endif\n #ifdef RENDERER_LVL_SPEED_CURVE_MODE\n uniform vec2 renderer_LVLSpeedXMaxCurve[4];\n uniform vec2 renderer_LVLSpeedYMaxCurve[4];\n uniform vec2 renderer_LVLSpeedZMaxCurve[4];\n #ifdef RENDERER_LVL_SPEED_IS_RANDOM_TWO\n uniform vec2 renderer_LVLSpeedXMinCurve[4];\n uniform vec2 renderer_LVLSpeedYMinCurve[4];\n uniform vec2 renderer_LVLSpeedZMinCurve[4];\n #endif\n #endif\n #endif\n\n // Drag curve\n #ifdef RENDERER_LVL_DRAG_CURVE_MODE\n uniform vec2 renderer_LVLDragMaxCurve[4];\n #ifdef RENDERER_LVL_DRAG_IS_RANDOM_TWO\n uniform vec2 renderer_LVLDragMinCurve[4];\n #endif\n #endif\n\n float evaluateLVLDrag(float normalizedAge, float dragRand) {\n #ifdef RENDERER_LVL_DRAG_CURVE_MODE\n float dragMax = evaluateParticleCurve(renderer_LVLDragMaxCurve, normalizedAge);\n #ifdef RENDERER_LVL_DRAG_IS_RANDOM_TWO\n float dragMin = evaluateParticleCurve(renderer_LVLDragMinCurve, normalizedAge);\n return mix(dragMin, dragMax, dragRand);\n #else\n return dragMax;\n #endif\n #else\n return mix(renderer_LVLDragConstant.x, renderer_LVLDragConstant.y, dragRand);\n #endif\n }\n\n vec3 applyLVLSpeedLimitTF(vec3 velocity, float normalizedAge, float limitRand, float effectiveDampen) {\n #ifdef RENDERER_LVL_SEPARATE_AXES\n vec3 limitSpeed;\n #ifdef RENDERER_LVL_SPEED_CONSTANT_MODE\n limitSpeed = renderer_LVLSpeedMaxConstVector;\n #ifdef RENDERER_LVL_SPEED_IS_RANDOM_TWO\n limitSpeed = mix(renderer_LVLSpeedMinConstVector, limitSpeed, limitRand);\n #endif\n #endif\n #ifdef RENDERER_LVL_SPEED_CURVE_MODE\n limitSpeed = vec3(\n evaluateParticleCurve(renderer_LVLSpeedXMaxCurve, normalizedAge),\n evaluateParticleCurve(renderer_LVLSpeedYMaxCurve, normalizedAge),\n evaluateParticleCurve(renderer_LVLSpeedZMaxCurve, normalizedAge)\n );\n #ifdef RENDERER_LVL_SPEED_IS_RANDOM_TWO\n vec3 minLimitSpeed = vec3(\n evaluateParticleCurve(renderer_LVLSpeedXMinCurve, normalizedAge),\n evaluateParticleCurve(renderer_LVLSpeedYMinCurve, normalizedAge),\n evaluateParticleCurve(renderer_LVLSpeedZMinCurve, normalizedAge)\n );\n limitSpeed = mix(minLimitSpeed, limitSpeed, limitRand);\n #endif\n #endif\n\n vec3 absVel = abs(velocity);\n vec3 excess = max(absVel - limitSpeed, vec3(0.0));\n velocity = sign(velocity) * (absVel - excess * effectiveDampen);\n #else\n float limitSpeed;\n #ifdef RENDERER_LVL_SPEED_CONSTANT_MODE\n limitSpeed = renderer_LVLSpeedMaxConst;\n #ifdef RENDERER_LVL_SPEED_IS_RANDOM_TWO\n limitSpeed = mix(renderer_LVLSpeedMinConst, limitSpeed, limitRand);\n #endif\n #endif\n #ifdef RENDERER_LVL_SPEED_CURVE_MODE\n limitSpeed = evaluateParticleCurve(renderer_LVLSpeedMaxCurve, normalizedAge);\n #ifdef RENDERER_LVL_SPEED_IS_RANDOM_TWO\n float minLimitSpeed = evaluateParticleCurve(renderer_LVLSpeedMinCurve, normalizedAge);\n limitSpeed = mix(minLimitSpeed, limitSpeed, limitRand);\n #endif\n #endif\n\n float speed = length(velocity);\n if (speed > limitSpeed && speed > 0.0) {\n float excess = speed - limitSpeed;\n velocity = velocity * ((speed - excess * effectiveDampen) / speed);\n }\n #endif\n return velocity;\n }\n\n#endif\n"; // eslint-disable-line
10480
- var noise_module = "#ifdef RENDERER_NOISE_MODULE_ENABLED\n\n#include <noise_common>\n#include <noise_simplex_3D_grad>\n\nuniform vec4 renderer_NoiseParams; // xyz = strength (constant mode only), w = frequency\nuniform vec4 renderer_NoiseOctaveParams; // x = scrollSpeed, y = octaveCount, z = octaveIntensityMultiplier, w = octaveFrequencyMultiplier\n\n#ifdef RENDERER_NOISE_STRENGTH_CURVE\n uniform vec2 renderer_NoiseStrengthMaxCurveX[4];\n #ifdef RENDERER_NOISE_IS_SEPARATE\n uniform vec2 renderer_NoiseStrengthMaxCurveY[4];\n uniform vec2 renderer_NoiseStrengthMaxCurveZ[4];\n #endif\n #ifdef RENDERER_NOISE_STRENGTH_IS_RANDOM_TWO\n uniform vec2 renderer_NoiseStrengthMinCurveX[4];\n #ifdef RENDERER_NOISE_IS_SEPARATE\n uniform vec2 renderer_NoiseStrengthMinCurveY[4];\n uniform vec2 renderer_NoiseStrengthMinCurveZ[4];\n #endif\n #endif\n#else\n #ifdef RENDERER_NOISE_STRENGTH_IS_RANDOM_TWO\n uniform vec3 renderer_NoiseStrengthMinConst;\n #endif\n#endif\n\nvec3 sampleCurlNoise3D(vec3 coord) {\n float axisOffset = 100.0;\n vec3 gradX = simplexGrad(vec3(coord.z, coord.y, coord.x));\n vec3 gradY = simplexGrad(vec3(coord.x + axisOffset, coord.z, coord.y));\n vec3 gradZ = simplexGrad(vec3(coord.y, coord.x + axisOffset, coord.z));\n return vec3(\n gradZ.x - gradY.y,\n gradX.x - gradZ.y,\n gradY.x - gradX.y\n );\n}\n\nvec3 computeNoiseVelocity(vec3 currentPosition, float normalizedAge) {\n vec3 coord = currentPosition * renderer_NoiseParams.w\n + vec3(renderer_CurrentTime * renderer_NoiseOctaveParams.x);\n\n int octaveCount = int(renderer_NoiseOctaveParams.y);\n float octaveIntensityMultiplier = renderer_NoiseOctaveParams.z;\n float octaveFrequencyMultiplier = renderer_NoiseOctaveParams.w;\n\n vec3 noiseValue = sampleCurlNoise3D(coord);\n float totalAmplitude = 1.0;\n\n // Unrolled octave loop (GLSL ES 1.0 requires constant loop bounds)\n if (octaveCount >= 2) {\n float amplitude = octaveIntensityMultiplier;\n totalAmplitude += amplitude;\n noiseValue += amplitude * sampleCurlNoise3D(coord * octaveFrequencyMultiplier);\n\n if (octaveCount >= 3) {\n amplitude *= octaveIntensityMultiplier;\n totalAmplitude += amplitude;\n noiseValue += amplitude * sampleCurlNoise3D(coord * octaveFrequencyMultiplier * octaveFrequencyMultiplier);\n }\n }\n\n // Evaluate strength (supports Constant, TwoConstants, Curve, TwoCurves).\n vec3 strength;\n #ifdef RENDERER_NOISE_STRENGTH_CURVE\n float sx = evaluateParticleCurve(renderer_NoiseStrengthMaxCurveX, normalizedAge);\n #ifdef RENDERER_NOISE_STRENGTH_IS_RANDOM_TWO\n sx = mix(evaluateParticleCurve(renderer_NoiseStrengthMinCurveX, normalizedAge), sx, a_Random0.z);\n #endif\n #ifdef RENDERER_NOISE_IS_SEPARATE\n float sy = evaluateParticleCurve(renderer_NoiseStrengthMaxCurveY, normalizedAge);\n float sz = evaluateParticleCurve(renderer_NoiseStrengthMaxCurveZ, normalizedAge);\n #ifdef RENDERER_NOISE_STRENGTH_IS_RANDOM_TWO\n sy = mix(evaluateParticleCurve(renderer_NoiseStrengthMinCurveY, normalizedAge), sy, a_Random0.z);\n sz = mix(evaluateParticleCurve(renderer_NoiseStrengthMinCurveZ, normalizedAge), sz, a_Random0.z);\n #endif\n strength = vec3(sx, sy, sz);\n #else\n strength = vec3(sx);\n #endif\n #else\n strength = renderer_NoiseParams.xyz;\n #ifdef RENDERER_NOISE_STRENGTH_IS_RANDOM_TWO\n strength = mix(renderer_NoiseStrengthMinConst, strength, a_Random0.z);\n #endif\n #endif\n\n return (noiseValue / totalAmplitude) * strength;\n}\n\n#endif\n"; // eslint-disable-line
10481
- var particle_feedback_simulation = "// Transform Feedback update shader for particle simulation.\n// Update order: VOL/FOL → Dampen → Drag → Position.\n// Runs once per particle per frame (no rasterization).\n\n// Previous frame TF data\nattribute vec3 a_FeedbackPosition;\nattribute vec3 a_FeedbackVelocity;\n\n// Per-particle instance data\nattribute vec4 a_ShapePositionStartLifeTime;\nattribute vec4 a_DirectionTime;\nattribute vec3 a_StartSize;\nattribute float a_StartSpeed;\nattribute vec4 a_Random0;\nattribute vec4 a_Random1;\nattribute vec3 a_SimulationWorldPosition;\nattribute vec4 a_SimulationWorldRotation;\nattribute vec4 a_Random2;\n\n// Uniforms\nuniform float renderer_CurrentTime;\nuniform float renderer_DeltaTime;\nuniform vec3 renderer_Gravity;\nuniform vec2 renderer_LVLDragConstant;\nuniform vec3 renderer_WorldPosition;\nuniform vec4 renderer_WorldRotation;\nuniform int renderer_SimulationSpace;\n\n// TF outputs\nvarying vec3 v_FeedbackPosition;\nvarying vec3 v_FeedbackVelocity;\n\n#include <particle_common>\n#include <velocity_over_lifetime_module>\n#include <force_over_lifetime_module>\n#include <limit_velocity_over_lifetime_module>\n#include <noise_module>\n\n// Get VOL instantaneous velocity at normalizedAge\nvec3 getVOLVelocity(float normalizedAge) {\n vec3 vel = vec3(0.0);\n #ifdef _VOL_MODULE_ENABLED\n #ifdef RENDERER_VOL_CONSTANT_MODE\n vel = renderer_VOLMaxConst;\n #ifdef RENDERER_VOL_IS_RANDOM_TWO\n vel = mix(renderer_VOLMinConst, vel, a_Random1.yzw);\n #endif\n #endif\n #ifdef RENDERER_VOL_CURVE_MODE\n vel = vec3(\n evaluateParticleCurve(renderer_VOLMaxGradientX, normalizedAge),\n evaluateParticleCurve(renderer_VOLMaxGradientY, normalizedAge),\n evaluateParticleCurve(renderer_VOLMaxGradientZ, normalizedAge)\n );\n #ifdef RENDERER_VOL_IS_RANDOM_TWO\n vec3 minVel = vec3(\n evaluateParticleCurve(renderer_VOLMinGradientX, normalizedAge),\n evaluateParticleCurve(renderer_VOLMinGradientY, normalizedAge),\n evaluateParticleCurve(renderer_VOLMinGradientZ, normalizedAge)\n );\n vel = mix(minVel, vel, a_Random1.yzw);\n #endif\n #endif\n #endif\n return vel;\n}\n\n// Get FOL instantaneous acceleration at normalizedAge\nvec3 getFOLAcceleration(float normalizedAge) {\n vec3 acc = vec3(0.0);\n #ifdef _FOL_MODULE_ENABLED\n #ifdef RENDERER_FOL_CONSTANT_MODE\n acc = renderer_FOLMaxConst;\n #ifdef RENDERER_FOL_IS_RANDOM_TWO\n acc = mix(renderer_FOLMinConst, acc, vec3(a_Random2.x, a_Random2.y, a_Random2.z));\n #endif\n #endif\n #ifdef RENDERER_FOL_CURVE_MODE\n acc = vec3(\n evaluateParticleCurve(renderer_FOLMaxGradientX, normalizedAge),\n evaluateParticleCurve(renderer_FOLMaxGradientY, normalizedAge),\n evaluateParticleCurve(renderer_FOLMaxGradientZ, normalizedAge)\n );\n #ifdef RENDERER_FOL_IS_RANDOM_TWO\n vec3 minAcc = vec3(\n evaluateParticleCurve(renderer_FOLMinGradientX, normalizedAge),\n evaluateParticleCurve(renderer_FOLMinGradientY, normalizedAge),\n evaluateParticleCurve(renderer_FOLMinGradientZ, normalizedAge)\n );\n acc = mix(minAcc, acc, vec3(a_Random2.x, a_Random2.y, a_Random2.z));\n #endif\n #endif\n #endif\n return acc;\n}\n\nvoid main() {\n float age = renderer_CurrentTime - a_DirectionTime.w;\n float lifetime = a_ShapePositionStartLifeTime.w;\n float normalizedAge = age / lifetime;\n // Clamp to age on the first TF pass: particles emitted mid-frame have age < dt,\n // so using the full dt would over-integrate. Subsequent passes are unaffected (age >= dt).\n float dt = min(renderer_DeltaTime, age);\n\n // normalizedAge < 0.0: stale TF slot whose startTime is from a previous playback (e.g. after StopEmittingAndClear).\n if (normalizedAge >= 1.0 || normalizedAge < 0.0) {\n v_FeedbackPosition = a_FeedbackPosition;\n v_FeedbackVelocity = a_FeedbackVelocity;\n gl_Position = vec4(0.0);\n return;\n }\n\n vec4 worldRotation;\n if (renderer_SimulationSpace == 0) {\n worldRotation = renderer_WorldRotation;\n } else {\n worldRotation = a_SimulationWorldRotation;\n }\n vec4 invWorldRotation = quaternionConjugate(worldRotation);\n\n // Read previous frame state (initialized by CPU on particle birth)\n vec3 localVelocity = a_FeedbackVelocity;\n\n // =====================================================\n // Step 1: Apply velocity module deltas (VOL + FOL + Gravity)\n // =====================================================\n\n // Gravity (world space)\n vec3 gravityDelta = renderer_Gravity * a_Random0.x * dt;\n\n // VOL instantaneous velocity (animated velocity, not persisted)\n vec3 volLocal = vec3(0.0);\n vec3 volWorld = vec3(0.0);\n #ifdef _VOL_MODULE_ENABLED\n vec3 vol = getVOLVelocity(normalizedAge);\n if (renderer_VOLSpace == 0) {\n volLocal = vol;\n } else {\n volWorld = vol;\n }\n #endif\n\n // FOL acceleration → velocity delta (always persisted, like gravity)\n vec3 folDeltaLocal = vec3(0.0);\n #ifdef _FOL_MODULE_ENABLED\n vec3 folAcc = getFOLAcceleration(normalizedAge);\n vec3 folVelDelta = folAcc * dt;\n if (renderer_FOLSpace == 0) {\n folDeltaLocal = folVelDelta;\n } else {\n // World FOL: convert to local and persist, same as gravity\n folDeltaLocal = rotationByQuaternions(folVelDelta, invWorldRotation);\n }\n #endif\n\n // Gravity and FOL contribute to base velocity (persisted, subject to dampen/drag).\n vec3 gravityLocal = rotationByQuaternions(gravityDelta, invWorldRotation);\n localVelocity += folDeltaLocal + gravityLocal;\n\n // =====================================================\n // Step 2 & 3: Dampen (Limit Velocity) + Drag\n // VOL must be projected into the LVL target space so that\n // limit/drag see the full velocity regardless of VOL.space vs LVL.space.\n // =====================================================\n #ifdef RENDERER_LVL_MODULE_ENABLED\n // Precompute VOL in both spaces\n vec3 volAsLocal = volLocal + rotationByQuaternions(volWorld, invWorldRotation);\n vec3 volAsWorld = rotationByQuaternions(volLocal, worldRotation) + volWorld;\n\n float limitRand = a_Random2.w;\n float dampen = renderer_LVLDampen;\n // Frame-rate independent dampen (30fps as reference)\n float effectiveDampen = 1.0 - pow(1.0 - dampen, dt * 30.0);\n\n if (renderer_LVLSpace == 0) {\n // Local space: total = base + all VOL projected to local\n vec3 totalLocal = localVelocity + volAsLocal;\n vec3 dampenedTotal = applyLVLSpeedLimitTF(totalLocal, normalizedAge, limitRand, effectiveDampen);\n localVelocity = dampenedTotal - volAsLocal;\n } else {\n // World space: total = rotated base + all VOL projected to world\n vec3 totalWorld = rotationByQuaternions(localVelocity, worldRotation) + volAsWorld;\n vec3 dampenedTotal = applyLVLSpeedLimitTF(totalWorld, normalizedAge, limitRand, effectiveDampen);\n localVelocity = rotationByQuaternions(dampenedTotal - volAsWorld, invWorldRotation);\n }\n\n // Drag: same space as dampen\n {\n float dragCoeff = evaluateLVLDrag(normalizedAge, a_Random2.w);\n if (dragCoeff > 0.0) {\n vec3 totalVel;\n if (renderer_LVLSpace == 0) {\n totalVel = localVelocity + volAsLocal;\n } else {\n totalVel = rotationByQuaternions(localVelocity, worldRotation) + volAsWorld;\n }\n float velMagSqr = dot(totalVel, totalVel);\n float velMag = sqrt(velMagSqr);\n\n float drag = dragCoeff;\n\n #ifdef RENDERER_LVL_DRAG_MULTIPLY_SIZE\n float maxDim = max(a_StartSize.x, max(a_StartSize.y, a_StartSize.z));\n float radius = maxDim * 0.5;\n drag *= 3.14159265 * radius * radius;\n #endif\n\n #ifdef RENDERER_LVL_DRAG_MULTIPLY_VELOCITY\n drag *= velMagSqr;\n #endif\n\n if (velMag > 0.0) {\n float newVelMag = max(0.0, velMag - drag * dt);\n vec3 draggedTotal = totalVel * (newVelMag / velMag);\n if (renderer_LVLSpace == 0) {\n localVelocity = draggedTotal - volAsLocal;\n } else {\n localVelocity = rotationByQuaternions(draggedTotal - volAsWorld, invWorldRotation);\n }\n }\n }\n }\n #endif\n\n // =====================================================\n // Step 4: Integrate position in simulation space\n // Local mode: position in local space, velocity rotated to local\n // World mode: position in world space, velocity rotated to world\n // =====================================================\n // FOL is now fully in localVelocity (both local and world-space FOL).\n // VOL and Noise overlays are added here (not persisted).\n\n vec3 totalVelocity;\n if (renderer_SimulationSpace == 0) {\n totalVelocity = localVelocity + volLocal + rotationByQuaternions(volWorld, invWorldRotation);\n } else {\n totalVelocity = rotationByQuaternions(localVelocity + volLocal, worldRotation) + volWorld;\n }\n #ifdef RENDERER_NOISE_MODULE_ENABLED\n // Use analytical base position (birth + initial velocity * age) instead of\n // a_FeedbackPosition to avoid feedback loop: position → noise → velocity → position\n vec3 noiseBasePos;\n if (renderer_SimulationSpace == 0) {\n noiseBasePos = a_ShapePositionStartLifeTime.xyz + a_DirectionTime.xyz * a_StartSpeed * age;\n } else {\n noiseBasePos = rotationByQuaternions(\n a_ShapePositionStartLifeTime.xyz + a_DirectionTime.xyz * a_StartSpeed * age,\n worldRotation) + a_SimulationWorldPosition;\n }\n totalVelocity += computeNoiseVelocity(noiseBasePos, normalizedAge);\n #endif\n vec3 position = a_FeedbackPosition + totalVelocity * dt;\n\n v_FeedbackPosition = position;\n v_FeedbackVelocity = localVelocity;\n gl_Position = vec4(0.0);\n}\n"; // eslint-disable-line
10494
+ var particle_feedback_simulation = "// Transform Feedback update shader for particle simulation.\n// Update order: VOL/FOL → Dampen → Drag → Position.\n// Runs once per particle per frame (no rasterization).\n\n// Previous frame TF data\nattribute vec3 a_FeedbackPosition;\nattribute vec3 a_FeedbackVelocity;\n\n// Per-particle instance data\nattribute vec4 a_ShapePositionStartLifeTime;\nattribute vec4 a_DirectionTime;\nattribute vec3 a_StartSize;\nattribute float a_StartSpeed;\nattribute vec4 a_Random0;\nattribute vec4 a_Random1;\nattribute vec3 a_SimulationWorldPosition;\nattribute vec4 a_SimulationWorldRotation;\nattribute vec4 a_Random2;\n\n// Uniforms\nuniform float renderer_CurrentTime;\nuniform float renderer_DeltaTime;\nuniform vec3 renderer_Gravity;\nuniform vec2 renderer_LVLDragConstant;\nuniform vec3 renderer_WorldPosition;\nuniform vec4 renderer_WorldRotation;\nuniform int renderer_SimulationSpace;\n\n// TF outputs\nvarying vec3 v_FeedbackPosition;\nvarying vec3 v_FeedbackVelocity;\n\n#include <particle_common>\n#include <velocity_over_lifetime_module>\n#include <force_over_lifetime_module>\n#include <limit_velocity_over_lifetime_module>\n\n// Get VOL instantaneous velocity at normalizedAge\nvec3 getVOLVelocity(float normalizedAge) {\n vec3 vel = vec3(0.0);\n #ifdef _VOL_MODULE_ENABLED\n #ifdef RENDERER_VOL_CONSTANT_MODE\n vel = renderer_VOLMaxConst;\n #ifdef RENDERER_VOL_IS_RANDOM_TWO\n vel = mix(renderer_VOLMinConst, vel, a_Random1.yzw);\n #endif\n #endif\n #ifdef RENDERER_VOL_CURVE_MODE\n vel = vec3(\n evaluateParticleCurve(renderer_VOLMaxGradientX, normalizedAge),\n evaluateParticleCurve(renderer_VOLMaxGradientY, normalizedAge),\n evaluateParticleCurve(renderer_VOLMaxGradientZ, normalizedAge)\n );\n #ifdef RENDERER_VOL_IS_RANDOM_TWO\n vec3 minVel = vec3(\n evaluateParticleCurve(renderer_VOLMinGradientX, normalizedAge),\n evaluateParticleCurve(renderer_VOLMinGradientY, normalizedAge),\n evaluateParticleCurve(renderer_VOLMinGradientZ, normalizedAge)\n );\n vel = mix(minVel, vel, a_Random1.yzw);\n #endif\n #endif\n #endif\n return vel;\n}\n\n// Get FOL instantaneous acceleration at normalizedAge\nvec3 getFOLAcceleration(float normalizedAge) {\n vec3 acc = vec3(0.0);\n #ifdef _FOL_MODULE_ENABLED\n #ifdef RENDERER_FOL_CONSTANT_MODE\n acc = renderer_FOLMaxConst;\n #ifdef RENDERER_FOL_IS_RANDOM_TWO\n acc = mix(renderer_FOLMinConst, acc, vec3(a_Random2.x, a_Random2.y, a_Random2.z));\n #endif\n #endif\n #ifdef RENDERER_FOL_CURVE_MODE\n acc = vec3(\n evaluateParticleCurve(renderer_FOLMaxGradientX, normalizedAge),\n evaluateParticleCurve(renderer_FOLMaxGradientY, normalizedAge),\n evaluateParticleCurve(renderer_FOLMaxGradientZ, normalizedAge)\n );\n #ifdef RENDERER_FOL_IS_RANDOM_TWO\n vec3 minAcc = vec3(\n evaluateParticleCurve(renderer_FOLMinGradientX, normalizedAge),\n evaluateParticleCurve(renderer_FOLMinGradientY, normalizedAge),\n evaluateParticleCurve(renderer_FOLMinGradientZ, normalizedAge)\n );\n acc = mix(minAcc, acc, vec3(a_Random2.x, a_Random2.y, a_Random2.z));\n #endif\n #endif\n #endif\n return acc;\n}\n\nvoid main() {\n float age = renderer_CurrentTime - a_DirectionTime.w;\n float lifetime = a_ShapePositionStartLifeTime.w;\n float normalizedAge = age / lifetime;\n // Clamp to age on the first TF pass: particles emitted mid-frame have age < dt,\n // so using the full dt would over-integrate. Subsequent passes are unaffected (age >= dt).\n float dt = min(renderer_DeltaTime, age);\n\n // normalizedAge < 0.0: stale TF slot whose startTime is from a previous playback (e.g. after StopEmittingAndClear).\n if (normalizedAge >= 1.0 || normalizedAge < 0.0) {\n v_FeedbackPosition = a_FeedbackPosition;\n v_FeedbackVelocity = a_FeedbackVelocity;\n gl_Position = vec4(0.0);\n return;\n }\n\n vec4 worldRotation;\n if (renderer_SimulationSpace == 0) {\n worldRotation = renderer_WorldRotation;\n } else {\n worldRotation = a_SimulationWorldRotation;\n }\n vec4 invWorldRotation = quaternionConjugate(worldRotation);\n\n // Read previous frame state (initialized by CPU on particle birth)\n vec3 localVelocity = a_FeedbackVelocity;\n\n // =====================================================\n // Step 1: Apply velocity module deltas (VOL + FOL + Gravity)\n // =====================================================\n\n // Gravity (world space)\n vec3 gravityDelta = renderer_Gravity * a_Random0.x * dt;\n\n // VOL instantaneous velocity (animated velocity, not persisted)\n vec3 volLocal = vec3(0.0);\n vec3 volWorld = vec3(0.0);\n #ifdef _VOL_MODULE_ENABLED\n vec3 vol = getVOLVelocity(normalizedAge);\n if (renderer_VOLSpace == 0) {\n volLocal = vol;\n } else {\n volWorld = vol;\n }\n #endif\n\n // FOL acceleration → velocity delta (always persisted, like gravity)\n vec3 folDeltaLocal = vec3(0.0);\n #ifdef _FOL_MODULE_ENABLED\n vec3 folAcc = getFOLAcceleration(normalizedAge);\n vec3 folVelDelta = folAcc * dt;\n if (renderer_FOLSpace == 0) {\n folDeltaLocal = folVelDelta;\n } else {\n // World FOL: convert to local and persist, same as gravity\n folDeltaLocal = rotationByQuaternions(folVelDelta, invWorldRotation);\n }\n #endif\n\n // Gravity and FOL contribute to base velocity (persisted, subject to dampen/drag).\n vec3 gravityLocal = rotationByQuaternions(gravityDelta, invWorldRotation);\n localVelocity += folDeltaLocal + gravityLocal;\n\n // =====================================================\n // Step 2 & 3: Dampen (Limit Velocity) + Drag\n // VOL must be projected into the LVL target space so that\n // limit/drag see the full velocity regardless of VOL.space vs LVL.space.\n // =====================================================\n #ifdef RENDERER_LVL_MODULE_ENABLED\n // Precompute VOL in both spaces\n vec3 volAsLocal = volLocal + rotationByQuaternions(volWorld, invWorldRotation);\n vec3 volAsWorld = rotationByQuaternions(volLocal, worldRotation) + volWorld;\n\n float limitRand = a_Random2.w;\n float dampen = renderer_LVLDampen;\n // Frame-rate independent dampen (30fps as reference)\n float effectiveDampen = 1.0 - pow(1.0 - dampen, dt * 30.0);\n\n if (renderer_LVLSpace == 0) {\n // Local space: total = base + all VOL projected to local\n vec3 totalLocal = localVelocity + volAsLocal;\n vec3 dampenedTotal = applyLVLSpeedLimitTF(totalLocal, normalizedAge, limitRand, effectiveDampen);\n localVelocity = dampenedTotal - volAsLocal;\n } else {\n // World space: total = rotated base + all VOL projected to world\n vec3 totalWorld = rotationByQuaternions(localVelocity, worldRotation) + volAsWorld;\n vec3 dampenedTotal = applyLVLSpeedLimitTF(totalWorld, normalizedAge, limitRand, effectiveDampen);\n localVelocity = rotationByQuaternions(dampenedTotal - volAsWorld, invWorldRotation);\n }\n\n // Drag: same space as dampen\n {\n float dragCoeff = evaluateLVLDrag(normalizedAge, a_Random2.w);\n if (dragCoeff > 0.0) {\n vec3 totalVel;\n if (renderer_LVLSpace == 0) {\n totalVel = localVelocity + volAsLocal;\n } else {\n totalVel = rotationByQuaternions(localVelocity, worldRotation) + volAsWorld;\n }\n float velMagSqr = dot(totalVel, totalVel);\n float velMag = sqrt(velMagSqr);\n\n float drag = dragCoeff;\n\n #ifdef RENDERER_LVL_DRAG_MULTIPLY_SIZE\n float maxDim = max(a_StartSize.x, max(a_StartSize.y, a_StartSize.z));\n float radius = maxDim * 0.5;\n drag *= 3.14159265 * radius * radius;\n #endif\n\n #ifdef RENDERER_LVL_DRAG_MULTIPLY_VELOCITY\n drag *= velMagSqr;\n #endif\n\n if (velMag > 0.0) {\n float newVelMag = max(0.0, velMag - drag * dt);\n vec3 draggedTotal = totalVel * (newVelMag / velMag);\n if (renderer_LVLSpace == 0) {\n localVelocity = draggedTotal - volAsLocal;\n } else {\n localVelocity = rotationByQuaternions(draggedTotal - volAsWorld, invWorldRotation);\n }\n }\n }\n }\n #endif\n\n // =====================================================\n // Step 4: Integrate position in simulation space\n // Local mode: position in local space, velocity rotated to local\n // World mode: position in world space, velocity rotated to world\n // =====================================================\n // FOL is now fully in localVelocity (both local and world-space FOL).\n // Only VOL overlay needs to be added here.\n vec3 totalVelocity;\n if (renderer_SimulationSpace == 0) {\n // Local: integrate in local space\n totalVelocity = localVelocity + volLocal\n + rotationByQuaternions(volWorld, invWorldRotation);\n } else {\n // World: integrate in world space\n totalVelocity = rotationByQuaternions(localVelocity + volLocal, worldRotation) + volWorld;\n }\n vec3 position = a_FeedbackPosition + totalVelocity * dt;\n\n v_FeedbackPosition = position;\n v_FeedbackVelocity = localVelocity;\n gl_Position = vec4(0.0);\n}\n"; // eslint-disable-line
10482
10495
  var sphere_billboard = "#ifdef RENDERER_MODE_SPHERE_BILLBOARD\n\tvec2 corner = a_CornerTextureCoordinate.xy + renderer_PivotOffset.xy;\n\tvec3 sideVector = normalize(cross(camera_Forward, camera_Up));\n\tvec3 upVector = normalize(cross(sideVector, camera_Forward));\n\tcorner *= computeParticleSizeBillboard(a_StartSize.xy, normalizedAge);\n #if defined(RENDERER_ROL_CONSTANT_MODE) || defined(RENDERER_ROL_CURVE_MODE)\n if (renderer_ThreeDStartRotation) {\n vec3 rotation = radians(vec3(a_StartRotation0.xy, computeParticleRotationFloat(a_StartRotation0.z, age, normalizedAge)));\n center += renderer_SizeScale.xzy * rotationByEuler(corner.x * sideVector + corner.y * upVector, rotation);\n } else {\n float rot = radians(computeParticleRotationFloat(a_StartRotation0.x, age, normalizedAge));\n float c = cos(rot);\n float s = sin(rot);\n mat2 rotation = mat2(c, -s, s, c);\n corner = rotation * corner;\n center += renderer_SizeScale.xzy * (corner.x * sideVector + corner.y * upVector);\n }\n #else\n if (renderer_ThreeDStartRotation) {\n center += renderer_SizeScale.xzy * rotationByEuler(corner.x * sideVector + corner.y * upVector, radians(a_StartRotation0));\n } else {\n float c = cos(radians(a_StartRotation0.x));\n float s = sin(radians(a_StartRotation0.x));\n mat2 rotation = mat2(c, -s, s, c);\n corner = rotation * corner;\n center += renderer_SizeScale.xzy * (corner.x * sideVector + corner.y * upVector);\n }\n #endif\n#endif"; // eslint-disable-line
10483
10496
  var stretched_billboard = "#ifdef RENDERER_MODE_STRETCHED_BILLBOARD\n\tvec2 corner = a_CornerTextureCoordinate.xy + renderer_PivotOffset.xy;\n\tvec3 velocity = rotationByQuaternions(renderer_SizeScale * localVelocity, worldRotation) + worldVelocity;\n\tvec3 cameraUpVector = normalize(velocity);\n\tvec3 direction = normalize(center - camera_Position);\n\tvec3 sideVector = normalize(cross(direction, normalize(velocity)));\n\n\tsideVector = renderer_SizeScale.xzy * sideVector;\n\tcameraUpVector = length(vec3(renderer_SizeScale.x, 0.0, 0.0)) * cameraUpVector;\n\n\tvec2 size = computeParticleSizeBillboard(a_StartSize.xy, normalizedAge);\n\n\tconst mat2 rotationZHalfPI = mat2(0.0, -1.0, 1.0, 0.0);\n\tcorner = rotationZHalfPI * corner;\n\tcorner.y = corner.y - abs(corner.y);\n\n\tfloat speed = length(velocity); // TODO:\n\tcenter += sign(renderer_SizeScale.x) * (sign(renderer_StretchedBillboardLengthScale) * size.x * corner.x * sideVector\n\t + (speed * renderer_StretchedBillboardSpeedScale + size.y * renderer_StretchedBillboardLengthScale) * corner.y * cameraUpVector);\n#endif"; // eslint-disable-line
10484
10497
  var vertical_billboard = "#ifdef RENDERER_MODE_VERTICAL_BILLBOARD\n\tvec2 corner = a_CornerTextureCoordinate.xy + renderer_PivotOffset.xy; // Billboard模式z轴无效\n\tconst vec3 cameraUpVector = vec3(0.0, 1.0, 0.0);\n\tvec3 sideVector = normalize(cross(camera_Forward, cameraUpVector));\n\n\tfloat rot = radians(computeParticleRotationFloat(a_StartRotation0.x, age, normalizedAge));\n\tfloat c = cos(rot);\n\tfloat s = sin(rot);\n\tmat2 rotation = mat2(c, -s, s, c);\n\tcorner = rotation * corner * cos(0.78539816339744830961566084581988); // TODO:临时缩小cos45,不确定U3D原因\n\tcorner *= computeParticleSizeBillboard(a_StartSize.xy, normalizedAge);\n\tcenter += renderer_SizeScale.xzy * (corner.x * sideVector + corner.y * cameraUpVector);\n#endif"; // eslint-disable-line
@@ -10493,7 +10506,6 @@
10493
10506
  texture_sheet_animation_module: texture_sheet_animation_module,
10494
10507
  force_over_lifetime_module: force_over_lifetime_module,
10495
10508
  limit_velocity_over_lifetime_module: limit_velocity_over_lifetime_module,
10496
- noise_module: noise_module,
10497
10509
  particle_feedback_simulation: particle_feedback_simulation,
10498
10510
  sphere_billboard: sphere_billboard,
10499
10511
  stretched_billboard: stretched_billboard,
@@ -10533,7 +10545,21 @@
10533
10545
  begin_viewdir_frag: begin_viewdir_frag,
10534
10546
  mobile_blinnphong_frag: mobile_blinnphong_frag,
10535
10547
  noise_common: noise_common,
10536
- noise_simplex_3D_grad: noise_simplex_3D_grad
10548
+ noise_cellular_2D: noise_cellular_2D,
10549
+ noise_cellular_2x2: noise_cellular_2x2,
10550
+ noise_cellular_2x2x2: noise_cellular_2x2x2,
10551
+ noise_cellular_3D: noise_cellular_3D,
10552
+ noise_cellular: noise_cellular,
10553
+ noise_perlin_2D: noise_perlin_2D,
10554
+ noise_perlin_3D: noise_perlin_3D,
10555
+ noise_perlin_4D: noise_perlin_4D,
10556
+ noise_perlin: noise_perlin,
10557
+ noise_psrd_2D: noise_psrd_2D,
10558
+ noise_simplex_2D: noise_simplex_2D,
10559
+ noise_simplex_3D_grad: noise_simplex_3D_grad,
10560
+ noise_simplex_3D: noise_simplex_3D,
10561
+ noise_simplex_4D: noise_simplex_4D,
10562
+ noise_simplex: noise_simplex
10537
10563
  }, ShadowLib, PBRShaderLib, {
10538
10564
  normal_get: normal_get
10539
10565
  }, ParticleShaderLib);
@@ -28680,13 +28706,6 @@
28680
28706
  if (!splits.length) {
28681
28707
  return this;
28682
28708
  }
28683
- // Some imported animation clips are normalized to include the single scene root
28684
- // name (for example "mixamorig:Hips/..."), while the Animator may already sit on
28685
- // that root entity. Accept a self-name prefix so wrapped model roots and
28686
- // standalone single-root clips resolve through the same path convention.
28687
- if (splits[0] === this.name) {
28688
- return splits.length === 1 ? this : Entity._findChildByName(this, 0, splits, 1);
28689
- }
28690
28709
  return Entity._findChildByName(this, 0, splits, 0);
28691
28710
  };
28692
28711
  /**
@@ -28707,11 +28726,17 @@
28707
28726
  for(var i = children.length - 1; i >= 0; i--){
28708
28727
  var child = children[i];
28709
28728
  child._parent = null;
28729
+ child._siblingIndex = -1;
28730
+ // Dispatch `Child` to the old parent before `_processInActive` (which unregisters
28731
+ // UI listeners via `cleanRootCanvas`), so subscribers such as UICanvas can react
28732
+ // to the hierarchy change while still attached.
28733
+ this._dispatchModify(EntityModifyFlags.Child, this);
28710
28734
  var activeChangeFlag = ActiveChangeFlag.None;
28711
28735
  child._isActiveInHierarchy && (activeChangeFlag |= ActiveChangeFlag.Hierarchy);
28712
28736
  child._isActiveInScene && (activeChangeFlag |= ActiveChangeFlag.Scene);
28713
28737
  activeChangeFlag && child._processInActive(activeChangeFlag);
28714
28738
  Entity._traverseSetOwnerScene(child, null); // Must after child._processInActive().
28739
+ child._setParentChange();
28715
28740
  }
28716
28741
  children.length = 0;
28717
28742
  };
@@ -29639,7 +29664,8 @@
29639
29664
  /** Plain text. */ AssetType["Text"] = "Text";
29640
29665
  /** JSON. */ AssetType["JSON"] = "JSON";
29641
29666
  /** ArrayBuffer. */ AssetType["Buffer"] = "Buffer";
29642
- /** Texture. */ AssetType["Texture"] = "Texture";
29667
+ /** 2D Texture. */ AssetType["Texture2D"] = "Texture2D";
29668
+ /** Cube Texture. */ AssetType["TextureCube"] = "TextureCube";
29643
29669
  /** Material. */ AssetType["Material"] = "Material";
29644
29670
  /** Shader. */ AssetType["Shader"] = "Shader";
29645
29671
  /** Mesh. */ AssetType["Mesh"] = "Mesh";
@@ -29799,7 +29825,20 @@
29799
29825
  */ _proto.loadScene = function loadScene(url, destroyOldScene) {
29800
29826
  var _this = this;
29801
29827
  if (destroyOldScene === void 0) destroyOldScene = true;
29802
- var scenePromise = this.engine.resourceManager.load({
29828
+ var resourceManager = this.engine.resourceManager;
29829
+ // Evict the Scene asset cache for managed scenes about to be destroyed, so a fresh Scene
29830
+ // instance is created by the loader instead of returning the same instance we're about to
29831
+ // destroy (self-destroy would leave the active scene in a zombie state).
29832
+ if (destroyOldScene) {
29833
+ var _resourceManager__virtualPathResourceMap_url;
29834
+ var _resourceManager__virtualPathResourceMap_url_path;
29835
+ var realPath = (_resourceManager__virtualPathResourceMap_url_path = (_resourceManager__virtualPathResourceMap_url = resourceManager._virtualPathResourceMap[url]) == null ? void 0 : _resourceManager__virtualPathResourceMap_url.path) != null ? _resourceManager__virtualPathResourceMap_url_path : url;
29836
+ var cached = resourceManager.getFromCache(realPath);
29837
+ if (cached && this._scenes.indexOf(cached) !== -1) {
29838
+ resourceManager._deleteAsset(cached);
29839
+ }
29840
+ }
29841
+ var scenePromise = resourceManager.load({
29803
29842
  url: url,
29804
29843
  type: AssetType.Scene
29805
29844
  });
@@ -31838,14 +31877,14 @@
31838
31877
  var depthOnlyFs = "void main() {\n}"; // eslint-disable-line
31839
31878
  var depthOnlyVs = "#define MATERIAL_OMIT_NORMAL\n#include <common>\n#include <common_vert>\n#include <blendShape_input>\nuniform mat4 camera_VPMat;\n\n\nvoid main() {\n\n #include <begin_position_vert>\n #include <blendShape_vert>\n #include <skinning_vert>\n #include <position_vert>\n\n}\n"; // eslint-disable-line
31840
31879
  var particleFs = "#include <common>\n\nvarying vec4 v_Color;\nvarying vec2 v_TextureCoordinate;\nuniform sampler2D material_BaseTexture;\nuniform vec4 material_BaseColor;\n \nuniform mediump vec3 material_EmissiveColor;\n#ifdef MATERIAL_HAS_EMISSIVETEXTURE\n uniform sampler2D material_EmissiveTexture;\n#endif\n\n#ifdef RENDERER_MODE_MESH\n\tvarying vec4 v_MeshColor;\n#endif\n\nvoid main() {\n\tvec4 color = material_BaseColor * v_Color;\n\n\t#if defined(RENDERER_MODE_MESH) && defined(RENDERER_ENABLE_VERTEXCOLOR)\n\t\tcolor *= v_MeshColor;\n\t#endif\n\n\t#ifdef MATERIAL_HAS_BASETEXTURE\n\t\tcolor *= texture2DSRGB(material_BaseTexture, v_TextureCoordinate);\n\t#endif\n\t\n\t// Emissive\n\tvec3 emissiveRadiance = material_EmissiveColor;\n\t#ifdef MATERIAL_HAS_EMISSIVETEXTURE\n\t\temissiveRadiance *= texture2DSRGB(material_EmissiveTexture, v_TextureCoordinate).rgb;\n\t#endif\n\n\tcolor.rgb += emissiveRadiance;\n\n\tgl_FragColor = color;\n}"; // eslint-disable-line
31841
- var particleVs = "#if defined(RENDERER_MODE_SPHERE_BILLBOARD) || defined(RENDERER_MODE_STRETCHED_BILLBOARD) || defined(RENDERER_MODE_HORIZONTAL_BILLBOARD) || defined(RENDERER_MODE_VERTICAL_BILLBOARD)\n attribute vec4 a_CornerTextureCoordinate;\n#endif\n\n#ifdef RENDERER_MODE_MESH\n attribute vec3 POSITION;\n #ifdef RENDERER_ENABLE_VERTEXCOLOR\n attribute vec4 COLOR_0;\n #endif\n attribute vec2 TEXCOORD_0;\n varying vec4 v_MeshColor;\n#endif\n\nattribute vec4 a_ShapePositionStartLifeTime;\nattribute vec4 a_DirectionTime;\nattribute vec4 a_StartColor;\nattribute vec3 a_StartSize;\nattribute vec3 a_StartRotation0;\nattribute float a_StartSpeed;\n\n//#if defined(COLOR_OVER_LIFETIME) || defined(RENDERER_COL_RANDOM_GRADIENTS) || defined(RENDERER_SOL_RANDOM_CURVES) || defined(RENDERER_SOL_RANDOM_CURVES_SEPARATE) || defined(ROTATION_OVER_LIFE_TIME_RANDOM_CONSTANTS) || defined(ROTATION_OVER_LIFETIME_RANDOM_CURVES)\n attribute vec4 a_Random0;\n//#endif\n\n#if defined(RENDERER_TSA_FRAME_RANDOM_CURVES) || defined(RENDERER_VOL_IS_RANDOM_TWO)\n attribute vec4 a_Random1; // x:texture sheet animation random\n#endif\n\n#if defined(RENDERER_FOL_CONSTANT_MODE) || defined(RENDERER_FOL_CURVE_MODE) || defined(RENDERER_LVL_MODULE_ENABLED)\n attribute vec4 a_Random2;\n#endif\n\nattribute vec3 a_SimulationWorldPosition;\nattribute vec4 a_SimulationWorldRotation;\n\n#ifdef RENDERER_TRANSFORM_FEEDBACK\n attribute vec3 a_FeedbackPosition;\n attribute vec3 a_FeedbackVelocity;\n#endif\n\nvarying vec4 v_Color;\n#ifdef MATERIAL_HAS_BASETEXTURE\n attribute vec4 a_SimulationUV;\n varying vec2 v_TextureCoordinate;\n#endif\n\nuniform float renderer_CurrentTime;\nuniform vec3 renderer_Gravity;\nuniform vec3 renderer_WorldPosition;\nuniform vec4 renderer_WorldRotation;\nuniform bool renderer_ThreeDStartRotation;\nuniform int renderer_ScalingMode;\nuniform vec3 renderer_PositionScale;\nuniform vec3 renderer_SizeScale;\nuniform vec3 renderer_PivotOffset;\n\nuniform mat4 camera_ViewMat;\nuniform mat4 camera_ProjMat;\n\n#ifdef RENDERER_MODE_STRETCHED_BILLBOARD\n uniform vec3 camera_Position;\n#endif\nuniform vec3 camera_Forward; // TODO:只有几种广告牌模式需要用\nuniform vec3 camera_Up;\n\nuniform float renderer_StretchedBillboardLengthScale;\nuniform float renderer_StretchedBillboardSpeedScale;\nuniform int renderer_SimulationSpace;\n\n#include <particle_common>\n#include <velocity_over_lifetime_module>\n#include <force_over_lifetime_module>\n#include <color_over_lifetime_module>\n#include <size_over_lifetime_module>\n#include <rotation_over_lifetime_module>\n#include <texture_sheet_animation_module>\n#include <noise_module>\n\nvec3 computeParticlePosition(in vec3 startVelocity, in float age, in float normalizedAge, vec3 gravityVelocity, vec4 worldRotation, inout vec3 localVelocity, inout vec3 worldVelocity) {\n vec3 startPosition = startVelocity * age;\n\n vec3 finalPosition;\n vec3 localPositionOffset = startPosition;\n vec3 worldPositionOffset;\n\n #ifdef _VOL_MODULE_ENABLED\n vec3 lifeVelocity; \n vec3 velocityPositionOffset = computeVelocityPositionOffset(normalizedAge, age, lifeVelocity);\n if (renderer_VOLSpace == 0) {\n localVelocity += lifeVelocity;\n localPositionOffset += velocityPositionOffset;\n } else {\n worldVelocity += lifeVelocity;\n worldPositionOffset += velocityPositionOffset;\n }\n #endif\n\n #ifdef _FOL_MODULE_ENABLED\n vec3 forceVelocity;\n vec3 forcePositionOffset = computeForcePositionOffset(normalizedAge, age, forceVelocity);\n if (renderer_FOLSpace == 0) {\n localVelocity += forceVelocity;\n localPositionOffset += forcePositionOffset;\n } else {\n worldVelocity += forceVelocity;\n worldPositionOffset += forcePositionOffset;\n }\n #endif\n\n finalPosition = rotationByQuaternions(a_ShapePositionStartLifeTime.xyz + localPositionOffset, worldRotation) + worldPositionOffset;\n\n if (renderer_SimulationSpace == 0) {\n finalPosition = finalPosition + renderer_WorldPosition;\n } else if (renderer_SimulationSpace == 1) {\n\t finalPosition = finalPosition + a_SimulationWorldPosition;\n\t}\n\n finalPosition += 0.5 * gravityVelocity * age;\n\n return finalPosition;\n}\n\nvoid main() {\n float age = renderer_CurrentTime - a_DirectionTime.w;\n float normalizedAge = age / a_ShapePositionStartLifeTime.w;\n // normalizedAge >= 0.0: skip stale TF slots whose startTime is from a previous playback (e.g. after StopEmittingAndClear).\n if (normalizedAge >= 0.0 && normalizedAge < 1.0) {\n vec4 worldRotation;\n if (renderer_SimulationSpace == 0) {\n worldRotation = renderer_WorldRotation;\n } else {\n worldRotation = a_SimulationWorldRotation;\n }\n\n vec3 localVelocity;\n vec3 worldVelocity;\n\n #ifdef RENDERER_TRANSFORM_FEEDBACK\n // Transform Feedback mode: position in simulation space (local or world).\n // Local: transform to world; World: use directly.\n vec3 center;\n if (renderer_SimulationSpace == 0) {\n center = rotationByQuaternions(a_FeedbackPosition, worldRotation) + renderer_WorldPosition;\n } else if (renderer_SimulationSpace == 1) {\n center = a_FeedbackPosition;\n }\n localVelocity = a_FeedbackVelocity;\n worldVelocity = vec3(0.0);\n\n #ifdef _VOL_MODULE_ENABLED\n vec3 instantVOLVelocity;\n computeVelocityPositionOffset(normalizedAge, age, instantVOLVelocity);\n if (renderer_VOLSpace == 0) {\n localVelocity += instantVOLVelocity;\n } else {\n worldVelocity += instantVOLVelocity;\n }\n #endif\n #else\n // Original analytical path\n vec3 startVelocity = a_DirectionTime.xyz * a_StartSpeed;\n vec3 gravityVelocity = renderer_Gravity * a_Random0.x * age;\n localVelocity = startVelocity;\n worldVelocity = gravityVelocity;\n vec3 center = computeParticlePosition(startVelocity, age, normalizedAge, gravityVelocity, worldRotation, localVelocity, worldVelocity);\n #endif\n\n #include <sphere_billboard>\n #include <stretched_billboard>\n #include <horizontal_billboard>\n #include <vertical_billboard>\n #include <particle_mesh>\n\n gl_Position = camera_ProjMat * camera_ViewMat * vec4(center, 1.0);\n v_Color = computeParticleColor(a_StartColor, normalizedAge);\n\n #ifdef MATERIAL_HAS_BASETEXTURE\n vec2 simulateUV;\n #if defined(RENDERER_MODE_SPHERE_BILLBOARD) || defined(RENDERER_MODE_STRETCHED_BILLBOARD) || defined(RENDERER_MODE_HORIZONTAL_BILLBOARD) || defined(RENDERER_MODE_VERTICAL_BILLBOARD)\n simulateUV = a_CornerTextureCoordinate.zw * a_SimulationUV.xy + a_SimulationUV.zw;\n v_TextureCoordinate = computeParticleUV(simulateUV, normalizedAge);\n #endif\n #ifdef RENDERER_MODE_MESH\n simulateUV = a_SimulationUV.zw + TEXCOORD_0 * a_SimulationUV.xy;\n v_TextureCoordinate = computeParticleUV(simulateUV, normalizedAge);\n #endif\n #endif\n } else {\n\t gl_Position = vec4(2.0, 2.0, 2.0, 1.0); // Discard use out of X(-1,1),Y(-1,1),Z(0,1)\n }\n}"; // eslint-disable-line
31880
+ var particleVs = "#if defined(RENDERER_MODE_SPHERE_BILLBOARD) || defined(RENDERER_MODE_STRETCHED_BILLBOARD) || defined(RENDERER_MODE_HORIZONTAL_BILLBOARD) || defined(RENDERER_MODE_VERTICAL_BILLBOARD)\n attribute vec4 a_CornerTextureCoordinate;\n#endif\n\n#ifdef RENDERER_MODE_MESH\n attribute vec3 POSITION;\n #ifdef RENDERER_ENABLE_VERTEXCOLOR\n attribute vec4 COLOR_0;\n #endif\n attribute vec2 TEXCOORD_0;\n varying vec4 v_MeshColor;\n#endif\n\nattribute vec4 a_ShapePositionStartLifeTime;\nattribute vec4 a_DirectionTime;\nattribute vec4 a_StartColor;\nattribute vec3 a_StartSize;\nattribute vec3 a_StartRotation0;\nattribute float a_StartSpeed;\n\n//#if defined(COLOR_OVER_LIFETIME) || defined(RENDERER_COL_RANDOM_GRADIENTS) || defined(RENDERER_SOL_RANDOM_CURVES) || defined(RENDERER_SOL_RANDOM_CURVES_SEPARATE) || defined(ROTATION_OVER_LIFE_TIME_RANDOM_CONSTANTS) || defined(ROTATION_OVER_LIFETIME_RANDOM_CURVES)\n attribute vec4 a_Random0;\n//#endif\n\n#if defined(RENDERER_TSA_FRAME_RANDOM_CURVES) || defined(RENDERER_VOL_IS_RANDOM_TWO)\n attribute vec4 a_Random1; // x:texture sheet animation random\n#endif\n\n#if defined(RENDERER_FOL_CONSTANT_MODE) || defined(RENDERER_FOL_CURVE_MODE) || defined(RENDERER_LVL_MODULE_ENABLED)\n attribute vec4 a_Random2;\n#endif\n\nattribute vec3 a_SimulationWorldPosition;\nattribute vec4 a_SimulationWorldRotation;\n\n#ifdef RENDERER_TRANSFORM_FEEDBACK\n attribute vec3 a_FeedbackPosition;\n attribute vec3 a_FeedbackVelocity;\n#endif\n\nvarying vec4 v_Color;\n#ifdef MATERIAL_HAS_BASETEXTURE\n attribute vec4 a_SimulationUV;\n varying vec2 v_TextureCoordinate;\n#endif\n\nuniform float renderer_CurrentTime;\nuniform vec3 renderer_Gravity;\nuniform vec3 renderer_WorldPosition;\nuniform vec4 renderer_WorldRotation;\nuniform bool renderer_ThreeDStartRotation;\nuniform int renderer_ScalingMode;\nuniform vec3 renderer_PositionScale;\nuniform vec3 renderer_SizeScale;\nuniform vec3 renderer_PivotOffset;\n\nuniform mat4 camera_ViewMat;\nuniform mat4 camera_ProjMat;\n\n#ifdef RENDERER_MODE_STRETCHED_BILLBOARD\n uniform vec3 camera_Position;\n#endif\nuniform vec3 camera_Forward; // TODO:只有几种广告牌模式需要用\nuniform vec3 camera_Up;\n\nuniform float renderer_StretchedBillboardLengthScale;\nuniform float renderer_StretchedBillboardSpeedScale;\nuniform int renderer_SimulationSpace;\n\n#include <particle_common>\n#include <velocity_over_lifetime_module>\n#include <force_over_lifetime_module>\n#include <color_over_lifetime_module>\n#include <size_over_lifetime_module>\n#include <rotation_over_lifetime_module>\n#include <texture_sheet_animation_module>\n\nvec3 computeParticlePosition(in vec3 startVelocity, in float age, in float normalizedAge, vec3 gravityVelocity, vec4 worldRotation, inout vec3 localVelocity, inout vec3 worldVelocity) {\n vec3 startPosition = startVelocity * age;\n\n vec3 finalPosition;\n vec3 localPositionOffset = startPosition;\n vec3 worldPositionOffset;\n\n #ifdef _VOL_MODULE_ENABLED\n vec3 lifeVelocity; \n vec3 velocityPositionOffset = computeVelocityPositionOffset(normalizedAge, age, lifeVelocity);\n if (renderer_VOLSpace == 0) {\n localVelocity += lifeVelocity;\n localPositionOffset += velocityPositionOffset;\n } else {\n worldVelocity += lifeVelocity;\n worldPositionOffset += velocityPositionOffset;\n }\n #endif\n\n #ifdef _FOL_MODULE_ENABLED\n vec3 forceVelocity;\n vec3 forcePositionOffset = computeForcePositionOffset(normalizedAge, age, forceVelocity);\n if (renderer_FOLSpace == 0) {\n localVelocity += forceVelocity;\n localPositionOffset += forcePositionOffset;\n } else {\n worldVelocity += forceVelocity;\n worldPositionOffset += forcePositionOffset;\n }\n #endif\n\n finalPosition = rotationByQuaternions(a_ShapePositionStartLifeTime.xyz + localPositionOffset, worldRotation) + worldPositionOffset;\n\n if (renderer_SimulationSpace == 0) {\n finalPosition = finalPosition + renderer_WorldPosition;\n } else if (renderer_SimulationSpace == 1) {\n\t finalPosition = finalPosition + a_SimulationWorldPosition;\n\t}\n\n finalPosition += 0.5 * gravityVelocity * age;\n\n return finalPosition;\n}\n\nvoid main() {\n float age = renderer_CurrentTime - a_DirectionTime.w;\n float normalizedAge = age / a_ShapePositionStartLifeTime.w;\n // normalizedAge >= 0.0: skip stale TF slots whose startTime is from a previous playback (e.g. after StopEmittingAndClear).\n if (normalizedAge >= 0.0 && normalizedAge < 1.0) {\n vec4 worldRotation;\n if (renderer_SimulationSpace == 0) {\n worldRotation = renderer_WorldRotation;\n } else {\n worldRotation = a_SimulationWorldRotation;\n }\n\n vec3 localVelocity;\n vec3 worldVelocity;\n\n #ifdef RENDERER_TRANSFORM_FEEDBACK\n // Transform Feedback mode: position in simulation space (local or world).\n // Local: transform to world; World: use directly.\n vec3 center;\n if (renderer_SimulationSpace == 0) {\n center = rotationByQuaternions(a_FeedbackPosition, worldRotation) + renderer_WorldPosition;\n } else if (renderer_SimulationSpace == 1) {\n center = a_FeedbackPosition;\n }\n localVelocity = a_FeedbackVelocity;\n worldVelocity = vec3(0.0);\n\n #ifdef _VOL_MODULE_ENABLED\n vec3 instantVOLVelocity;\n computeVelocityPositionOffset(normalizedAge, age, instantVOLVelocity);\n if (renderer_VOLSpace == 0) {\n localVelocity += instantVOLVelocity;\n } else {\n worldVelocity += instantVOLVelocity;\n }\n #endif\n #else\n // Original analytical path\n vec3 startVelocity = a_DirectionTime.xyz * a_StartSpeed;\n vec3 gravityVelocity = renderer_Gravity * a_Random0.x * age;\n localVelocity = startVelocity;\n worldVelocity = gravityVelocity;\n vec3 center = computeParticlePosition(startVelocity, age, normalizedAge, gravityVelocity, worldRotation, localVelocity, worldVelocity);\n #endif\n\n #include <sphere_billboard>\n #include <stretched_billboard>\n #include <horizontal_billboard>\n #include <vertical_billboard>\n #include <particle_mesh>\n\n gl_Position = camera_ProjMat * camera_ViewMat * vec4(center, 1.0);\n v_Color = computeParticleColor(a_StartColor, normalizedAge);\n\n #ifdef MATERIAL_HAS_BASETEXTURE\n vec2 simulateUV;\n #if defined(RENDERER_MODE_SPHERE_BILLBOARD) || defined(RENDERER_MODE_STRETCHED_BILLBOARD) || defined(RENDERER_MODE_HORIZONTAL_BILLBOARD) || defined(RENDERER_MODE_VERTICAL_BILLBOARD)\n simulateUV = a_CornerTextureCoordinate.zw * a_SimulationUV.xy + a_SimulationUV.zw;\n v_TextureCoordinate = computeParticleUV(simulateUV, normalizedAge);\n #endif\n #ifdef RENDERER_MODE_MESH\n simulateUV = a_SimulationUV.zw + TEXCOORD_0 * a_SimulationUV.xy;\n v_TextureCoordinate = computeParticleUV(simulateUV, normalizedAge);\n #endif\n #endif\n } else {\n\t gl_Position = vec4(2.0, 2.0, 2.0, 1.0); // Discard use out of X(-1,1),Y(-1,1),Z(0,1)\n }\n}"; // eslint-disable-line
31842
31881
  var pbrSpecularFs = "#include <common>\n#include <camera_declare>\n\n#include <FogFragmentDeclaration>\n\n#include <uv_share>\n#include <normal_share>\n#include <color_share>\n#include <worldpos_share>\n\n#include <light_frag_define>\n\n\n#include <pbr_frag_define>\n#include <pbr_helper>\n\nvoid main() {\n #include <pbr_frag>\n #include <FogFragment>\n}\n"; // eslint-disable-line
31843
31882
  var pbrFs = "#include <common>\n#include <camera_declare>\n#include <transform_declare>\n\n#include <FogFragmentDeclaration>\n#include <PositionClipSpaceDeclaration>\n\n#include <uv_share>\n#include <normal_share>\n#include <color_share>\n#include <worldpos_share>\n\n#include <light_frag_define>\n\n#include <pbr_frag_define>\n#include <pbr_helper>\n\nvoid main() {\n #include <pbr_frag>\n #include <FogFragment>\n}\n"; // eslint-disable-line
31844
31883
  var pbrVs = "#include <common>\n#include <common_vert>\n#include <blendShape_input>\n#include <uv_share>\n#include <color_share>\n#include <normal_share>\n#include <worldpos_share>\n\n#include <ShadowVertexDeclaration>\n#include <FogVertexDeclaration>\n#include <PositionClipSpaceDeclaration>\n\nvoid main() {\n\n #include <begin_position_vert>\n #include <begin_normal_vert>\n #include <blendShape_vert>\n #include <skinning_vert>\n #include <uv_vert>\n #include <color_vert>\n #include <normal_vert>\n #include <worldpos_vert>\n #include <position_vert>\n\n #include <ShadowVertex>\n #include <FogVertex>\n #include <PositionClipSpaceVertex>\n}\n"; // eslint-disable-line
31845
31884
  var shadowMapFs = "#ifdef ENGINE_NO_DEPTH_TEXTURE\n /**\n * Decompose and save depth value.\n */\n vec4 pack (float depth) {\n // Use rgba 4 bytes with a total of 32 bits to store the z value, and the accuracy of 1 byte is 1/256.\n const vec4 bitShift = vec4(1.0, 256.0, 256.0 * 256.0, 256.0 * 256.0 * 256.0);\n const vec4 bitMask = vec4(1.0/256.0, 1.0/256.0, 1.0/256.0, 0.0);\n\n vec4 rgbaDepth = fract(depth * bitShift); // Calculate the z value of each point\n\n // Cut off the value which do not fit in 8 bits\n rgbaDepth -= rgbaDepth.gbaa * bitMask;\n\n return rgbaDepth;\n }\n#endif\n\n\nuniform vec4 material_BaseColor;\nuniform sampler2D material_BaseTexture;\nuniform float material_AlphaCutoff;\nvarying vec2 v_uv;\n\nvoid main() {\n #if defined(MATERIAL_IS_ALPHA_CUTOFF) || (defined(SCENE_ENABLE_TRANSPARENT_SHADOW) && defined(MATERIAL_IS_TRANSPARENT))\n float alpha = material_BaseColor.a;\n #ifdef MATERIAL_HAS_BASETEXTURE\n alpha *= texture2D(material_BaseTexture, v_uv).a;\n #endif\n \n #ifdef MATERIAL_IS_ALPHA_CUTOFF\n if(alpha < material_AlphaCutoff){\n discard;\n }\n #endif\n \n #if defined(SCENE_ENABLE_TRANSPARENT_SHADOW) && defined(MATERIAL_IS_TRANSPARENT)\n // Interleaved gradient noise\n float noise = fract(52.982919 * fract(dot(vec2(0.06711, 0.00584), gl_FragCoord.xy)));\n if (alpha <= noise) {\n discard;\n };\n #endif\n #endif\n\n #ifdef ENGINE_NO_DEPTH_TEXTURE\n gl_FragColor = pack(gl_FragCoord.z);\n #else\n gl_FragColor = vec4(0.0, 0.0, 0.0, 0.0);\n #endif\n}"; // eslint-disable-line
31846
31885
  var shadowMapVs = "#include <common>\n#include <common_vert>\n#include <blendShape_input>\n#include <normal_share>\n#include <uv_share>\nuniform mat4 camera_VPMat;\nuniform vec2 scene_ShadowBias; // x: depth bias, y: normal bias\nuniform vec3 scene_LightDirection;\n\nvec3 applyShadowBias(vec3 positionWS) {\n positionWS -= scene_LightDirection * scene_ShadowBias.x;\n return positionWS;\n}\n\nvec3 applyShadowNormalBias(vec3 positionWS, vec3 normalWS) {\n float invNdotL = 1.0 - clamp(dot(-scene_LightDirection, normalWS), 0.0, 1.0);\n float scale = invNdotL * scene_ShadowBias.y;\n positionWS += normalWS * vec3(scale);\n return positionWS;\n}\n\nvoid main() {\n\n #include <begin_position_vert>\n #include <begin_normal_vert>\n #include <blendShape_vert>\n #include <skinning_vert>\n #include <uv_vert>\n \n vec4 positionWS = renderer_ModelMat * position;\n\n positionWS.xyz = applyShadowBias(positionWS.xyz);\n #ifndef MATERIAL_OMIT_NORMAL\n #ifdef RENDERER_HAS_NORMAL\n vec3 normalWS = normalize( mat3(renderer_NormalMat) * normal );\n positionWS.xyz = applyShadowNormalBias(positionWS.xyz, normalWS);\n #endif\n #endif\n\n\n vec4 positionCS = camera_VPMat * positionWS;\n positionCS.z = max(positionCS.z, -1.0);// clamp to min ndc z\n\n gl_Position = positionCS;\n\n}\n"; // eslint-disable-line
31847
31886
  var skyboxFs = "#include <common>\nuniform samplerCube material_CubeTexture;\n\nvarying vec3 v_cubeUV;\nuniform float material_Exposure;\nuniform vec4 material_TintColor;\n\nvoid main() {\n vec4 textureColor = textureCube( material_CubeTexture, v_cubeUV );\n\n #ifdef ENGINE_NO_SRGB\n textureColor = sRGBToLinear(textureColor);\n #endif\n\n textureColor.rgb *= material_Exposure * material_TintColor.rgb;\n \n gl_FragColor = textureColor;\n}\n"; // eslint-disable-line
31848
- var skyboxVs = "#include <common_vert>\n\nuniform mat4 camera_VPMat;\n\nvarying vec3 v_cubeUV;\nuniform float material_Rotation;\n\nvec4 rotateY(vec4 v, float angle) {\n\tconst float deg2rad = 3.1415926 / 180.0;\n\tfloat radian = angle * deg2rad;\n\tfloat sina = sin(radian);\n\tfloat cosa = cos(radian);\n\tmat2 m = mat2(cosa, -sina, sina, cosa);\n\treturn vec4(m * v.xz, v.yw).xzyw;\n}\n\nvoid main() {\n v_cubeUV = POSITION;\n gl_Position = camera_VPMat * rotateY(vec4(POSITION, 1.0), material_Rotation);\n}\n"; // eslint-disable-line
31887
+ var skyboxVs = "#include <common_vert>\n\nuniform mat4 camera_VPMat;\n\nvarying vec3 v_cubeUV;\nuniform float material_Rotation;\n\nvec4 rotateY(vec4 v, float angle) {\n\tconst float deg2rad = 3.1415926 / 180.0;\n\tfloat radian = angle * deg2rad;\n\tfloat sina = sin(radian);\n\tfloat cosa = cos(radian);\n\tmat2 m = mat2(cosa, -sina, sina, cosa);\n\treturn vec4(m * v.xz, v.yw).xzyw;\n}\n\nvoid main() {\n v_cubeUV = vec3( -POSITION.x, POSITION.yz ); // TextureCube is left-hand,so x need inverse\n gl_Position = camera_VPMat * rotateY(vec4(POSITION, 1.0), material_Rotation);\n}\n"; // eslint-disable-line
31849
31888
  var spriteMaskFs = "uniform sampler2D renderer_MaskTexture;\nuniform float renderer_MaskAlphaCutoff;\nvarying vec2 v_uv;\n\nvoid main()\n{\n vec4 color = texture2D(renderer_MaskTexture, v_uv);\n if (color.a < renderer_MaskAlphaCutoff) {\n discard;\n }\n\n gl_FragColor = color;\n}\n"; // eslint-disable-line
31850
31889
  var spriteMaskVs = "uniform mat4 camera_VPMat;\n\nattribute vec3 POSITION;\nattribute vec2 TEXCOORD_0;\n\nvarying vec2 v_uv;\n\nvoid main()\n{\n gl_Position = camera_VPMat * vec4(POSITION, 1.0);\n v_uv = TEXCOORD_0;\n}\n"; // eslint-disable-line
31851
31890
  var spriteFs = "#include <common>\nuniform sampler2D renderer_SpriteTexture;\n\nvarying vec2 v_uv;\nvarying vec4 v_color;\n\nvoid main()\n{\n vec4 baseColor = texture2DSRGB(renderer_SpriteTexture, v_uv);\n gl_FragColor = baseColor * v_color;\n}\n"; // eslint-disable-line
@@ -39290,7 +39329,6 @@
39290
39329
  ParticleRandomSubSeeds[ParticleRandomSubSeeds["GravityModifier"] = 2759560269] = "GravityModifier";
39291
39330
  ParticleRandomSubSeeds[ParticleRandomSubSeeds["ForceOverLifetime"] = 3875246972] = "ForceOverLifetime";
39292
39331
  ParticleRandomSubSeeds[ParticleRandomSubSeeds["LimitVelocityOverLifetime"] = 3047300990] = "LimitVelocityOverLifetime";
39293
- ParticleRandomSubSeeds[ParticleRandomSubSeeds["Noise"] = 4105357473] = "Noise";
39294
39332
  return ParticleRandomSubSeeds;
39295
39333
  }({});
39296
39334
  /**
@@ -40080,48 +40118,30 @@
40080
40118
  }
40081
40119
  this._emitBySubBurst(middleTime, playTime, duration);
40082
40120
  } else {
40083
- if (lastPlayTime < duration) {
40084
- this._emitBySubBurst(lastPlayTime, Math.min(playTime, duration), duration);
40085
- }
40121
+ this._emitBySubBurst(lastPlayTime, playTime, duration);
40086
40122
  }
40087
40123
  };
40088
40124
  _proto._emitBySubBurst = function _emitBySubBurst(lastPlayTime, playTime, duration) {
40089
- var _this = this, generator = _this._generator, rand = _this._burstRand, bursts = _this.bursts;
40125
+ var generator = this._generator;
40126
+ var rand = this._burstRand;
40127
+ var bursts = this.bursts;
40128
+ // Calculate the relative time of the burst
40090
40129
  var baseTime = Math.floor(lastPlayTime / duration) * duration;
40091
40130
  var startTime = lastPlayTime % duration;
40092
40131
  var endTime = startTime + (playTime - lastPlayTime);
40093
- var pendingIndex = -1;
40094
40132
  var index = this._currentBurstIndex;
40095
40133
  for(var n = bursts.length; index < n; index++){
40096
40134
  var burst = bursts[index];
40097
40135
  var burstTime = burst.time;
40098
- if (burstTime >= endTime) break;
40099
- var cycles = burst.cycles, repeatInterval = burst.repeatInterval;
40100
- if (cycles === 1) {
40101
- if (burstTime >= startTime) {
40102
- generator._emit(baseTime + burstTime, burst.count.evaluate(undefined, rand.random()));
40103
- }
40104
- } else {
40105
- var maxCycles = cycles === Infinity ? Math.ceil((duration - burstTime) / repeatInterval) : cycles;
40106
- // Absorb float drift: (startTime - burstTime) / repeatInterval may land at cycle + 1e-15
40107
- // when it should be exactly cycle, and ceil would then skip ahead to cycle + 1.
40108
- var tolerance = MathUtil.zeroTolerance;
40109
- var lastCycle = Math.ceil((endTime - burstTime) / repeatInterval - tolerance) - 1;
40110
- var first = Math.max(0, Math.ceil((startTime - burstTime) / repeatInterval - tolerance));
40111
- var last = Math.min(maxCycles - 1, lastCycle);
40112
- for(var c = first; c <= last; c++){
40113
- var effectiveTime = burstTime + c * repeatInterval;
40114
- if (effectiveTime >= duration) break;
40115
- generator._emit(baseTime + effectiveTime, burst.count.evaluate(undefined, rand.random()));
40116
- }
40117
- // `_currentBurstIndex` caches next frame's scan start, so only the earliest unfinished
40118
- // burst can be the entry point — skipping past it would drop its remaining cycles
40119
- if (pendingIndex < 0 && lastCycle < maxCycles - 1) {
40120
- pendingIndex = index;
40121
- }
40136
+ if (burstTime > endTime) {
40137
+ break;
40138
+ }
40139
+ if (burstTime >= startTime) {
40140
+ var count = burst.count.evaluate(undefined, rand.random());
40141
+ generator._emit(baseTime + burstTime, count);
40122
40142
  }
40123
40143
  }
40124
- this._currentBurstIndex = pendingIndex >= 0 ? pendingIndex : index;
40144
+ this._currentBurstIndex = index;
40125
40145
  };
40126
40146
  _create_class$2(EmissionModule, [
40127
40147
  {
@@ -40684,7 +40704,7 @@
40684
40704
  return;
40685
40705
  }
40686
40706
  this._enabled = value;
40687
- this._generator._setTransformFeedback();
40707
+ this._generator._setTransformFeedback(value);
40688
40708
  this._generator._renderer._onGeneratorParamsChanged();
40689
40709
  }
40690
40710
  }
@@ -40769,9 +40789,9 @@
40769
40789
  /**
40770
40790
  * Control how Particle Generator apply transform scale.
40771
40791
  */ var ParticleScaleMode = /*#__PURE__*/ function(ParticleScaleMode) {
40772
- /** Scale the Particle Generator using the world scale, including all parent transforms. */ ParticleScaleMode[ParticleScaleMode["World"] = 0] = "World";
40773
- /** Scale the Particle Generator using only its own transform scale, ignoring parent scale. */ ParticleScaleMode[ParticleScaleMode["Local"] = 1] = "Local";
40774
- /** Scale only the emitter shape positions; particle size and movement are unaffected. */ ParticleScaleMode[ParticleScaleMode["Shape"] = 2] = "Shape";
40792
+ /** Scale the Particle Generator using the entire transform hierarchy. */ ParticleScaleMode[ParticleScaleMode["Hierarchy"] = 0] = "Hierarchy";
40793
+ /** Scale the Particle Generator using only its own transform scale. (Ignores parent scale). */ ParticleScaleMode[ParticleScaleMode["Local"] = 1] = "Local";
40794
+ /** Only apply transform scale to the shape component, which controls where particles are spawned, but does not affect their size or movement. */ ParticleScaleMode[ParticleScaleMode["World"] = 2] = "World";
40775
40795
  return ParticleScaleMode;
40776
40796
  }({});
40777
40797
  var MainModule = /*#__PURE__*/ function() {
@@ -40822,8 +40842,8 @@
40822
40842
  */ _proto._getPositionScale = function _getPositionScale() {
40823
40843
  var transform = this._generator._renderer.entity.transform;
40824
40844
  switch(this.scalingMode){
40845
+ case ParticleScaleMode.Hierarchy:
40825
40846
  case ParticleScaleMode.World:
40826
- case ParticleScaleMode.Shape:
40827
40847
  return transform.lossyWorldScale;
40828
40848
  case ParticleScaleMode.Local:
40829
40849
  return transform.scale;
@@ -40847,7 +40867,7 @@
40847
40867
  throw new Error("ParticleRenderer: SimulationSpace value is invalid.");
40848
40868
  }
40849
40869
  switch(this.scalingMode){
40850
- case ParticleScaleMode.World:
40870
+ case ParticleScaleMode.Hierarchy:
40851
40871
  var scale = transform.lossyWorldScale;
40852
40872
  shaderData.setVector3(MainModule._positionScale, scale);
40853
40873
  shaderData.setVector3(MainModule._sizeScale, scale);
@@ -40857,7 +40877,7 @@
40857
40877
  shaderData.setVector3(MainModule._positionScale, scale);
40858
40878
  shaderData.setVector3(MainModule._sizeScale, scale);
40859
40879
  break;
40860
- case ParticleScaleMode.Shape:
40880
+ case ParticleScaleMode.World:
40861
40881
  shaderData.setVector3(MainModule._positionScale, transform.lossyWorldScale);
40862
40882
  shaderData.setVector3(MainModule._sizeScale, MainModule._vector3One);
40863
40883
  break;
@@ -41623,297 +41643,6 @@
41623
41643
  __decorate$1([
41624
41644
  ignoreClone
41625
41645
  ], TextureSheetAnimationModule.prototype, "_onTilingChanged", null);
41626
- /**
41627
- * Noise module for particle system.
41628
- * Adds simplex noise-based turbulence displacement to particles.
41629
- */ var NoiseModule = /*#__PURE__*/ function(ParticleGeneratorModule) {
41630
- _inherits$2(NoiseModule, ParticleGeneratorModule);
41631
- function NoiseModule(generator) {
41632
- var _this;
41633
- _this = ParticleGeneratorModule.call(this, generator) || this, /** @internal */ _this._noiseRand = new Rand(0, ParticleRandomSubSeeds.Noise), _this._noiseParams = new Vector4(), _this._noiseOctaveParams = new Vector4(), _this._strengthMinConst = new Vector3(), _this._scrollSpeed = 0, _this._separateAxes = false, _this._frequency = 0.5, _this._octaveCount = 1, _this._octaveIntensityMultiplier = 0.5, _this._octaveFrequencyMultiplier = 2.0;
41634
- _this.strengthX = new ParticleCompositeCurve(1);
41635
- _this.strengthY = new ParticleCompositeCurve(1);
41636
- _this.strengthZ = new ParticleCompositeCurve(1);
41637
- return _this;
41638
- }
41639
- var _proto = NoiseModule.prototype;
41640
- /**
41641
- * @internal
41642
- */ _proto._updateShaderData = function _updateShaderData(shaderData) {
41643
- var enabledMacro = null;
41644
- var strengthCurveMacro = null;
41645
- var strengthIsRandomTwoMacro = null;
41646
- var separateAxesMacro = null;
41647
- if (this.enabled) {
41648
- enabledMacro = NoiseModule._enabledMacro;
41649
- var strengthX = this._strengthX;
41650
- var strengthY = this._strengthY;
41651
- var strengthZ = this._strengthZ;
41652
- var separateAxes = this._separateAxes;
41653
- // Determine strength curve mode (following SOL pattern)
41654
- var isRandomCurveMode = separateAxes ? strengthX.mode === ParticleCurveMode.TwoCurves && strengthY.mode === ParticleCurveMode.TwoCurves && strengthZ.mode === ParticleCurveMode.TwoCurves : strengthX.mode === ParticleCurveMode.TwoCurves;
41655
- var isCurveMode = isRandomCurveMode || (separateAxes ? strengthX.mode === ParticleCurveMode.Curve && strengthY.mode === ParticleCurveMode.Curve && strengthZ.mode === ParticleCurveMode.Curve : strengthX.mode === ParticleCurveMode.Curve);
41656
- var isRandomConstMode = separateAxes ? strengthX.mode === ParticleCurveMode.TwoConstants && strengthY.mode === ParticleCurveMode.TwoConstants && strengthZ.mode === ParticleCurveMode.TwoConstants : strengthX.mode === ParticleCurveMode.TwoConstants;
41657
- // noiseParams.w = frequency (always needed)
41658
- var noiseParams = this._noiseParams;
41659
- if (isCurveMode) {
41660
- // Curve/TwoCurves: encode curve data as float arrays
41661
- shaderData.setFloatArray(NoiseModule._strengthMaxCurveXProperty, strengthX.curveMax._getTypeArray());
41662
- if (separateAxes) {
41663
- shaderData.setFloatArray(NoiseModule._strengthMaxCurveYProperty, strengthY.curveMax._getTypeArray());
41664
- shaderData.setFloatArray(NoiseModule._strengthMaxCurveZProperty, strengthZ.curveMax._getTypeArray());
41665
- }
41666
- if (isRandomCurveMode) {
41667
- shaderData.setFloatArray(NoiseModule._strengthMinCurveXProperty, strengthX.curveMin._getTypeArray());
41668
- if (separateAxes) {
41669
- shaderData.setFloatArray(NoiseModule._strengthMinCurveYProperty, strengthY.curveMin._getTypeArray());
41670
- shaderData.setFloatArray(NoiseModule._strengthMinCurveZProperty, strengthZ.curveMin._getTypeArray());
41671
- }
41672
- strengthIsRandomTwoMacro = NoiseModule._strengthIsRandomTwoMacro;
41673
- }
41674
- strengthCurveMacro = NoiseModule._strengthCurveMacro;
41675
- // xyz unused in curve mode, just set frequency
41676
- noiseParams.set(0, 0, 0, this._frequency);
41677
- } else {
41678
- // Constant/TwoConstants: pack strength into noiseParams.xyz
41679
- if (separateAxes) {
41680
- noiseParams.set(strengthX.constantMax, strengthY.constantMax, strengthZ.constantMax, this._frequency);
41681
- } else {
41682
- var s = strengthX.constantMax;
41683
- noiseParams.set(s, s, s, this._frequency);
41684
- }
41685
- if (isRandomConstMode) {
41686
- var minConst = this._strengthMinConst;
41687
- if (separateAxes) {
41688
- minConst.set(strengthX.constantMin, strengthY.constantMin, strengthZ.constantMin);
41689
- } else {
41690
- var sMin = strengthX.constantMin;
41691
- minConst.set(sMin, sMin, sMin);
41692
- }
41693
- shaderData.setVector3(NoiseModule._strengthMinConstProperty, minConst);
41694
- strengthIsRandomTwoMacro = NoiseModule._strengthIsRandomTwoMacro;
41695
- }
41696
- }
41697
- shaderData.setVector4(NoiseModule._noiseProperty, noiseParams);
41698
- if (separateAxes) {
41699
- separateAxesMacro = NoiseModule._separateAxesMacro;
41700
- }
41701
- var noiseOctaveParams = this._noiseOctaveParams;
41702
- noiseOctaveParams.set(this._scrollSpeed, this._octaveCount, this._octaveIntensityMultiplier, this._octaveFrequencyMultiplier);
41703
- shaderData.setVector4(NoiseModule._noiseOctaveProperty, noiseOctaveParams);
41704
- }
41705
- this._enabledModuleMacro = this._enableMacro(shaderData, this._enabledModuleMacro, enabledMacro);
41706
- this._strengthCurveModeMacro = this._enableMacro(shaderData, this._strengthCurveModeMacro, strengthCurveMacro);
41707
- this._strengthIsRandomTwoModeMacro = this._enableMacro(shaderData, this._strengthIsRandomTwoModeMacro, strengthIsRandomTwoMacro);
41708
- this._separateAxesModeMacro = this._enableMacro(shaderData, this._separateAxesModeMacro, separateAxesMacro);
41709
- };
41710
- /**
41711
- * @internal
41712
- */ _proto._resetRandomSeed = function _resetRandomSeed(seed) {
41713
- this._noiseRand.reset(seed, ParticleRandomSubSeeds.Noise);
41714
- };
41715
- _create_class$2(NoiseModule, [
41716
- {
41717
- key: "separateAxes",
41718
- get: /**
41719
- * Specifies whether the strength is separate on each axis, when disabled, only `strength` is used.
41720
- */ function get() {
41721
- return this._separateAxes;
41722
- },
41723
- set: function set(value) {
41724
- if (value !== this._separateAxes) {
41725
- this._separateAxes = value;
41726
- this._generator._renderer._onGeneratorParamsChanged();
41727
- }
41728
- }
41729
- },
41730
- {
41731
- key: "strengthX",
41732
- get: /**
41733
- * Noise strength. When `separateAxes` is disabled, applies to all axes.
41734
- * When `separateAxes` is enabled, applies only to x axis.
41735
- */ function get() {
41736
- return this._strengthX;
41737
- },
41738
- set: function set(value) {
41739
- var lastValue = this._strengthX;
41740
- if (value !== lastValue) {
41741
- this._strengthX = value;
41742
- this._onCompositeCurveChange(lastValue, value);
41743
- }
41744
- }
41745
- },
41746
- {
41747
- key: "strengthY",
41748
- get: /**
41749
- * Noise strength for y axis, used when `separateAxes` is enabled.
41750
- */ function get() {
41751
- return this._strengthY;
41752
- },
41753
- set: function set(value) {
41754
- var lastValue = this._strengthY;
41755
- if (value !== lastValue) {
41756
- this._strengthY = value;
41757
- this._onCompositeCurveChange(lastValue, value);
41758
- }
41759
- }
41760
- },
41761
- {
41762
- key: "strengthZ",
41763
- get: /**
41764
- * Noise strength for z axis, used when `separateAxes` is enabled.
41765
- */ function get() {
41766
- return this._strengthZ;
41767
- },
41768
- set: function set(value) {
41769
- var lastValue = this._strengthZ;
41770
- if (value !== lastValue) {
41771
- this._strengthZ = value;
41772
- this._onCompositeCurveChange(lastValue, value);
41773
- }
41774
- }
41775
- },
41776
- {
41777
- key: "frequency",
41778
- get: /**
41779
- * Noise spatial frequency.
41780
- */ function get() {
41781
- return this._frequency;
41782
- },
41783
- set: function set(value) {
41784
- value = Math.max(1e-6, value);
41785
- if (value !== this._frequency) {
41786
- this._frequency = value;
41787
- this._generator._renderer._onGeneratorParamsChanged();
41788
- }
41789
- }
41790
- },
41791
- {
41792
- key: "scrollSpeed",
41793
- get: /**
41794
- * Noise field scroll speed over time.
41795
- */ function get() {
41796
- return this._scrollSpeed;
41797
- },
41798
- set: function set(value) {
41799
- if (value !== this._scrollSpeed) {
41800
- this._scrollSpeed = value;
41801
- this._generator._renderer._onGeneratorParamsChanged();
41802
- }
41803
- }
41804
- },
41805
- {
41806
- key: "octaveCount",
41807
- get: /**
41808
- * Number of noise octave layers (1-3).
41809
- */ function get() {
41810
- return this._octaveCount;
41811
- },
41812
- set: function set(value) {
41813
- value = Math.max(1, Math.min(3, Math.floor(value)));
41814
- if (value !== this._octaveCount) {
41815
- this._octaveCount = value;
41816
- this._generator._renderer._onGeneratorParamsChanged();
41817
- }
41818
- }
41819
- },
41820
- {
41821
- key: "octaveIntensityMultiplier",
41822
- get: /**
41823
- * Intensity multiplier for each successive octave, only effective when `octaveCount` > 1.
41824
- * Each layer's contribution is scaled by this factor relative to the previous layer, range [0, 1].
41825
- */ function get() {
41826
- return this._octaveIntensityMultiplier;
41827
- },
41828
- set: function set(value) {
41829
- value = Math.max(0, Math.min(1, value));
41830
- if (value !== this._octaveIntensityMultiplier) {
41831
- this._octaveIntensityMultiplier = value;
41832
- this._generator._renderer._onGeneratorParamsChanged();
41833
- }
41834
- }
41835
- },
41836
- {
41837
- key: "octaveFrequencyMultiplier",
41838
- get: /**
41839
- * Frequency multiplier for each successive octave, only effective when `octaveCount` > 1.
41840
- * Each layer samples at this multiple of the previous layer's frequency, range [1, 4].
41841
- */ function get() {
41842
- return this._octaveFrequencyMultiplier;
41843
- },
41844
- set: function set(value) {
41845
- value = Math.max(1, Math.min(4, value));
41846
- if (value !== this._octaveFrequencyMultiplier) {
41847
- this._octaveFrequencyMultiplier = value;
41848
- this._generator._renderer._onGeneratorParamsChanged();
41849
- }
41850
- }
41851
- },
41852
- {
41853
- key: "enabled",
41854
- get: function get() {
41855
- return this._enabled;
41856
- },
41857
- set: function set(value) {
41858
- if (value !== this._enabled) {
41859
- if (value && !this._generator._renderer.engine._hardwareRenderer.isWebGL2) {
41860
- return;
41861
- }
41862
- this._enabled = value;
41863
- this._generator._setTransformFeedback();
41864
- this._generator._renderer._onGeneratorParamsChanged();
41865
- }
41866
- }
41867
- }
41868
- ]);
41869
- return NoiseModule;
41870
- }(ParticleGeneratorModule);
41871
- NoiseModule._enabledMacro = ShaderMacro.getByName("RENDERER_NOISE_MODULE_ENABLED");
41872
- NoiseModule._strengthCurveMacro = ShaderMacro.getByName("RENDERER_NOISE_STRENGTH_CURVE");
41873
- NoiseModule._strengthIsRandomTwoMacro = ShaderMacro.getByName("RENDERER_NOISE_STRENGTH_IS_RANDOM_TWO");
41874
- NoiseModule._separateAxesMacro = ShaderMacro.getByName("RENDERER_NOISE_IS_SEPARATE");
41875
- NoiseModule._noiseProperty = ShaderProperty.getByName("renderer_NoiseParams");
41876
- NoiseModule._noiseOctaveProperty = ShaderProperty.getByName("renderer_NoiseOctaveParams");
41877
- NoiseModule._strengthMinConstProperty = ShaderProperty.getByName("renderer_NoiseStrengthMinConst");
41878
- NoiseModule._strengthMaxCurveXProperty = ShaderProperty.getByName("renderer_NoiseStrengthMaxCurveX");
41879
- NoiseModule._strengthMaxCurveYProperty = ShaderProperty.getByName("renderer_NoiseStrengthMaxCurveY");
41880
- NoiseModule._strengthMaxCurveZProperty = ShaderProperty.getByName("renderer_NoiseStrengthMaxCurveZ");
41881
- NoiseModule._strengthMinCurveXProperty = ShaderProperty.getByName("renderer_NoiseStrengthMinCurveX");
41882
- NoiseModule._strengthMinCurveYProperty = ShaderProperty.getByName("renderer_NoiseStrengthMinCurveY");
41883
- NoiseModule._strengthMinCurveZProperty = ShaderProperty.getByName("renderer_NoiseStrengthMinCurveZ");
41884
- __decorate$1([
41885
- ignoreClone
41886
- ], NoiseModule.prototype, "_enabledModuleMacro", void 0);
41887
- __decorate$1([
41888
- ignoreClone
41889
- ], NoiseModule.prototype, "_strengthCurveModeMacro", void 0);
41890
- __decorate$1([
41891
- ignoreClone
41892
- ], NoiseModule.prototype, "_strengthIsRandomTwoModeMacro", void 0);
41893
- __decorate$1([
41894
- ignoreClone
41895
- ], NoiseModule.prototype, "_separateAxesModeMacro", void 0);
41896
- __decorate$1([
41897
- ignoreClone
41898
- ], NoiseModule.prototype, "_noiseRand", void 0);
41899
- __decorate$1([
41900
- ignoreClone
41901
- ], NoiseModule.prototype, "_noiseParams", void 0);
41902
- __decorate$1([
41903
- ignoreClone
41904
- ], NoiseModule.prototype, "_noiseOctaveParams", void 0);
41905
- __decorate$1([
41906
- ignoreClone
41907
- ], NoiseModule.prototype, "_strengthMinConst", void 0);
41908
- __decorate$1([
41909
- deepClone
41910
- ], NoiseModule.prototype, "_strengthX", void 0);
41911
- __decorate$1([
41912
- deepClone
41913
- ], NoiseModule.prototype, "_strengthY", void 0);
41914
- __decorate$1([
41915
- deepClone
41916
- ], NoiseModule.prototype, "_strengthZ", void 0);
41917
41646
  /**
41918
41647
  * Velocity over lifetime module.
41919
41648
  */ var VelocityOverLifetimeModule = /*#__PURE__*/ function(ParticleGeneratorModule) {
@@ -42119,7 +41848,6 @@
42119
41848
  this.forceOverLifetime = new ForceOverLifetimeModule(this);
42120
41849
  this.sizeOverLifetime = new SizeOverLifetimeModule(this);
42121
41850
  this.limitVelocityOverLifetime = new LimitVelocityOverLifetimeModule(this);
42122
- this.noise = new NoiseModule(this);
42123
41851
  this.emission.enabled = true;
42124
41852
  }
42125
41853
  var _proto = ParticleGenerator.prototype;
@@ -42427,7 +42155,6 @@
42427
42155
  this.sizeOverLifetime._updateShaderData(shaderData);
42428
42156
  this.rotationOverLifetime._updateShaderData(shaderData);
42429
42157
  this.colorOverLifetime._updateShaderData(shaderData);
42430
- this.noise._updateShaderData(shaderData);
42431
42158
  };
42432
42159
  /**
42433
42160
  * @internal
@@ -42441,19 +42168,16 @@
42441
42168
  this.limitVelocityOverLifetime._resetRandomSeed(seed);
42442
42169
  this.rotationOverLifetime._resetRandomSeed(seed);
42443
42170
  this.colorOverLifetime._resetRandomSeed(seed);
42444
- this.noise._resetRandomSeed(seed);
42445
42171
  };
42446
42172
  /**
42447
42173
  * @internal
42448
- */ _proto._setTransformFeedback = function _setTransformFeedback() {
42449
- var needed = this.limitVelocityOverLifetime.enabled || this.noise.enabled;
42450
- if (needed === this._useTransformFeedback) return;
42451
- this._useTransformFeedback = needed;
42174
+ */ _proto._setTransformFeedback = function _setTransformFeedback(enabled) {
42175
+ this._useTransformFeedback = enabled;
42452
42176
  // Switching TF mode invalidates all active particle state: feedback buffers and instance
42453
42177
  // buffer layout are incompatible between the two paths. Clear rather than show a one-frame
42454
42178
  // jump; new particles will fill in naturally from the next emit cycle.
42455
42179
  this._clearActiveParticles();
42456
- if (needed) {
42180
+ if (enabled) {
42457
42181
  if (!this._feedbackSimulator) {
42458
42182
  this._feedbackSimulator = new ParticleTransformFeedbackSimulator(this._renderer.engine);
42459
42183
  }
@@ -42503,7 +42227,9 @@
42503
42227
  /**
42504
42228
  * @internal
42505
42229
  */ _proto._cloneTo = function _cloneTo(target) {
42506
- target._setTransformFeedback();
42230
+ if (target.limitVelocityOverLifetime.enabled) {
42231
+ target._setTransformFeedback(true);
42232
+ }
42507
42233
  };
42508
42234
  /**
42509
42235
  * @internal
@@ -42665,6 +42391,10 @@
42665
42391
  // Start rotation
42666
42392
  var startRotationRand = main._startRotationRand, flipRotation = main.flipRotation;
42667
42393
  var isFlip = flipRotation > startRotationRand.random();
42394
+ // @todo:None-Mesh mode should inverse the rotation, maybe should unify it
42395
+ if (this._renderer.renderMode !== ParticleRenderMode.Mesh) {
42396
+ isFlip = !isFlip;
42397
+ }
42668
42398
  var rotationZ = main.startRotationZ.evaluate(undefined, startRotationRand.random());
42669
42399
  if (main.startRotation3D) {
42670
42400
  var rotationX = main.startRotationX.evaluate(undefined, startRotationRand.random());
@@ -42690,9 +42420,7 @@
42690
42420
  if (colorOverLifetime.enabled && colorOverLifetime.color.mode === ParticleGradientMode.TwoGradients) {
42691
42421
  instanceVertices[offset + 20] = colorOverLifetime._colorGradientRand.random();
42692
42422
  }
42693
- if (this.noise.enabled) {
42694
- instanceVertices[offset + 21] = this.noise._noiseRand.random();
42695
- }
42423
+ // instanceVertices[offset + 21] = rand.random();
42696
42424
  var rotationOverLifetime = this.rotationOverLifetime;
42697
42425
  if (rotationOverLifetime.enabled && rotationOverLifetime.rotationZ.mode === ParticleCurveMode.TwoConstants) {
42698
42426
  instanceVertices[offset + 22] = rotationOverLifetime._rotationRand.random();
@@ -42885,7 +42613,7 @@
42885
42613
  // StartSpeed's impact
42886
42614
  var shape = this.emission.shape;
42887
42615
  if (shape == null ? void 0 : shape.enabled) {
42888
- shape._getPositionRange(bounds);
42616
+ shape._getPositionRange(min, max);
42889
42617
  shape._getDirectionRange(directionMin, directionMax);
42890
42618
  } else {
42891
42619
  min.set(0, 0, 0);
@@ -42980,21 +42708,6 @@
42980
42708
  out.transform(rotateMat);
42981
42709
  min.add(worldOffsetMin);
42982
42710
  max.add(worldOffsetMax);
42983
- // Noise module impact: noise output is normalized to [-1, 1],
42984
- // max displacement = |strength_max|
42985
- var noise = this.noise;
42986
- if (noise.enabled) {
42987
- var noiseMaxX, noiseMaxY, noiseMaxZ;
42988
- if (noise.separateAxes) {
42989
- noiseMaxX = Math.abs(noise.strengthX._getMax());
42990
- noiseMaxY = Math.abs(noise.strengthY._getMax());
42991
- noiseMaxZ = Math.abs(noise.strengthZ._getMax());
42992
- } else {
42993
- noiseMaxX = noiseMaxY = noiseMaxZ = Math.abs(noise.strengthX._getMax());
42994
- }
42995
- min.set(min.x - noiseMaxX, min.y - noiseMaxY, min.z - noiseMaxZ);
42996
- max.set(max.x + noiseMaxX, max.y + noiseMaxY, max.z + noiseMaxZ);
42997
- }
42998
42711
  min.add(worldPosition);
42999
42712
  max.add(worldPosition);
43000
42713
  };
@@ -43092,9 +42805,6 @@
43092
42805
  __decorate$1([
43093
42806
  deepClone
43094
42807
  ], ParticleGenerator.prototype, "textureSheetAnimation", void 0);
43095
- __decorate$1([
43096
- deepClone
43097
- ], ParticleGenerator.prototype, "noise", void 0);
43098
42808
  __decorate$1([
43099
42809
  ignoreClone
43100
42810
  ], ParticleGenerator.prototype, "_playTime", void 0);
@@ -43257,39 +42967,10 @@
43257
42967
  }(EffectMaterial);
43258
42968
  /**
43259
42969
  * A burst is a particle emission event, where a number of particles are all emitted at the same time
43260
- */ var Burst = /*#__PURE__*/ function() {
43261
- function Burst(time, count, cycles, repeatInterval) {
43262
- this.time = time;
43263
- this.count = count;
43264
- this._cycles = Math.max(cycles != null ? cycles : 1, 1);
43265
- this._repeatInterval = Math.max(repeatInterval != null ? repeatInterval : 0.01, 0.01);
43266
- }
43267
- _create_class$2(Burst, [
43268
- {
43269
- key: "cycles",
43270
- get: /**
43271
- * Number of times to repeat the burst.
43272
- */ function get() {
43273
- return this._cycles;
43274
- },
43275
- set: function set(value) {
43276
- this._cycles = Math.max(value, 1);
43277
- }
43278
- },
43279
- {
43280
- key: "repeatInterval",
43281
- get: /**
43282
- * Time interval between each repeated burst.
43283
- */ function get() {
43284
- return this._repeatInterval;
43285
- },
43286
- set: function set(value) {
43287
- this._repeatInterval = Math.max(value, 0.01);
43288
- }
43289
- }
43290
- ]);
43291
- return Burst;
43292
- }();
42970
+ */ var Burst = function Burst(time, count) {
42971
+ this.time = time;
42972
+ this.count = count;
42973
+ };
43293
42974
  __decorate$1([
43294
42975
  deepClone
43295
42976
  ], Burst.prototype, "count", void 0);
@@ -43297,28 +42978,9 @@
43297
42978
  * Base class for all particle shapes.
43298
42979
  */ var BaseShape = /*#__PURE__*/ function() {
43299
42980
  function BaseShape() {
43300
- var _this = this;
43301
42981
  this._updateManager = new UpdateFlagManager();
43302
42982
  this._enabled = true;
43303
42983
  this._randomDirectionAmount = 0;
43304
- this._position = new Vector3(0, 0, 0);
43305
- this._rotation = new Vector3(0, 0, 0);
43306
- this._scale = new Vector3(1, 1, 1);
43307
- this._matrix = new Matrix();
43308
- this._transformDirty = false;
43309
- this._hasShapeTransform = false;
43310
- this._onTransformChanged = function() {
43311
- _this._transformDirty = true;
43312
- var p = _this._position, r = _this._rotation, s = _this._scale;
43313
- _this._hasShapeTransform = p.x !== 0 || p.y !== 0 || p.z !== 0 || r.x !== 0 || r.y !== 0 || r.z !== 0 || s.x !== 1 || s.y !== 1 || s.z !== 1;
43314
- _this._updateManager.dispatch();
43315
- };
43316
- // @ts-ignore
43317
- this._position._onValueChanged = this._onTransformChanged;
43318
- // @ts-ignore
43319
- this._rotation._onValueChanged = this._onTransformChanged;
43320
- // @ts-ignore
43321
- this._scale._onValueChanged = this._onTransformChanged;
43322
42984
  }
43323
42985
  var _proto = BaseShape.prototype;
43324
42986
  /**
@@ -43331,53 +42993,6 @@
43331
42993
  */ _proto._unRegisterOnValueChanged = function _unRegisterOnValueChanged(listener) {
43332
42994
  this._updateManager.removeListener(listener);
43333
42995
  };
43334
- /**
43335
- * @internal
43336
- */ _proto._generatePositionAndDirection = function _generatePositionAndDirection(rand, emitTime, position, direction) {
43337
- this._generateLocalPositionAndDirection(rand, emitTime, position, direction);
43338
- if (this._hasShapeTransform) {
43339
- var matrix = this._getMatrix();
43340
- Vector3.transformToVec3(position, matrix, position);
43341
- Vector3.transformNormal(direction, matrix, direction);
43342
- direction.normalize();
43343
- }
43344
- };
43345
- /**
43346
- * @internal
43347
- */ _proto._getPositionRange = function _getPositionRange(bounds) {
43348
- this._getLocalPositionRange(bounds.min, bounds.max);
43349
- if (this._hasShapeTransform) {
43350
- BoundingBox.transform(bounds, this._getMatrix(), bounds);
43351
- }
43352
- };
43353
- /**
43354
- * @internal
43355
- */ _proto._getDirectionRange = function _getDirectionRange(outMin, outMax) {
43356
- this._getLocalDirectionRange(outMin, outMax);
43357
- if (this._hasShapeTransform) {
43358
- this._transformDirectionRange(outMin, outMax);
43359
- }
43360
- };
43361
- _proto._getMatrix = function _getMatrix() {
43362
- if (this._transformDirty) {
43363
- var _this = this, r = _this._rotation;
43364
- var q = BaseShape._tempQuaternion;
43365
- Quaternion.rotationEuler(MathUtil.degreeToRadian(r.x), MathUtil.degreeToRadian(r.y), MathUtil.degreeToRadian(r.z), q);
43366
- Matrix.affineTransformation(this._scale, q, this._position, this._matrix);
43367
- this._transformDirty = false;
43368
- }
43369
- return this._matrix;
43370
- };
43371
- // Arvo min/max method without translation, only apply RS part of the matrix
43372
- _proto._transformDirectionRange = function _transformDirectionRange(outMin, outMax) {
43373
- var e = this._getMatrix().elements;
43374
- var minX = outMin.x, minY = outMin.y, minZ = outMin.z;
43375
- var maxX = outMax.x, maxY = outMax.y, maxZ = outMax.z;
43376
- // prettier-ignore
43377
- var e0 = e[0], e1 = e[1], e2 = e[2], e4 = e[4], e5 = e[5], e6 = e[6], e8 = e[8], e9 = e[9], e10 = e[10];
43378
- outMin.set((e0 > 0 ? e0 * minX : e0 * maxX) + (e4 > 0 ? e4 * minY : e4 * maxY) + (e8 > 0 ? e8 * minZ : e8 * maxZ), (e1 > 0 ? e1 * minX : e1 * maxX) + (e5 > 0 ? e5 * minY : e5 * maxY) + (e9 > 0 ? e9 * minZ : e9 * maxZ), (e2 > 0 ? e2 * minX : e2 * maxX) + (e6 > 0 ? e6 * minY : e6 * maxY) + (e10 > 0 ? e10 * minZ : e10 * maxZ));
43379
- outMax.set((e0 > 0 ? e0 * maxX : e0 * minX) + (e4 > 0 ? e4 * maxY : e4 * minY) + (e8 > 0 ? e8 * maxZ : e8 * minZ), (e1 > 0 ? e1 * maxX : e1 * minX) + (e5 > 0 ? e5 * maxY : e5 * minY) + (e9 > 0 ? e9 * maxZ : e9 * minZ), (e2 > 0 ? e2 * maxX : e2 * minX) + (e6 > 0 ? e6 * maxY : e6 * minY) + (e10 > 0 ? e10 * maxZ : e10 * minZ));
43380
- };
43381
42996
  _create_class$2(BaseShape, [
43382
42997
  {
43383
42998
  key: "enabled",
@@ -43406,78 +43021,13 @@
43406
43021
  this._updateManager.dispatch();
43407
43022
  }
43408
43023
  }
43409
- },
43410
- {
43411
- key: "position",
43412
- get: /**
43413
- * Apply a local position offset to the shape.
43414
- */ function get() {
43415
- return this._position;
43416
- },
43417
- set: function set(value) {
43418
- if (value !== this._position) {
43419
- this._position.copyFrom(value);
43420
- }
43421
- }
43422
- },
43423
- {
43424
- key: "rotation",
43425
- get: /**
43426
- * Apply a local rotation to the shape, specified as euler angles in degrees.
43427
- */ function get() {
43428
- return this._rotation;
43429
- },
43430
- set: function set(value) {
43431
- if (value !== this._rotation) {
43432
- this._rotation.copyFrom(value);
43433
- }
43434
- }
43435
- },
43436
- {
43437
- key: "scale",
43438
- get: /**
43439
- * Apply a local scale to the shape.
43440
- */ function get() {
43441
- return this._scale;
43442
- },
43443
- set: function set(value) {
43444
- if (value !== this._scale) {
43445
- this._scale.copyFrom(value);
43446
- }
43447
- }
43448
43024
  }
43449
43025
  ]);
43450
43026
  return BaseShape;
43451
43027
  }();
43452
- /** @internal */ BaseShape._tempVector20 = new Vector2();
43453
- /** @internal */ BaseShape._tempVector21 = new Vector2();
43454
- /** @internal */ BaseShape._tempVector30 = new Vector3();
43455
- /** @internal */ BaseShape._tempVector31 = new Vector3();
43456
- BaseShape._tempQuaternion = new Quaternion();
43457
43028
  __decorate$1([
43458
43029
  ignoreClone
43459
43030
  ], BaseShape.prototype, "_updateManager", void 0);
43460
- __decorate$1([
43461
- deepClone
43462
- ], BaseShape.prototype, "_position", void 0);
43463
- __decorate$1([
43464
- deepClone
43465
- ], BaseShape.prototype, "_rotation", void 0);
43466
- __decorate$1([
43467
- deepClone
43468
- ], BaseShape.prototype, "_scale", void 0);
43469
- __decorate$1([
43470
- ignoreClone
43471
- ], BaseShape.prototype, "_matrix", void 0);
43472
- __decorate$1([
43473
- ignoreClone
43474
- ], BaseShape.prototype, "_transformDirty", void 0);
43475
- __decorate$1([
43476
- ignoreClone
43477
- ], BaseShape.prototype, "_hasShapeTransform", void 0);
43478
- __decorate$1([
43479
- ignoreClone
43480
- ], BaseShape.prototype, "_onTransformChanged", void 0);
43481
43031
  /**
43482
43032
  * @internal
43483
43033
  */ var ShapeUtils = /*#__PURE__*/ function() {
@@ -43540,11 +43090,11 @@
43540
43090
  }({});
43541
43091
  /**
43542
43092
  * Particle shape that emits particles from a box.
43543
- */ var BoxShape = /*#__PURE__*/ function(BaseShape1) {
43544
- _inherits$2(BoxShape, BaseShape1);
43093
+ */ var BoxShape = /*#__PURE__*/ function(BaseShape) {
43094
+ _inherits$2(BoxShape, BaseShape);
43545
43095
  function BoxShape() {
43546
43096
  var _this;
43547
- _this = BaseShape1.call(this) || this, _this.shapeType = ParticleShapeType.Box, _this._size = new Vector3(1, 1, 1);
43097
+ _this = BaseShape.call(this) || this, _this.shapeType = ParticleShapeType.Box, _this._size = new Vector3(1, 1, 1);
43548
43098
  // @ts-ignore
43549
43099
  _this._size._onValueChanged = _this._updateManager.dispatch.bind(_this._updateManager);
43550
43100
  return _this;
@@ -43552,17 +43102,17 @@
43552
43102
  var _proto = BoxShape.prototype;
43553
43103
  /**
43554
43104
  * @internal
43555
- */ _proto._generateLocalPositionAndDirection = function _generateLocalPositionAndDirection(rand, emitTime, position, direction) {
43105
+ */ _proto._generatePositionAndDirection = function _generatePositionAndDirection(rand, emitTime, position, direction) {
43556
43106
  ShapeUtils._randomPointInsideHalfUnitBox(position, rand);
43557
43107
  position.multiply(this.size);
43558
- var defaultDirection = BaseShape._tempVector30;
43108
+ var defaultDirection = BoxShape._tempVector30;
43559
43109
  defaultDirection.set(0.0, 0.0, -1.0);
43560
43110
  ShapeUtils._randomPointUnitSphere(direction, rand);
43561
43111
  Vector3.lerp(defaultDirection, direction, this.randomDirectionAmount, direction);
43562
43112
  };
43563
43113
  /**
43564
43114
  * @internal
43565
- */ _proto._getLocalDirectionRange = function _getLocalDirectionRange(outMin, outMax) {
43115
+ */ _proto._getDirectionRange = function _getDirectionRange(outMin, outMax) {
43566
43116
  var radian = Math.PI * this.randomDirectionAmount;
43567
43117
  if (this.randomDirectionAmount < 0.5) {
43568
43118
  var dirSin = Math.sin(radian);
@@ -43576,7 +43126,7 @@
43576
43126
  };
43577
43127
  /**
43578
43128
  * @internal
43579
- */ _proto._getLocalPositionRange = function _getLocalPositionRange(outMin, outMax) {
43129
+ */ _proto._getPositionRange = function _getPositionRange(outMin, outMax) {
43580
43130
  var _this__size = this._size, x = _this__size.x, y = _this__size.y, z = _this__size.z;
43581
43131
  outMin.set(-x * 0.5, -y * 0.5, -z * 0.5);
43582
43132
  outMax.set(x * 0.5, y * 0.5, z * 0.5);
@@ -43598,6 +43148,7 @@
43598
43148
  ]);
43599
43149
  return BoxShape;
43600
43150
  }(BaseShape);
43151
+ BoxShape._tempVector30 = new Vector3();
43601
43152
  __decorate$1([
43602
43153
  deepClone
43603
43154
  ], BoxShape.prototype, "_size", void 0);
@@ -43610,18 +43161,18 @@
43610
43161
  }({});
43611
43162
  /**
43612
43163
  * Particle shape that emits particles from a circle.
43613
- */ var CircleShape = /*#__PURE__*/ function(BaseShape1) {
43614
- _inherits$2(CircleShape, BaseShape1);
43164
+ */ var CircleShape = /*#__PURE__*/ function(BaseShape) {
43165
+ _inherits$2(CircleShape, BaseShape);
43615
43166
  function CircleShape() {
43616
43167
  var _this;
43617
- _this = BaseShape1.apply(this, arguments) || this, _this.shapeType = ParticleShapeType.Circle, _this._radius = 1.0, _this._arc = 360.0, _this._arcMode = ParticleShapeArcMode.Random, _this._arcSpeed = 1.0;
43168
+ _this = BaseShape.apply(this, arguments) || this, _this.shapeType = ParticleShapeType.Circle, _this._radius = 1.0, _this._arc = 360.0, _this._arcMode = ParticleShapeArcMode.Random, _this._arcSpeed = 1.0;
43618
43169
  return _this;
43619
43170
  }
43620
43171
  var _proto = CircleShape.prototype;
43621
43172
  /**
43622
43173
  * @internal
43623
- */ _proto._generateLocalPositionAndDirection = function _generateLocalPositionAndDirection(rand, emitTime, position, direction) {
43624
- var positionPoint = BaseShape._tempVector20;
43174
+ */ _proto._generatePositionAndDirection = function _generatePositionAndDirection(rand, emitTime, position, direction) {
43175
+ var positionPoint = CircleShape._tempPositionPoint;
43625
43176
  switch(this.arcMode){
43626
43177
  case ParticleShapeArcMode.Loop:
43627
43178
  var normalizedEmitTime = emitTime * this.arcSpeed * (360 / this.arc) % 1;
@@ -43640,7 +43191,7 @@
43640
43191
  };
43641
43192
  /**
43642
43193
  * @internal
43643
- */ _proto._getLocalDirectionRange = function _getLocalDirectionRange(outMin, outMax) {
43194
+ */ _proto._getDirectionRange = function _getDirectionRange(outMin, outMax) {
43644
43195
  var randomDirZ = this.randomDirectionAmount > 0.5 ? 1 : Math.sin(this.randomDirectionAmount * Math.PI);
43645
43196
  var randomDegreeOnXY = 0.5 * (360 - this._arc) * this.randomDirectionAmount;
43646
43197
  var randomDirY = randomDegreeOnXY > 90 ? -1 : -Math.sin(randomDegreeOnXY);
@@ -43648,7 +43199,7 @@
43648
43199
  };
43649
43200
  /**
43650
43201
  * @internal
43651
- */ _proto._getLocalPositionRange = function _getLocalPositionRange(outMin, outMax) {
43202
+ */ _proto._getPositionRange = function _getPositionRange(outMin, outMax) {
43652
43203
  this._getUnitArcRange(this._arc, outMin, outMax, 0, 0);
43653
43204
  outMin.scale(this._radius);
43654
43205
  outMax.scale(this._radius);
@@ -43731,20 +43282,21 @@
43731
43282
  ]);
43732
43283
  return CircleShape;
43733
43284
  }(BaseShape);
43285
+ CircleShape._tempPositionPoint = new Vector2();
43734
43286
  /**
43735
43287
  * Cone shape.
43736
- */ var ConeShape = /*#__PURE__*/ function(BaseShape1) {
43737
- _inherits$2(ConeShape, BaseShape1);
43288
+ */ var ConeShape = /*#__PURE__*/ function(BaseShape) {
43289
+ _inherits$2(ConeShape, BaseShape);
43738
43290
  function ConeShape() {
43739
43291
  var _this;
43740
- _this = BaseShape1.apply(this, arguments) || this, _this.shapeType = ParticleShapeType.Cone, _this._angle = 25.0, _this._radius = 1.0, _this._length = 5.0, _this._emitType = 0;
43292
+ _this = BaseShape.apply(this, arguments) || this, _this.shapeType = ParticleShapeType.Cone, _this._angle = 25.0, _this._radius = 1.0, _this._length = 5.0, _this._emitType = 0;
43741
43293
  return _this;
43742
43294
  }
43743
43295
  var _proto = ConeShape.prototype;
43744
43296
  /**
43745
43297
  * @internal
43746
- */ _proto._generateLocalPositionAndDirection = function _generateLocalPositionAndDirection(rand, emitTime, position, direction) {
43747
- var unitPosition = BaseShape._tempVector20;
43298
+ */ _proto._generatePositionAndDirection = function _generatePositionAndDirection(rand, emitTime, position, direction) {
43299
+ var unitPosition = ConeShape._tempVector20;
43748
43300
  var radian = MathUtil.degreeToRadian(this.angle);
43749
43301
  var dirSinA = Math.sin(radian);
43750
43302
  var dirCosA = Math.cos(radian);
@@ -43752,7 +43304,7 @@
43752
43304
  case 0:
43753
43305
  ShapeUtils.randomPointInsideUnitCircle(unitPosition, rand);
43754
43306
  position.set(unitPosition.x * this.radius, unitPosition.y * this.radius, 0);
43755
- var unitDirection = BaseShape._tempVector21;
43307
+ var unitDirection = ConeShape._tempVector21;
43756
43308
  ShapeUtils.randomPointInsideUnitCircle(unitDirection, rand);
43757
43309
  Vector2.lerp(unitPosition, unitDirection, this.randomDirectionAmount, unitDirection);
43758
43310
  direction.set(unitDirection.x * dirSinA, unitDirection.y * dirSinA, -dirCosA);
@@ -43762,10 +43314,10 @@
43762
43314
  position.set(unitPosition.x * this.radius, unitPosition.y * this.radius, 0);
43763
43315
  direction.set(unitPosition.x * dirSinA, unitPosition.y * dirSinA, -dirCosA);
43764
43316
  direction.normalize();
43765
- var distance = BaseShape._tempVector30;
43317
+ var distance = ConeShape._tempVector30;
43766
43318
  Vector3.scale(direction, this.length * rand.random(), distance);
43767
43319
  position.add(distance);
43768
- var randomDirection = BaseShape._tempVector31;
43320
+ var randomDirection = ConeShape._tempVector31;
43769
43321
  ShapeUtils._randomPointUnitSphere(randomDirection, rand);
43770
43322
  Vector3.lerp(direction, randomDirection, this.randomDirectionAmount, direction);
43771
43323
  break;
@@ -43773,7 +43325,7 @@
43773
43325
  };
43774
43326
  /**
43775
43327
  * @internal
43776
- */ _proto._getLocalDirectionRange = function _getLocalDirectionRange(outMin, outMax) {
43328
+ */ _proto._getDirectionRange = function _getDirectionRange(outMin, outMax) {
43777
43329
  var radian = 0;
43778
43330
  switch(this.emitType){
43779
43331
  case 0:
@@ -43790,7 +43342,7 @@
43790
43342
  };
43791
43343
  /**
43792
43344
  * @internal
43793
- */ _proto._getLocalPositionRange = function _getLocalPositionRange(outMin, outMax) {
43345
+ */ _proto._getPositionRange = function _getPositionRange(outMin, outMax) {
43794
43346
  var radius = this.radius;
43795
43347
  switch(this.emitType){
43796
43348
  case 0:
@@ -43865,6 +43417,10 @@
43865
43417
  ]);
43866
43418
  return ConeShape;
43867
43419
  }(BaseShape);
43420
+ ConeShape._tempVector20 = new Vector2();
43421
+ ConeShape._tempVector21 = new Vector2();
43422
+ ConeShape._tempVector30 = new Vector3();
43423
+ ConeShape._tempVector31 = new Vector3();
43868
43424
  /**
43869
43425
  * Cone emitter type.
43870
43426
  */ var ConeEmitType = /*#__PURE__*/ function(ConeEmitType) {
@@ -43884,7 +43440,7 @@
43884
43440
  var _proto = HemisphereShape.prototype;
43885
43441
  /**
43886
43442
  * @internal
43887
- */ _proto._generateLocalPositionAndDirection = function _generateLocalPositionAndDirection(rand, emitTime, position, direction) {
43443
+ */ _proto._generatePositionAndDirection = function _generatePositionAndDirection(rand, emitTime, position, direction) {
43888
43444
  ShapeUtils._randomPointInsideUnitSphere(position, rand);
43889
43445
  position.scale(this.radius);
43890
43446
  var z = position.z;
@@ -43894,14 +43450,14 @@
43894
43450
  };
43895
43451
  /**
43896
43452
  * @internal
43897
- */ _proto._getLocalDirectionRange = function _getLocalDirectionRange(outMin, outMax) {
43453
+ */ _proto._getDirectionRange = function _getDirectionRange(outMin, outMax) {
43898
43454
  var randomDir = Math.sin(0.5 * this.randomDirectionAmount * Math.PI);
43899
43455
  outMin.set(-1, -1, -1);
43900
43456
  outMax.set(1, 1, randomDir);
43901
43457
  };
43902
43458
  /**
43903
43459
  * @internal
43904
- */ _proto._getLocalPositionRange = function _getLocalPositionRange(outMin, outMax) {
43460
+ */ _proto._getPositionRange = function _getPositionRange(outMin, outMax) {
43905
43461
  var radius = this._radius;
43906
43462
  outMin.set(-radius, -radius, -radius);
43907
43463
  outMax.set(radius, radius, 0);
@@ -43938,7 +43494,7 @@
43938
43494
  var _proto = MeshShape.prototype;
43939
43495
  /**
43940
43496
  * @internal
43941
- */ _proto._generateLocalPositionAndDirection = function _generateLocalPositionAndDirection(rand, emitTime, position, direction) {
43497
+ */ _proto._generatePositionAndDirection = function _generatePositionAndDirection(rand, emitTime, position, direction) {
43942
43498
  var _this = this, positions = _this._positionBuffer, positionInfo = _this._positionElementInfo, normals = _this._normalBuffer, normalInfo = _this._normalElementInfo;
43943
43499
  var randomIndex = Math.floor(rand.random() * this._mesh.vertexCount);
43944
43500
  // index = randomIndex * stride + offset
@@ -43951,14 +43507,14 @@
43951
43507
  };
43952
43508
  /**
43953
43509
  * @internal
43954
- */ _proto._getLocalPositionRange = function _getLocalPositionRange(outMin, outMax) {
43510
+ */ _proto._getPositionRange = function _getPositionRange(outMin, outMax) {
43955
43511
  var bounds = this._mesh.bounds;
43956
43512
  bounds.min.copyTo(outMin);
43957
43513
  bounds.max.copyTo(outMax);
43958
43514
  };
43959
43515
  /**
43960
43516
  * @internal
43961
- */ _proto._getLocalDirectionRange = function _getLocalDirectionRange(outMin, outMax) {
43517
+ */ _proto._getDirectionRange = function _getDirectionRange(outMin, outMax) {
43962
43518
  // @todo: Should use min and max of normal, use bounds is worst, but we can't get the min and max of normal by fast way.
43963
43519
  var bounds = this._mesh.bounds;
43964
43520
  bounds.min.copyTo(outMin);
@@ -44072,7 +43628,7 @@
44072
43628
  var _proto = SphereShape.prototype;
44073
43629
  /**
44074
43630
  * @internal
44075
- */ _proto._generateLocalPositionAndDirection = function _generateLocalPositionAndDirection(rand, emitTime, position, direction) {
43631
+ */ _proto._generatePositionAndDirection = function _generatePositionAndDirection(rand, emitTime, position, direction) {
44076
43632
  ShapeUtils._randomPointInsideUnitSphere(position, rand);
44077
43633
  position.scale(this.radius);
44078
43634
  ShapeUtils._randomPointUnitSphere(direction, rand);
@@ -44080,13 +43636,13 @@
44080
43636
  };
44081
43637
  /**
44082
43638
  * @internal
44083
- */ _proto._getLocalDirectionRange = function _getLocalDirectionRange(outMin, outMax) {
43639
+ */ _proto._getDirectionRange = function _getDirectionRange(outMin, outMax) {
44084
43640
  outMin.set(-1, -1, -1);
44085
43641
  outMax.set(1, 1, 1);
44086
43642
  };
44087
43643
  /**
44088
43644
  * @internal
44089
- */ _proto._getLocalPositionRange = function _getLocalPositionRange(outMin, outMax) {
43645
+ */ _proto._getPositionRange = function _getPositionRange(outMin, outMax) {
44090
43646
  var radius = this._radius;
44091
43647
  outMin.set(-radius, -radius, -radius);
44092
43648
  outMax.set(radius, radius, radius);
@@ -44838,27 +44394,37 @@
44838
44394
  * Suspend the audio context.
44839
44395
  * @returns A promise that resolves when the audio context is suspended
44840
44396
  */ AudioManager.suspend = function suspend() {
44841
- return AudioManager.getContext().suspend();
44397
+ var _AudioManager__context;
44398
+ var _AudioManager__context_suspend;
44399
+ return (_AudioManager__context_suspend = (_AudioManager__context = AudioManager._context) == null ? void 0 : _AudioManager__context.suspend()) != null ? _AudioManager__context_suspend : Promise.resolve();
44842
44400
  };
44843
44401
  /**
44844
44402
  * Resume the audio context.
44845
44403
  * @remarks On iOS Safari, calling this within a user gesture (e.g., click/touch event handler) can pre-unlock audio and reduce playback delay.
44846
44404
  * @returns A promise that resolves when the audio context is resumed
44847
44405
  */ AudioManager.resume = function resume() {
44848
- var _AudioManager;
44849
- var __resumePromise;
44850
- return (__resumePromise = (_AudioManager = AudioManager)._resumePromise) != null ? __resumePromise : _AudioManager._resumePromise = AudioManager.getContext().resume().then(function() {
44406
+ var context = AudioManager._context;
44407
+ if (!context || context.state === "running") {
44408
+ return Promise.resolve();
44409
+ }
44410
+ return context.resume().then(function() {
44851
44411
  AudioManager._needsUserGestureResume = false;
44852
- }).finally(function() {
44853
- AudioManager._resumePromise = null;
44412
+ AudioManager._resumePendingSources();
44854
44413
  });
44855
44414
  };
44415
+ /** @internal */ AudioManager._registerPendingSource = function _registerPendingSource(source) {
44416
+ AudioManager._pendingSources.add(source);
44417
+ };
44418
+ /** @internal */ AudioManager._unregisterPendingSource = function _unregisterPendingSource(source) {
44419
+ AudioManager._pendingSources.delete(source);
44420
+ };
44856
44421
  /**
44857
44422
  * @internal
44858
44423
  */ AudioManager.getContext = function getContext() {
44859
44424
  var context = AudioManager._context;
44860
44425
  if (!context) {
44861
44426
  AudioManager._context = context = new window.AudioContext();
44427
+ context.onstatechange = AudioManager._onContextStateChange;
44862
44428
  document.addEventListener("visibilitychange", AudioManager._onVisibilityChange);
44863
44429
  // iOS Safari requires user gesture to resume AudioContext
44864
44430
  document.addEventListener("touchstart", AudioManager._resumeAfterInterruption, {
@@ -44887,28 +44453,58 @@
44887
44453
  */ AudioManager.isAudioContextRunning = function isAudioContextRunning() {
44888
44454
  return AudioManager.getContext().state === "running";
44889
44455
  };
44456
+ AudioManager._onContextStateChange = function _onContextStateChange() {
44457
+ var _AudioManager__context;
44458
+ if (((_AudioManager__context = AudioManager._context) == null ? void 0 : _AudioManager__context.state) === "running") {
44459
+ AudioManager._needsUserGestureResume = false;
44460
+ AudioManager._resumePendingSources();
44461
+ }
44462
+ };
44463
+ AudioManager._resumePendingSources = function _resumePendingSources() {
44464
+ if (!AudioManager._pendingSources.size || !AudioManager.isAudioContextRunning()) {
44465
+ return;
44466
+ }
44467
+ var pendingSources = Array.from(AudioManager._pendingSources);
44468
+ AudioManager._pendingSources.clear();
44469
+ for(var i = 0, n = pendingSources.length; i < n; i++){
44470
+ pendingSources[i]._resumePendingPlayback();
44471
+ }
44472
+ };
44890
44473
  AudioManager._onVisibilityChange = function _onVisibilityChange() {
44891
- if (!document.hidden && AudioManager._playingCount > 0 && !AudioManager.isAudioContextRunning()) {
44892
- // iOS WKWebView WebKit bug(Triggered in LingGuang App): AudioContext may be in a "zombie" state where
44893
- // state reports "suspended" but resume() alone won't restart audio rendering.
44894
- // Calling suspend() first forces a clean internal state reset before user gesture triggers resume.
44895
- // Related: https://bugs.webkit.org/show_bug.cgi?id=263627
44896
- AudioManager.suspend();
44897
- AudioManager._needsUserGestureResume = true;
44474
+ var context = AudioManager._context;
44475
+ if (document.hidden || !context || AudioManager._playingCount === 0 && AudioManager._pendingSources.size === 0 || context.state === "running") {
44476
+ return;
44898
44477
  }
44478
+ AudioManager.resume().then(function() {
44479
+ var _AudioManager__context;
44480
+ if (((_AudioManager__context = AudioManager._context) == null ? void 0 : _AudioManager__context.state) !== "running") {
44481
+ return AudioManager._prepareGestureResume();
44482
+ }
44483
+ }).catch(function() {
44484
+ return AudioManager._prepareGestureResume();
44485
+ });
44899
44486
  };
44900
44487
  AudioManager._resumeAfterInterruption = function _resumeAfterInterruption() {
44901
- if (AudioManager._needsUserGestureResume) {
44488
+ if (AudioManager._needsUserGestureResume || AudioManager._pendingSources.size > 0) {
44902
44489
  AudioManager.resume().catch(function(e) {
44903
44490
  console.warn("Failed to resume AudioContext:", e);
44904
44491
  });
44905
44492
  }
44906
44493
  };
44494
+ AudioManager._prepareGestureResume = function _prepareGestureResume() {
44495
+ // iOS WKWebView WebKit bug(Triggered in LingGuang App): AudioContext may be in a "zombie" state where
44496
+ // state reports "suspended" but resume() alone won't restart audio rendering.
44497
+ // Calling suspend() first forces a clean internal state reset before user gesture triggers resume.
44498
+ // Related: https://bugs.webkit.org/show_bug.cgi?id=263627
44499
+ return AudioManager.suspend().catch(function() {}).then(function() {
44500
+ AudioManager._needsUserGestureResume = true;
44501
+ });
44502
+ };
44907
44503
  return AudioManager;
44908
44504
  }();
44909
44505
  /** @internal */ AudioManager._playingCount = 0;
44910
- AudioManager._resumePromise = null;
44911
44506
  AudioManager._needsUserGestureResume = false;
44507
+ AudioManager._pendingSources = new Set();
44912
44508
  /**
44913
44509
  * Audio Source Component.
44914
44510
  */ var AudioSource = /*#__PURE__*/ function(Component) {
@@ -44925,7 +44521,6 @@
44925
44521
  /**
44926
44522
  * Play the clip.
44927
44523
  */ _proto.play = function play() {
44928
- var _this = this;
44929
44524
  var _this__clip;
44930
44525
  if (!((_this__clip = this._clip) == null ? void 0 : _this__clip._getAudioSource()) || this._isPlaying || this._pendingPlay) {
44931
44526
  return;
@@ -44933,22 +44528,9 @@
44933
44528
  if (AudioManager.isAudioContextRunning()) {
44934
44529
  this._startPlayback();
44935
44530
  } else {
44936
- // iOS Safari requires resume() to be called within the same user gesture callback that triggers playback.
44937
- // Document-level events won't work - must call resume() directly here in play().
44938
44531
  this._pendingPlay = true;
44939
- AudioManager.resume().then(function() {
44940
- // Check if cancelled by stop()/pause()
44941
- if (!_this._pendingPlay) {
44942
- return;
44943
- }
44944
- _this._pendingPlay = false;
44945
- // Check if still valid to play after async resume
44946
- if (_this._destroyed || !_this.enabled || !_this._clip) {
44947
- return;
44948
- }
44949
- _this._startPlayback();
44950
- }, function(e) {
44951
- _this._pendingPlay = false;
44532
+ AudioManager._registerPendingSource(this);
44533
+ AudioManager.resume().catch(function(e) {
44952
44534
  console.warn("Failed to resume AudioContext:", e);
44953
44535
  });
44954
44536
  }
@@ -44956,7 +44538,7 @@
44956
44538
  /**
44957
44539
  * Stops playing the clip.
44958
44540
  */ _proto.stop = function stop() {
44959
- this._pendingPlay = false;
44541
+ this._cancelPendingPlayback();
44960
44542
  if (this._isPlaying) {
44961
44543
  this._clearSourceNode();
44962
44544
  this._isPlaying = false;
@@ -44968,7 +44550,7 @@
44968
44550
  /**
44969
44551
  * Pauses playing the clip.
44970
44552
  */ _proto.pause = function pause() {
44971
- this._pendingPlay = false;
44553
+ this._cancelPendingPlayback();
44972
44554
  if (this._isPlaying) {
44973
44555
  this._clearSourceNode();
44974
44556
  this._pausedTime = AudioManager.getContext().currentTime;
@@ -45003,6 +44585,17 @@
45003
44585
  _proto._onPlayEnd = function _onPlayEnd() {
45004
44586
  this.stop();
45005
44587
  };
44588
+ /** @internal */ _proto._resumePendingPlayback = function _resumePendingPlayback() {
44589
+ var _this__clip;
44590
+ if (!this._pendingPlay) {
44591
+ return;
44592
+ }
44593
+ this._pendingPlay = false;
44594
+ if (this._destroyed || !this.enabled || !((_this__clip = this._clip) == null ? void 0 : _this__clip._getAudioSource())) {
44595
+ return;
44596
+ }
44597
+ this._startPlayback();
44598
+ };
45006
44599
  _proto._startPlayback = function _startPlayback() {
45007
44600
  var startTime = this._pausedTime > 0 ? this._pausedTime - this._playTime : 0;
45008
44601
  this._initSourceNode(startTime);
@@ -45028,6 +44621,13 @@
45028
44621
  this._sourceNode.onended = null;
45029
44622
  this._sourceNode = null;
45030
44623
  };
44624
+ _proto._cancelPendingPlayback = function _cancelPendingPlayback() {
44625
+ if (!this._pendingPlay) {
44626
+ return;
44627
+ }
44628
+ this._pendingPlay = false;
44629
+ AudioManager._unregisterPendingSource(this);
44630
+ };
45031
44631
  _create_class$2(AudioSource, [
45032
44632
  {
45033
44633
  key: "clip",
@@ -45447,7 +45047,6 @@
45447
45047
  MeshShape: MeshShape,
45448
45048
  MeshTopology: MeshTopology,
45449
45049
  ModelMesh: ModelMesh,
45450
- NoiseModule: NoiseModule,
45451
45050
  OverflowMode: OverflowMode,
45452
45051
  PBRMaterial: PBRMaterial,
45453
45052
  ParticleCompositeCurve: ParticleCompositeCurve,
@@ -46641,7 +46240,7 @@
46641
46240
  };
46642
46241
  case TextureFormat.ETC2_RGBA5:
46643
46242
  return {
46644
- internalFormat: isSRGBColorSpace ? GLCompressedTextureInternalFormat.SRGB8_PUNCHTHROUGH_ALPHA1_ETC2 : GLCompressedTextureInternalFormat.RGB8_PUNCHTHROUGH_ALPHA1_ETC2,
46243
+ internalFormat: GLCompressedTextureInternalFormat.RGB8_PUNCHTHROUGH_ALPHA1_ETC2,
46645
46244
  isCompressed: true
46646
46245
  };
46647
46246
  case TextureFormat.ETC2_RGBA8:
@@ -46676,27 +46275,27 @@
46676
46275
  };
46677
46276
  case TextureFormat.ASTC_5x5:
46678
46277
  return {
46679
- internalFormat: isSRGBColorSpace ? GLCompressedTextureInternalFormat.SRGB8_ALPHA8_ASTC_5X5_KHR : GLCompressedTextureInternalFormat.RGBA_ASTC_5X5_KHR,
46278
+ internalFormat: GLCompressedTextureInternalFormat.RGBA_ASTC_5X5_KHR,
46680
46279
  isCompressed: true
46681
46280
  };
46682
46281
  case TextureFormat.ASTC_6x6:
46683
46282
  return {
46684
- internalFormat: isSRGBColorSpace ? GLCompressedTextureInternalFormat.SRGB8_ALPHA8_ASTC_6X6_KHR : GLCompressedTextureInternalFormat.RGBA_ASTC_6X6_KHR,
46283
+ internalFormat: GLCompressedTextureInternalFormat.RGBA_ASTC_6X6_KHR,
46685
46284
  isCompressed: true
46686
46285
  };
46687
46286
  case TextureFormat.ASTC_8x8:
46688
46287
  return {
46689
- internalFormat: isSRGBColorSpace ? GLCompressedTextureInternalFormat.SRGB8_ALPHA8_ASTC_8X8_KHR : GLCompressedTextureInternalFormat.RGBA_ASTC_8X8_KHR,
46288
+ internalFormat: GLCompressedTextureInternalFormat.RGBA_ASTC_8X8_KHR,
46690
46289
  isCompressed: true
46691
46290
  };
46692
46291
  case TextureFormat.ASTC_10x10:
46693
46292
  return {
46694
- internalFormat: isSRGBColorSpace ? GLCompressedTextureInternalFormat.SRGB8_ALPHA8_ASTC_10X10_KHR : GLCompressedTextureInternalFormat.RGBA_ASTC_10X10_KHR,
46293
+ internalFormat: GLCompressedTextureInternalFormat.RGBA_ASTC_10X10_KHR,
46695
46294
  isCompressed: true
46696
46295
  };
46697
46296
  case TextureFormat.ASTC_12x12:
46698
46297
  return {
46699
- internalFormat: isSRGBColorSpace ? GLCompressedTextureInternalFormat.SRGB8_ALPHA8_ASTC_12X12_KHR : GLCompressedTextureInternalFormat.RGBA_ASTC_12X12_KHR,
46298
+ internalFormat: GLCompressedTextureInternalFormat.RGBA_ASTC_12X12_KHR,
46700
46299
  isCompressed: true
46701
46300
  };
46702
46301
  case TextureFormat.Depth:
@@ -48978,189 +48577,11 @@
48978
48577
  };
48979
48578
  return ReflectionParser;
48980
48579
  }();
48981
- /**
48982
- * HDR (Radiance RGBE) image decoder.
48983
- *
48984
- * Decodes .hdr files into pixel data. Supports parsing the header
48985
- * and decoding RLE-compressed RGBE scanlines into R16G16B16A16 half-float pixels.
48986
- */ var HDRDecoder = /*#__PURE__*/ function() {
48987
- function HDRDecoder() {}
48988
- /**
48989
- * Parse the header of an HDR file.
48990
- * @returns Header info including width, height, and data start position.
48991
- */ HDRDecoder.parseHeader = function parseHeader(uint8array) {
48992
- var line = this._readStringLine(uint8array, 0);
48993
- if (line[0] !== "#" || line[1] !== "?") {
48994
- throw "HDRDecoder: invalid file header";
48995
- }
48996
- var endOfHeader = false;
48997
- var findFormat = false;
48998
- var lineIndex = 0;
48999
- do {
49000
- lineIndex += line.length + 1;
49001
- line = this._readStringLine(uint8array, lineIndex);
49002
- if (line === "FORMAT=32-bit_rle_rgbe") findFormat = true;
49003
- else if (line.length === 0) endOfHeader = true;
49004
- }while (!endOfHeader);
49005
- if (!findFormat) {
49006
- throw "HDRDecoder: unsupported format, expected 32-bit_rle_rgbe";
49007
- }
49008
- lineIndex += line.length + 1;
49009
- line = this._readStringLine(uint8array, lineIndex);
49010
- var match = /^\-Y (.*) \+X (.*)$/g.exec(line);
49011
- if (!match || match.length < 3) {
49012
- throw "HDRDecoder: missing image size, only -Y +X layout is supported";
49013
- }
49014
- var width = parseInt(match[2]);
49015
- var height = parseInt(match[1]);
49016
- if (width < 8 || width > 0x7fff) {
49017
- throw "HDRDecoder: unsupported image width, must be between 8 and 32767";
49018
- }
49019
- return {
49020
- height: height,
49021
- width: width,
49022
- dataPosition: lineIndex + line.length + 1
49023
- };
49024
- };
49025
- /**
49026
- * Decode an HDR file buffer into R16G16B16A16 half-float pixel data.
49027
- * @param buffer - The full HDR file as Uint8Array.
49028
- * @returns Object with width, height, and half-float pixel data.
49029
- */ HDRDecoder.decode = function decode(buffer) {
49030
- var header = this.parseHeader(buffer);
49031
- var width = header.width, height = header.height, dataPosition = header.dataPosition;
49032
- var rgbe = this._readPixels(buffer.subarray(dataPosition), width, height);
49033
- var pixels = this._rgbeToHalfFloat(rgbe, width, height);
49034
- return {
49035
- width: width,
49036
- height: height,
49037
- pixels: pixels
49038
- };
49039
- };
49040
- /**
49041
- * Convert RGBE pixel data to R16G16B16A16 half-float.
49042
- */ HDRDecoder._rgbeToHalfFloat = function _rgbeToHalfFloat(rgbe, width, height) {
49043
- var floatView = this._floatView;
49044
- var uint32View = this._uint32View;
49045
- var _this__float2HalfTables = this._float2HalfTables, baseTable = _this__float2HalfTables.baseTable, shiftTable = _this__float2HalfTables.shiftTable;
49046
- var one = 0x3c00; // Half float 1.0
49047
- var pixelCount = width * height;
49048
- var result = new Uint16Array(pixelCount * 4);
49049
- for(var i = 0; i < pixelCount; i++){
49050
- var srcIdx = i * 4;
49051
- var dstIdx = i * 4;
49052
- var scaleFactor = Math.pow(2, rgbe[srcIdx + 3] - 128 - 8);
49053
- for(var c = 0; c < 3; c++){
49054
- floatView[0] = Math.min(rgbe[srcIdx + c] * scaleFactor, 65504);
49055
- var f = uint32View[0];
49056
- var e = f >> 23 & 0x1ff;
49057
- result[dstIdx + c] = baseTable[e] + ((f & 0x007fffff) >> shiftTable[e]);
49058
- }
49059
- result[dstIdx + 3] = one;
49060
- }
49061
- return result;
49062
- };
49063
- /**
49064
- * Decode RLE-compressed RGBE scanlines into raw RGBE pixel data.
49065
- */ HDRDecoder._readPixels = function _readPixels(buffer, width, height) {
49066
- var byteLength = buffer.byteLength;
49067
- var dataRGBA = new Uint8Array(4 * width * height);
49068
- var offset = 0;
49069
- var pos = 0;
49070
- var ptrEnd = 4 * width;
49071
- var scanLineBuffer = new Uint8Array(ptrEnd);
49072
- var numScanLines = height;
49073
- while(numScanLines > 0 && pos < byteLength){
49074
- var a = buffer[pos++];
49075
- var b = buffer[pos++];
49076
- var c = buffer[pos++];
49077
- var d = buffer[pos++];
49078
- if (a !== 2 || b !== 2 || c & 0x80 || width < 8 || width > 32767) return buffer;
49079
- if ((c << 8 | d) !== width) throw "HDRDecoder: wrong scanline width";
49080
- var ptr = 0;
49081
- while(ptr < ptrEnd && pos < byteLength){
49082
- var count = buffer[pos++];
49083
- var isEncodedRun = count > 128;
49084
- if (isEncodedRun) count -= 128;
49085
- if (count === 0 || ptr + count > ptrEnd) throw "HDRDecoder: bad scanline data";
49086
- if (isEncodedRun) {
49087
- var byteValue = buffer[pos++];
49088
- for(var i = 0; i < count; i++)scanLineBuffer[ptr++] = byteValue;
49089
- } else {
49090
- scanLineBuffer.set(buffer.subarray(pos, pos + count), ptr);
49091
- ptr += count;
49092
- pos += count;
49093
- }
49094
- }
49095
- for(var i1 = 0; i1 < width; i1++, offset += 4){
49096
- dataRGBA[offset] = scanLineBuffer[i1];
49097
- dataRGBA[offset + 1] = scanLineBuffer[i1 + width];
49098
- dataRGBA[offset + 2] = scanLineBuffer[i1 + width * 2];
49099
- dataRGBA[offset + 3] = scanLineBuffer[i1 + width * 3];
49100
- }
49101
- numScanLines--;
49102
- }
49103
- return dataRGBA;
49104
- };
49105
- HDRDecoder._generateFloat2HalfTables = function _generateFloat2HalfTables() {
49106
- var baseTable = new Uint32Array(512);
49107
- var shiftTable = new Uint32Array(512);
49108
- for(var i = 0; i < 256; ++i){
49109
- var e = i - 127;
49110
- if (e < -27) {
49111
- baseTable[i] = 0x0000;
49112
- baseTable[i | 0x100] = 0x8000;
49113
- shiftTable[i] = 24;
49114
- shiftTable[i | 0x100] = 24;
49115
- } else if (e < -14) {
49116
- baseTable[i] = 0x0400 >> -e - 14;
49117
- baseTable[i | 0x100] = 0x0400 >> -e - 14 | 0x8000;
49118
- shiftTable[i] = -e - 1;
49119
- shiftTable[i | 0x100] = -e - 1;
49120
- } else if (e <= 15) {
49121
- baseTable[i] = e + 15 << 10;
49122
- baseTable[i | 0x100] = e + 15 << 10 | 0x8000;
49123
- shiftTable[i] = 13;
49124
- shiftTable[i | 0x100] = 13;
49125
- } else if (e < 128) {
49126
- baseTable[i] = 0x7c00;
49127
- baseTable[i | 0x100] = 0xfc00;
49128
- shiftTable[i] = 24;
49129
- shiftTable[i | 0x100] = 24;
49130
- } else {
49131
- baseTable[i] = 0x7c00;
49132
- baseTable[i | 0x100] = 0xfc00;
49133
- shiftTable[i] = 13;
49134
- shiftTable[i | 0x100] = 13;
49135
- }
49136
- }
49137
- return {
49138
- baseTable: baseTable,
49139
- shiftTable: shiftTable
49140
- };
49141
- };
49142
- HDRDecoder._readStringLine = function _readStringLine(uint8array, startIndex) {
49143
- var line = "";
49144
- for(var i = startIndex, n = uint8array.length; i < n; i++){
49145
- var character = String.fromCharCode(uint8array[i]);
49146
- if (character === "\n") break;
49147
- line += character;
49148
- }
49149
- return line;
49150
- };
49151
- return HDRDecoder;
49152
- }();
49153
- HDRDecoder._float2HalfTables = HDRDecoder._generateFloat2HalfTables();
49154
- HDRDecoder._floatView = new Float32Array(1);
49155
- HDRDecoder._uint32View = new Uint32Array(HDRDecoder._floatView.buffer);
49156
- /**
49157
- * Data format: [url] [mipmap(1B)] [filterMode(1B)] [anisoLevel(1B)] [wrapModeU(1B)] [wrapModeV(1B)]
49158
- * [format(1B)] [width(2B)] [height(2B)] [isSRGBColorSpace(1B)] [Uint32(imageSize) + imageBytes]
49159
- */ var Texture2DDecoder = /*#__PURE__*/ function() {
48580
+ exports.Texture2DDecoder = /*#__PURE__*/ function() {
49160
48581
  function Texture2DDecoder() {}
49161
48582
  Texture2DDecoder.decode = function decode(engine, bufferReader, restoredTexture) {
49162
48583
  return new AssetPromise(function(resolve, reject) {
49163
- bufferReader.nextStr();
48584
+ var url = bufferReader.nextStr();
49164
48585
  var mipmap = !!bufferReader.nextUint8();
49165
48586
  var filterMode = bufferReader.nextUint8();
49166
48587
  var anisoLevel = bufferReader.nextUint8();
@@ -49169,34 +48590,58 @@
49169
48590
  var format = bufferReader.nextUint8();
49170
48591
  var width = bufferReader.nextUint16();
49171
48592
  var height = bufferReader.nextUint16();
48593
+ var isPixelBuffer = bufferReader.nextUint8();
49172
48594
  var isSRGBColorSpace = !!bufferReader.nextUint8();
49173
- var imageData = bufferReader.nextImagesData(1)[0];
49174
- var isHDR = imageData[0] === 0x23 && imageData[1] === 0x3f;
49175
- var textureFormat = isHDR ? TextureFormat.R16G16B16A16 : format;
49176
- var texture = restoredTexture || new Texture2D(engine, width, height, textureFormat, mipmap, isHDR ? false : isSRGBColorSpace);
49177
- texture.filterMode = filterMode;
49178
- texture.anisoLevel = anisoLevel;
49179
- texture.wrapModeU = wrapModeU;
49180
- texture.wrapModeV = wrapModeV;
49181
- if (isHDR) {
49182
- var pixels = HDRDecoder.decode(imageData).pixels;
49183
- texture.setPixelBuffer(pixels);
49184
- mipmap && texture.generateMipmaps();
49185
- resolve(texture);
48595
+ var mipCount = bufferReader.nextUint8();
48596
+ var imagesData = bufferReader.nextImagesData(mipCount);
48597
+ var texture2D = restoredTexture || new Texture2D(engine, width, height, format, mipmap, isSRGBColorSpace);
48598
+ texture2D.filterMode = filterMode;
48599
+ texture2D.anisoLevel = anisoLevel;
48600
+ texture2D.wrapModeU = wrapModeU;
48601
+ texture2D.wrapModeV = wrapModeV;
48602
+ if (isPixelBuffer) {
48603
+ var pixelBuffer = imagesData[0];
48604
+ texture2D.setPixelBuffer(pixelBuffer);
48605
+ if (mipmap) {
48606
+ texture2D.generateMipmaps();
48607
+ for(var i = 1; i < mipCount; i++){
48608
+ var pixelBuffer1 = imagesData[i];
48609
+ texture2D.setPixelBuffer(pixelBuffer1, i);
48610
+ }
48611
+ }
48612
+ // @ts-ignore
48613
+ engine.resourceManager._objectPool[url] = texture2D;
48614
+ resolve(texture2D);
49186
48615
  } else {
49187
- var blob = new Blob([
49188
- imageData
48616
+ var blob = new window.Blob([
48617
+ imagesData[0]
49189
48618
  ]);
49190
48619
  var img = new Image();
49191
48620
  img.onload = function() {
49192
- URL.revokeObjectURL(img.src);
49193
- texture.setImageSource(img);
49194
- mipmap && texture.generateMipmaps();
49195
- resolve(texture);
49196
- };
49197
- img.onerror = function(e) {
49198
- URL.revokeObjectURL(img.src);
49199
- reject(e);
48621
+ texture2D.setImageSource(img);
48622
+ var completedCount = 0;
48623
+ var onComplete = function onComplete() {
48624
+ completedCount++;
48625
+ if (completedCount >= mipCount) {
48626
+ resolve(texture2D);
48627
+ }
48628
+ };
48629
+ onComplete();
48630
+ if (mipmap) {
48631
+ var _loop = function _loop(i) {
48632
+ var blob = new window.Blob([
48633
+ imagesData[i]
48634
+ ]);
48635
+ var img = new Image();
48636
+ img.onload = function() {
48637
+ texture2D.setImageSource(img, i);
48638
+ onComplete();
48639
+ };
48640
+ img.src = URL.createObjectURL(blob);
48641
+ };
48642
+ texture2D.generateMipmaps();
48643
+ for(var i = 1; i < mipCount; i++)_loop(i);
48644
+ }
49200
48645
  };
49201
48646
  img.src = URL.createObjectURL(blob);
49202
48647
  }
@@ -49204,71 +48649,9 @@
49204
48649
  };
49205
48650
  return Texture2DDecoder;
49206
48651
  }();
49207
- Texture2DDecoder = __decorate([
48652
+ exports.Texture2DDecoder = __decorate([
49208
48653
  decoder("Texture2D")
49209
- ], Texture2DDecoder);
49210
- /**
49211
- * Data format: [url] [mipmap(1B)] [filterMode(1B)] [anisoLevel(1B)] [wrapModeU(1B)] [wrapModeV(1B)]
49212
- * [format(1B)] [faceSize(2B)] [isSRGBColorSpace(1B)] [Uint32(size) + faceBytes] × 6
49213
- */ var TextureCubeDecoder = /*#__PURE__*/ function() {
49214
- function TextureCubeDecoder() {}
49215
- TextureCubeDecoder.decode = function decode(engine, bufferReader, restoredTexture) {
49216
- return new AssetPromise(function(resolve, reject) {
49217
- bufferReader.nextStr();
49218
- var mipmap = !!bufferReader.nextUint8();
49219
- var filterMode = bufferReader.nextUint8();
49220
- var anisoLevel = bufferReader.nextUint8();
49221
- var wrapModeU = bufferReader.nextUint8();
49222
- var wrapModeV = bufferReader.nextUint8();
49223
- var format = bufferReader.nextUint8();
49224
- var faceSize = bufferReader.nextUint16();
49225
- var isSRGBColorSpace = !!bufferReader.nextUint8();
49226
- var facesData = bufferReader.nextImagesData(6);
49227
- // Detect format by first face's magic bytes
49228
- var isHDR = facesData[0][0] === 0x23 && facesData[0][1] === 0x3f;
49229
- var textureFormat = isHDR ? TextureFormat.R16G16B16A16 : format;
49230
- var texture = restoredTexture || new TextureCube(engine, faceSize, textureFormat, mipmap, isSRGBColorSpace);
49231
- texture.filterMode = filterMode;
49232
- texture.anisoLevel = anisoLevel;
49233
- texture.wrapModeU = wrapModeU;
49234
- texture.wrapModeV = wrapModeV;
49235
- if (isHDR) {
49236
- for(var i = 0; i < 6; i++){
49237
- var pixels = HDRDecoder.decode(facesData[i]).pixels;
49238
- texture.setPixelBuffer(TextureCubeFace.PositiveX + i, pixels, 0);
49239
- }
49240
- mipmap && texture.generateMipmaps();
49241
- resolve(texture);
49242
- } else {
49243
- var _loop = function _loop(i1) {
49244
- var blob = new Blob([
49245
- facesData[i1]
49246
- ]);
49247
- var img = new Image();
49248
- img.onload = function() {
49249
- URL.revokeObjectURL(img.src);
49250
- texture.setImageSource(TextureCubeFace.PositiveX + i1, img);
49251
- if (++loadedCount === 6) {
49252
- mipmap && texture.generateMipmaps();
49253
- resolve(texture);
49254
- }
49255
- };
49256
- img.onerror = function(e) {
49257
- URL.revokeObjectURL(img.src);
49258
- reject(e);
49259
- };
49260
- img.src = URL.createObjectURL(blob);
49261
- };
49262
- var loadedCount = 0;
49263
- for(var i1 = 0; i1 < 6; i1++)_loop(i1);
49264
- }
49265
- });
49266
- };
49267
- return TextureCubeDecoder;
49268
- }();
49269
- TextureCubeDecoder = __decorate([
49270
- decoder("TextureCube")
49271
- ], TextureCubeDecoder);
48654
+ ], exports.Texture2DDecoder);
49272
48655
  function _instanceof1(left, right) {
49273
48656
  if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
49274
48657
  return !!right[Symbol.hasInstance](left);
@@ -51839,13 +51222,11 @@
51839
51222
  });
51840
51223
  var img = new Image();
51841
51224
  img.onerror = function() {
51842
- URL.revokeObjectURL(img.src);
51843
51225
  reject(new Error("Failed to load image buffer"));
51844
51226
  };
51845
51227
  img.onload = function() {
51846
51228
  // Call requestAnimationFrame to avoid iOS's bug.
51847
51229
  requestAnimationFrame(function() {
51848
- URL.revokeObjectURL(img.src);
51849
51230
  resolve(img);
51850
51231
  img.onload = null;
51851
51232
  img.onerror = null;
@@ -53298,7 +52679,7 @@
53298
52679
  if (uri) {
53299
52680
  var extIndex = uri.lastIndexOf(".");
53300
52681
  var ext = uri.substring(extIndex + 1);
53301
- var type = ext.startsWith("ktx") ? AssetType.KTX : AssetType.Texture;
52682
+ var type = ext.startsWith("ktx") ? AssetType.KTX : AssetType.Texture2D;
53302
52683
  texture = engine.resourceManager.load({
53303
52684
  url: Utils.resolveAbsoluteUrl(url, uri),
53304
52685
  type: type,
@@ -54155,7 +53536,7 @@
54155
53536
  var _atlasItem_type;
54156
53537
  chainPromises.push(resourceManager.load({
54157
53538
  url: Utils.resolveAbsoluteUrl(item.url, atlasItem.img),
54158
- type: (_atlasItem_type = atlasItem.type) != null ? _atlasItem_type : AssetType.Texture,
53539
+ type: (_atlasItem_type = atlasItem.type) != null ? _atlasItem_type : AssetType.Texture2D,
54159
53540
  params: {
54160
53541
  format: format,
54161
53542
  mipmap: mipmap
@@ -54290,12 +53671,26 @@
54290
53671
  "txt"
54291
53672
  ])
54292
53673
  ], TextLoader);
54293
- var TextureLoader = /*#__PURE__*/ function(Loader) {
54294
- _inherits(TextureLoader, Loader);
54295
- function TextureLoader() {
53674
+ function loadImageFromBuffer(buffer) {
53675
+ return new AssetPromise(function(resolve, reject) {
53676
+ var blob = new Blob([
53677
+ buffer
53678
+ ]);
53679
+ var img = new Image();
53680
+ img.onload = function() {
53681
+ URL.revokeObjectURL(img.src);
53682
+ resolve(img);
53683
+ };
53684
+ img.onerror = reject;
53685
+ img.src = URL.createObjectURL(blob);
53686
+ });
53687
+ }
53688
+ var Texture2DLoader = /*#__PURE__*/ function(Loader) {
53689
+ _inherits(Texture2DLoader, Loader);
53690
+ function Texture2DLoader() {
54296
53691
  return Loader.apply(this, arguments) || this;
54297
53692
  }
54298
- var _proto = TextureLoader.prototype;
53693
+ var _proto = Texture2DLoader.prototype;
54299
53694
  _proto.load = function load(item, resourceManager) {
54300
53695
  var _this = this;
54301
53696
  var url = item.url;
@@ -54305,136 +53700,427 @@
54305
53700
  return new AssetPromise(function(resolve, reject, setTaskCompleteProgress, setTaskDetailProgress) {
54306
53701
  resourceManager // @ts-ignore
54307
53702
  ._request(url, requestConfig).onProgress(setTaskCompleteProgress, setTaskDetailProgress).then(function(buffer) {
54308
- _this._decode(buffer, item, resourceManager).then(function(texture) {
54309
- resourceManager.addContentRestorer(new TextureContentRestorer(texture, url, requestConfig));
54310
- resolve(texture);
54311
- }, reject);
53703
+ if (FileHeader.checkMagic(buffer)) {
53704
+ decode(buffer, resourceManager.engine).then(function(texture) {
53705
+ resourceManager.addContentRestorer(new Texture2DContentRestorer(texture, url, requestConfig));
53706
+ resolve(texture);
53707
+ }, reject);
53708
+ } else {
53709
+ loadImageFromBuffer(buffer).then(function(img) {
53710
+ var texture = _this._createTexture(img, item, resourceManager);
53711
+ resourceManager.addContentRestorer(new Texture2DContentRestorer(texture, url, requestConfig));
53712
+ resolve(texture);
53713
+ }, reject);
53714
+ }
54312
53715
  }).catch(reject);
54313
53716
  });
54314
53717
  };
54315
- _proto._decode = function _decode(buffer, item, resourceManager) {
54316
- if (FileHeader.checkMagic(buffer)) {
54317
- return decode(buffer, resourceManager.engine);
54318
- }
54319
- var bufferView = new Uint8Array(buffer);
54320
- var isHDR = bufferView[0] === 0x23 && bufferView[1] === 0x3f;
54321
- if (isHDR) {
54322
- return this._decodeHDR(bufferView, item, resourceManager);
54323
- }
54324
- return this._decodeImage(buffer, item, resourceManager);
54325
- };
54326
- _proto._decodeHDR = function _decodeHDR(buffer, item, resourceManager) {
54327
- var _this = this;
54328
- return new AssetPromise(function(resolve, reject) {
54329
- var engine = resourceManager.engine;
54330
- if (!SystemInfo.supportsTextureFormat(engine, TextureFormat.R16G16B16A16)) {
54331
- reject(new Error("TextureLoader: HDR texture requires half float support."));
54332
- return;
54333
- }
54334
- var _HDRDecoder_decode = HDRDecoder.decode(buffer), width = _HDRDecoder_decode.width, height = _HDRDecoder_decode.height, pixels = _HDRDecoder_decode.pixels;
54335
- var _item_params;
54336
- var _ref = (_item_params = item.params) != null ? _item_params : {}, _ref_mipmap = _ref.mipmap, mipmap = _ref_mipmap === void 0 ? true : _ref_mipmap;
54337
- var texture = new Texture2D(engine, width, height, TextureFormat.R16G16B16A16, mipmap, false);
54338
- texture.setPixelBuffer(pixels);
54339
- mipmap && texture.generateMipmaps();
54340
- _this._applyParams(texture, item);
54341
- resolve(texture);
54342
- });
54343
- };
54344
- _proto._decodeImage = function _decodeImage(buffer, item, resourceManager) {
54345
- var _this = this;
54346
- return new AssetPromise(function(resolve, reject) {
54347
- var blob = new Blob([
54348
- buffer
54349
- ]);
54350
- var img = new Image();
54351
- img.onload = function() {
54352
- URL.revokeObjectURL(img.src);
54353
- var _item_params;
54354
- var _ref = (_item_params = item.params) != null ? _item_params : {}, _ref_format = _ref.format, format = _ref_format === void 0 ? TextureFormat.R8G8B8A8 : _ref_format, _ref_isSRGBColorSpace = _ref.isSRGBColorSpace, isSRGBColorSpace = _ref_isSRGBColorSpace === void 0 ? true : _ref_isSRGBColorSpace, _ref_mipmap = _ref.mipmap, mipmap = _ref_mipmap === void 0 ? true : _ref_mipmap;
54355
- var engine = resourceManager.engine;
54356
- var width = img.width, height = img.height;
54357
- var generateMipmap = TextureUtils.supportGenerateMipmapsWithCorrection(engine, width, height, format, mipmap, isSRGBColorSpace);
54358
- var texture = new Texture2D(engine, width, height, format, generateMipmap, isSRGBColorSpace);
54359
- texture.setImageSource(img);
54360
- generateMipmap && texture.generateMipmaps();
54361
- _this._applyParams(texture, item);
54362
- resolve(texture);
54363
- };
54364
- img.onerror = function(e) {
54365
- URL.revokeObjectURL(img.src);
54366
- reject(e);
54367
- };
54368
- img.src = URL.createObjectURL(blob);
54369
- });
54370
- };
54371
- _proto._applyParams = function _applyParams(texture, item) {
53718
+ _proto._createTexture = function _createTexture(img, item, resourceManager) {
54372
53719
  var _item_params;
54373
- var _ref = (_item_params = item.params) != null ? _item_params : {}, anisoLevel = _ref.anisoLevel, wrapModeU = _ref.wrapModeU, wrapModeV = _ref.wrapModeV, filterMode = _ref.filterMode;
53720
+ var _ref = (_item_params = item.params) != null ? _item_params : {}, _ref_format = _ref.format, format = _ref_format === void 0 ? TextureFormat.R8G8B8A8 : _ref_format, anisoLevel = _ref.anisoLevel, wrapModeU = _ref.wrapModeU, wrapModeV = _ref.wrapModeV, filterMode = _ref.filterMode, _ref_isSRGBColorSpace = _ref.isSRGBColorSpace, isSRGBColorSpace = _ref_isSRGBColorSpace === void 0 ? true : _ref_isSRGBColorSpace, _ref_mipmap = _ref.mipmap, mipmap = _ref_mipmap === void 0 ? true : _ref_mipmap;
53721
+ var width = img.width, height = img.height;
53722
+ var engine = resourceManager.engine;
53723
+ var generateMipmap = TextureUtils.supportGenerateMipmapsWithCorrection(engine, width, height, format, mipmap, isSRGBColorSpace);
53724
+ var texture = new Texture2D(engine, width, height, format, generateMipmap, isSRGBColorSpace);
54374
53725
  texture.anisoLevel = anisoLevel != null ? anisoLevel : texture.anisoLevel;
54375
53726
  texture.filterMode = filterMode != null ? filterMode : texture.filterMode;
54376
53727
  texture.wrapModeU = wrapModeU != null ? wrapModeU : texture.wrapModeU;
54377
53728
  texture.wrapModeV = wrapModeV != null ? wrapModeV : texture.wrapModeV;
53729
+ texture.setImageSource(img);
53730
+ generateMipmap && texture.generateMipmaps();
54378
53731
  var url = item.url;
54379
53732
  if (url.indexOf("data:") !== 0) {
54380
53733
  texture.name = url.substring(url.lastIndexOf("/") + 1);
54381
53734
  }
53735
+ return texture;
54382
53736
  };
54383
- return TextureLoader;
53737
+ return Texture2DLoader;
54384
53738
  }(Loader);
54385
- TextureLoader = __decorate([
54386
- resourceLoader(AssetType.Texture, [
54387
- "tex",
53739
+ Texture2DLoader = __decorate([
53740
+ resourceLoader(AssetType.Texture2D, [
54388
53741
  "png",
54389
53742
  "jpg",
54390
53743
  "webp",
54391
53744
  "jpeg",
54392
- "hdr"
53745
+ "tex"
54393
53746
  ])
54394
- ], TextureLoader);
54395
- var TextureContentRestorer = /*#__PURE__*/ function(ContentRestorer) {
54396
- _inherits(TextureContentRestorer, ContentRestorer);
54397
- function TextureContentRestorer(resource, url, requestConfig) {
53747
+ ], Texture2DLoader);
53748
+ var Texture2DContentRestorer = /*#__PURE__*/ function(ContentRestorer) {
53749
+ _inherits(Texture2DContentRestorer, ContentRestorer);
53750
+ function Texture2DContentRestorer(resource, url, requestConfig) {
54398
53751
  var _this;
54399
53752
  _this = ContentRestorer.call(this, resource) || this, _this.url = url, _this.requestConfig = requestConfig;
54400
53753
  return _this;
54401
53754
  }
54402
- var _proto = TextureContentRestorer.prototype;
53755
+ var _proto = Texture2DContentRestorer.prototype;
54403
53756
  _proto.restoreContent = function restoreContent() {
54404
- var _this = this;
54405
- return this.resource.engine.resourceManager // @ts-ignore
53757
+ var texture = this.resource;
53758
+ var engine = texture.engine;
53759
+ return engine.resourceManager // @ts-ignore
54406
53760
  ._request(this.url, this.requestConfig).then(function(buffer) {
54407
53761
  if (FileHeader.checkMagic(buffer)) {
54408
- return decode(buffer, _this.resource.engine, _this.resource);
54409
- }
54410
- var bufferView = new Uint8Array(buffer);
54411
- var texture = _this.resource;
54412
- if (bufferView[0] === 0x23 && bufferView[1] === 0x3f) {
54413
- var pixels = HDRDecoder.decode(bufferView).pixels;
54414
- texture.setPixelBuffer(pixels);
54415
- texture.mipmapCount > 1 && texture.generateMipmaps();
54416
- return texture;
54417
- }
54418
- return new AssetPromise(function(resolve, reject) {
54419
- var blob = new Blob([
54420
- buffer
54421
- ]);
54422
- var img = new Image();
54423
- img.onload = function() {
54424
- URL.revokeObjectURL(img.src);
53762
+ return decode(buffer, engine, texture);
53763
+ } else {
53764
+ return loadImageFromBuffer(buffer).then(function(img) {
54425
53765
  texture.setImageSource(img);
54426
- texture.mipmapCount > 1 && texture.generateMipmaps();
54427
- resolve(texture);
54428
- };
54429
- img.onerror = function(e) {
54430
- URL.revokeObjectURL(img.src);
54431
- reject(e);
54432
- };
54433
- img.src = URL.createObjectURL(blob);
53766
+ texture.generateMipmaps();
53767
+ return texture;
53768
+ });
53769
+ }
53770
+ });
53771
+ };
53772
+ return Texture2DContentRestorer;
53773
+ }(ContentRestorer);
53774
+ /**
53775
+ * HDR panorama to cubemap decoder.
53776
+ */ var HDRDecoder = /*#__PURE__*/ function() {
53777
+ function HDRDecoder() {}
53778
+ HDRDecoder.parseHeader = function parseHeader(uint8array) {
53779
+ var line = this._readStringLine(uint8array, 0);
53780
+ if (line[0] !== "#" || line[1] !== "?") {
53781
+ throw "HDRDecoder: invalid file header";
53782
+ }
53783
+ var endOfHeader = false;
53784
+ var findFormat = false;
53785
+ var lineIndex = 0;
53786
+ do {
53787
+ lineIndex += line.length + 1;
53788
+ line = this._readStringLine(uint8array, lineIndex);
53789
+ if (line === "FORMAT=32-bit_rle_rgbe") findFormat = true;
53790
+ else if (line.length === 0) endOfHeader = true;
53791
+ }while (!endOfHeader);
53792
+ if (!findFormat) {
53793
+ throw "HDRDecoder: unsupported format, expected 32-bit_rle_rgbe";
53794
+ }
53795
+ lineIndex += line.length + 1;
53796
+ line = this._readStringLine(uint8array, lineIndex);
53797
+ var match = /^\-Y (.*) \+X (.*)$/g.exec(line);
53798
+ if (!match || match.length < 3) {
53799
+ throw "HDRDecoder: missing image size, only -Y +X layout is supported";
53800
+ }
53801
+ var width = parseInt(match[2]);
53802
+ var height = parseInt(match[1]);
53803
+ if (width < 8 || width > 0x7fff) {
53804
+ throw "HDRDecoder: unsupported image width, must be between 8 and 32767";
53805
+ }
53806
+ return {
53807
+ height: height,
53808
+ width: width,
53809
+ dataPosition: lineIndex + line.length + 1
53810
+ };
53811
+ };
53812
+ HDRDecoder.decodeFaces = function decodeFaces(bufferArray, header, onFace) {
53813
+ var width = header.width, height = header.height, dataPosition = header.dataPosition;
53814
+ var cubeSize = height >> 1;
53815
+ var pixels = HDRDecoder._readPixels(bufferArray.subarray(dataPosition), width, height);
53816
+ var faces = HDRDecoder._faces;
53817
+ var faceBuffer = new Uint16Array(cubeSize * cubeSize * 4);
53818
+ for(var faceIndex = 0; faceIndex < 6; faceIndex++){
53819
+ HDRDecoder._createCubemapData(cubeSize, faces[faceIndex], pixels, width, height, faceBuffer);
53820
+ onFace(faceIndex, faceBuffer);
53821
+ }
53822
+ };
53823
+ HDRDecoder._generateFloat2HalfTables = function _generateFloat2HalfTables() {
53824
+ var baseTable = new Uint32Array(512);
53825
+ var shiftTable = new Uint32Array(512);
53826
+ for(var i = 0; i < 256; ++i){
53827
+ var e = i - 127;
53828
+ if (e < -27) {
53829
+ baseTable[i] = 0x0000;
53830
+ baseTable[i | 0x100] = 0x8000;
53831
+ shiftTable[i] = 24;
53832
+ shiftTable[i | 0x100] = 24;
53833
+ } else if (e < -14) {
53834
+ baseTable[i] = 0x0400 >> -e - 14;
53835
+ baseTable[i | 0x100] = 0x0400 >> -e - 14 | 0x8000;
53836
+ shiftTable[i] = -e - 1;
53837
+ shiftTable[i | 0x100] = -e - 1;
53838
+ } else if (e <= 15) {
53839
+ baseTable[i] = e + 15 << 10;
53840
+ baseTable[i | 0x100] = e + 15 << 10 | 0x8000;
53841
+ shiftTable[i] = 13;
53842
+ shiftTable[i | 0x100] = 13;
53843
+ } else if (e < 128) {
53844
+ baseTable[i] = 0x7c00;
53845
+ baseTable[i | 0x100] = 0xfc00;
53846
+ shiftTable[i] = 24;
53847
+ shiftTable[i | 0x100] = 24;
53848
+ } else {
53849
+ baseTable[i] = 0x7c00;
53850
+ baseTable[i | 0x100] = 0xfc00;
53851
+ shiftTable[i] = 13;
53852
+ shiftTable[i | 0x100] = 13;
53853
+ }
53854
+ }
53855
+ return {
53856
+ baseTable: baseTable,
53857
+ shiftTable: shiftTable
53858
+ };
53859
+ };
53860
+ HDRDecoder._createCubemapData = function _createCubemapData(texSize, face, pixels, inputWidth, inputHeight, facePixels) {
53861
+ var invSize = 1 / texSize;
53862
+ var rotDX1X = (face[3] - face[0]) * invSize;
53863
+ var rotDX1Y = (face[4] - face[1]) * invSize;
53864
+ var rotDX1Z = (face[5] - face[2]) * invSize;
53865
+ var rotDX2X = (face[9] - face[6]) * invSize;
53866
+ var rotDX2Y = (face[10] - face[7]) * invSize;
53867
+ var rotDX2Z = (face[11] - face[8]) * invSize;
53868
+ var floatView = HDRDecoder._floatView;
53869
+ var uint32View = HDRDecoder._uint32View;
53870
+ var _HDRDecoder__float2HalfTables = HDRDecoder._float2HalfTables, baseTable = _HDRDecoder__float2HalfTables.baseTable, shiftTable = _HDRDecoder__float2HalfTables.shiftTable;
53871
+ var one = HDRDecoder._one;
53872
+ var fy = 0;
53873
+ for(var y = 0; y < texSize; y++){
53874
+ var xv1X = face[0], xv1Y = face[1], xv1Z = face[2];
53875
+ var xv2X = face[6], xv2Y = face[7], xv2Z = face[8];
53876
+ for(var x = 0; x < texSize; x++){
53877
+ var dirX = xv1X + (xv2X - xv1X) * fy;
53878
+ var dirY = xv1Y + (xv2Y - xv1Y) * fy;
53879
+ var dirZ = xv1Z + (xv2Z - xv1Z) * fy;
53880
+ var invLen = 1 / Math.sqrt(dirX * dirX + dirY * dirY + dirZ * dirZ);
53881
+ dirX *= invLen;
53882
+ dirY *= invLen;
53883
+ dirZ *= invLen;
53884
+ var px = Math.round((Math.atan2(dirZ, dirX) / Math.PI * 0.5 + 0.5) * inputWidth);
53885
+ if (px < 0) px = 0;
53886
+ else if (px >= inputWidth) px = inputWidth - 1;
53887
+ var py = Math.round(Math.acos(dirY) / Math.PI * inputHeight);
53888
+ if (py < 0) py = 0;
53889
+ else if (py >= inputHeight) py = inputHeight - 1;
53890
+ var srcIndex = (inputHeight - py - 1) * inputWidth * 4 + px * 4;
53891
+ var scaleFactor = Math.pow(2, pixels[srcIndex + 3] - 128) / 255;
53892
+ var dstIndex = y * texSize * 4 + x * 4;
53893
+ for(var c = 0; c < 3; c++){
53894
+ // Clamp to half-float max (65504) to prevent Infinity in R16G16B16A16
53895
+ floatView[0] = Math.min(pixels[srcIndex + c] * scaleFactor, 65504);
53896
+ var f = uint32View[0];
53897
+ var e = f >> 23 & 0x1ff;
53898
+ facePixels[dstIndex + c] = baseTable[e] + ((f & 0x007fffff) >> shiftTable[e]);
53899
+ }
53900
+ facePixels[dstIndex + 3] = one;
53901
+ xv1X += rotDX1X;
53902
+ xv1Y += rotDX1Y;
53903
+ xv1Z += rotDX1Z;
53904
+ xv2X += rotDX2X;
53905
+ xv2Y += rotDX2Y;
53906
+ xv2Z += rotDX2Z;
53907
+ }
53908
+ fy += invSize;
53909
+ }
53910
+ };
53911
+ HDRDecoder._readStringLine = function _readStringLine(uint8array, startIndex) {
53912
+ var line = "";
53913
+ for(var i = startIndex, n = uint8array.length; i < n; i++){
53914
+ var character = String.fromCharCode(uint8array[i]);
53915
+ if (character === "\n") break;
53916
+ line += character;
53917
+ }
53918
+ return line;
53919
+ };
53920
+ HDRDecoder._readPixels = function _readPixels(buffer, width, height) {
53921
+ var byteLength = buffer.byteLength;
53922
+ var dataRGBA = new Uint8Array(4 * width * height);
53923
+ var offset = 0;
53924
+ var pos = 0;
53925
+ var ptrEnd = 4 * width;
53926
+ var scanLineBuffer = new Uint8Array(ptrEnd);
53927
+ var numScanLines = height;
53928
+ while(numScanLines > 0 && pos < byteLength){
53929
+ var a = buffer[pos++];
53930
+ var b = buffer[pos++];
53931
+ var c = buffer[pos++];
53932
+ var d = buffer[pos++];
53933
+ if (a !== 2 || b !== 2 || c & 0x80 || width < 8 || width > 32767) return buffer;
53934
+ if ((c << 8 | d) !== width) throw "HDRDecoder: wrong scanline width";
53935
+ var ptr = 0;
53936
+ while(ptr < ptrEnd && pos < byteLength){
53937
+ var count = buffer[pos++];
53938
+ var isEncodedRun = count > 128;
53939
+ if (isEncodedRun) count -= 128;
53940
+ if (count === 0 || ptr + count > ptrEnd) throw "HDRDecoder: bad scanline data";
53941
+ if (isEncodedRun) {
53942
+ var byteValue = buffer[pos++];
53943
+ for(var i = 0; i < count; i++)scanLineBuffer[ptr++] = byteValue;
53944
+ } else {
53945
+ scanLineBuffer.set(buffer.subarray(pos, pos + count), ptr);
53946
+ ptr += count;
53947
+ pos += count;
53948
+ }
53949
+ }
53950
+ for(var i1 = 0; i1 < width; i1++, offset += 4){
53951
+ dataRGBA[offset] = scanLineBuffer[i1];
53952
+ dataRGBA[offset + 1] = scanLineBuffer[i1 + width];
53953
+ dataRGBA[offset + 2] = scanLineBuffer[i1 + width * 2];
53954
+ dataRGBA[offset + 3] = scanLineBuffer[i1 + width * 3];
53955
+ }
53956
+ numScanLines--;
53957
+ }
53958
+ return dataRGBA;
53959
+ };
53960
+ return HDRDecoder;
53961
+ }();
53962
+ // Float32 to Float16 lookup tables (http://www.fox-toolkit.org/ftp/fasthalffloatconversion.pdf)
53963
+ HDRDecoder._float2HalfTables = HDRDecoder._generateFloat2HalfTables();
53964
+ HDRDecoder._floatView = new Float32Array(1);
53965
+ HDRDecoder._uint32View = new Uint32Array(HDRDecoder._floatView.buffer);
53966
+ HDRDecoder._one = 0x3c00 // Half float for 1.0
53967
+ ;
53968
+ // prettier-ignore
53969
+ HDRDecoder._faces = [
53970
+ /* +X */ [
53971
+ 1,
53972
+ -1,
53973
+ -1,
53974
+ 1,
53975
+ -1,
53976
+ 1,
53977
+ 1,
53978
+ 1,
53979
+ -1,
53980
+ 1,
53981
+ 1,
53982
+ 1
53983
+ ],
53984
+ /* -X */ [
53985
+ -1,
53986
+ -1,
53987
+ 1,
53988
+ -1,
53989
+ -1,
53990
+ -1,
53991
+ -1,
53992
+ 1,
53993
+ 1,
53994
+ -1,
53995
+ 1,
53996
+ -1
53997
+ ],
53998
+ /* +Y */ [
53999
+ -1,
54000
+ -1,
54001
+ 1,
54002
+ 1,
54003
+ -1,
54004
+ 1,
54005
+ -1,
54006
+ -1,
54007
+ -1,
54008
+ 1,
54009
+ -1,
54010
+ -1
54011
+ ],
54012
+ /* -Y */ [
54013
+ -1,
54014
+ 1,
54015
+ -1,
54016
+ 1,
54017
+ 1,
54018
+ -1,
54019
+ -1,
54020
+ 1,
54021
+ 1,
54022
+ 1,
54023
+ 1,
54024
+ 1
54025
+ ],
54026
+ /* +Z */ [
54027
+ -1,
54028
+ -1,
54029
+ -1,
54030
+ 1,
54031
+ -1,
54032
+ -1,
54033
+ -1,
54034
+ 1,
54035
+ -1,
54036
+ 1,
54037
+ 1,
54038
+ -1
54039
+ ],
54040
+ /* -Z */ [
54041
+ 1,
54042
+ -1,
54043
+ 1,
54044
+ -1,
54045
+ -1,
54046
+ 1,
54047
+ 1,
54048
+ 1,
54049
+ 1,
54050
+ -1,
54051
+ 1,
54052
+ 1
54053
+ ]
54054
+ ];
54055
+ var TextureCubeLoader = /*#__PURE__*/ function(Loader) {
54056
+ _inherits(TextureCubeLoader, Loader);
54057
+ function TextureCubeLoader() {
54058
+ return Loader.apply(this, arguments) || this;
54059
+ }
54060
+ var _proto = TextureCubeLoader.prototype;
54061
+ _proto.load = function load(item, resourceManager) {
54062
+ return new AssetPromise(function(resolve, reject) {
54063
+ var engine = resourceManager.engine;
54064
+ var url = item.url;
54065
+ var requestConfig = _extends({}, item, {
54066
+ type: "arraybuffer"
54434
54067
  });
54068
+ resourceManager // @ts-ignore
54069
+ ._request(url, requestConfig).then(function(buffer) {
54070
+ if (!SystemInfo.supportsTextureFormat(engine, TextureFormat.R16G16B16A16)) {
54071
+ reject(new Error("TextureCubeLoader: HDR texture requires half float support."));
54072
+ return;
54073
+ }
54074
+ var _item_params;
54075
+ var _ref = (_item_params = item.params) != null ? _item_params : {}, _ref_mipmap = _ref.mipmap, mipmap = _ref_mipmap === void 0 ? true : _ref_mipmap, anisoLevel = _ref.anisoLevel, wrapModeU = _ref.wrapModeU, wrapModeV = _ref.wrapModeV, filterMode = _ref.filterMode;
54076
+ var bufferArray = new Uint8Array(buffer);
54077
+ var header = HDRDecoder.parseHeader(bufferArray);
54078
+ var texture = new TextureCube(engine, header.height >> 1, TextureFormat.R16G16B16A16, mipmap, false);
54079
+ HDRDecoder.decodeFaces(bufferArray, header, function(faceIndex, data) {
54080
+ texture.setPixelBuffer(TextureCubeFace.PositiveX + faceIndex, data, 0);
54081
+ });
54082
+ texture.generateMipmaps();
54083
+ texture.anisoLevel = anisoLevel != null ? anisoLevel : texture.anisoLevel;
54084
+ texture.filterMode = filterMode != null ? filterMode : texture.filterMode;
54085
+ texture.wrapModeU = wrapModeU != null ? wrapModeU : texture.wrapModeU;
54086
+ texture.wrapModeV = wrapModeV != null ? wrapModeV : texture.wrapModeV;
54087
+ resourceManager.addContentRestorer(new HDRContentRestorer(texture, url, requestConfig));
54088
+ resolve(texture);
54089
+ }).catch(reject);
54090
+ });
54091
+ };
54092
+ return TextureCubeLoader;
54093
+ }(Loader);
54094
+ TextureCubeLoader = __decorate([
54095
+ resourceLoader(AssetType.TextureCube, [
54096
+ "texCube",
54097
+ "hdr"
54098
+ ])
54099
+ ], TextureCubeLoader);
54100
+ var HDRContentRestorer = /*#__PURE__*/ function(ContentRestorer) {
54101
+ _inherits(HDRContentRestorer, ContentRestorer);
54102
+ function HDRContentRestorer(resource, url, requestConfig) {
54103
+ var _this;
54104
+ _this = ContentRestorer.call(this, resource) || this, _this.url = url, _this.requestConfig = requestConfig;
54105
+ return _this;
54106
+ }
54107
+ var _proto = HDRContentRestorer.prototype;
54108
+ _proto.restoreContent = function restoreContent() {
54109
+ var _this = this;
54110
+ return new AssetPromise(function(resolve, reject) {
54111
+ var resource = _this.resource;
54112
+ resource.engine.resourceManager // @ts-ignore
54113
+ ._request(_this.url, _this.requestConfig).then(function(buffer) {
54114
+ var bufferArray = new Uint8Array(buffer);
54115
+ HDRDecoder.decodeFaces(bufferArray, HDRDecoder.parseHeader(bufferArray), function(faceIndex, data) {
54116
+ resource.setPixelBuffer(TextureCubeFace.PositiveX + faceIndex, data, 0);
54117
+ });
54118
+ resource.generateMipmaps();
54119
+ resolve(resource);
54120
+ }).catch(reject);
54435
54121
  });
54436
54122
  };
54437
- return TextureContentRestorer;
54123
+ return HDRContentRestorer;
54438
54124
  }(ContentRestorer);
54439
54125
  var AudioLoader = /*#__PURE__*/ function(Loader) {
54440
54126
  _inherits(AudioLoader, Loader);
@@ -55266,7 +54952,7 @@
55266
54952
  ], EXT_texture_webp);
55267
54953
 
55268
54954
  //@ts-ignore
55269
- var version = "0.0.0-experimental-2.0-game.2";
54955
+ var version = "0.0.0-experimental-2.0-game.3";
55270
54956
  console.log("Galacean Engine Version: " + version);
55271
54957
  for(var key in CoreObjects){
55272
54958
  Loader.registerClass(key, CoreObjects[key]);
@@ -55431,7 +55117,6 @@
55431
55117
  exports.MeshShape = MeshShape;
55432
55118
  exports.MeshTopology = MeshTopology;
55433
55119
  exports.ModelMesh = ModelMesh;
55434
- exports.NoiseModule = NoiseModule;
55435
55120
  exports.OverflowMode = OverflowMode;
55436
55121
  exports.PBRMaterial = PBRMaterial;
55437
55122
  exports.ParserContext = ParserContext;