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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/browser.js CHANGED
@@ -845,20 +845,16 @@
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
- // 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;
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;
855
853
  var e = matrix.elements;
856
854
  // prettier-ignore
857
855
  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];
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);
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]);
862
858
  };
863
859
  /**
864
860
  * Calculate a bounding box that is as large as the total combined area of the two specified boxes.
@@ -873,8 +869,6 @@
873
869
  };
874
870
  return BoundingBox;
875
871
  }();
876
- BoundingBox._tempVec30 = new Vector3();
877
- BoundingBox._tempVec31 = new Vector3();
878
872
  /**
879
873
  * Contains static methods to help in determining intersections, containment, etc.
880
874
  */ var CollisionUtil = /*#__PURE__*/ function() {
@@ -6487,6 +6481,12 @@
6487
6481
  case TextureFormat.ETC2_RGB:
6488
6482
  case TextureFormat.ETC2_RGBA8:
6489
6483
  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);
7023
+ var texture = new Texture2D(engine, 512, 512, format, false, false);
7024
7024
  texture.filterMode = TextureFilterMode.Bilinear;
7025
7025
  texture.isGCIgnored = true;
7026
7026
  _this.texture = texture;
@@ -10437,27 +10437,13 @@
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_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
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
10456
10442
  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
10457
10443
  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
10458
10444
  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
10459
10445
  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
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
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
10461
10447
  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
10462
10448
  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
10463
10449
  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
@@ -10491,7 +10477,8 @@
10491
10477
  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
10492
10478
  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
10493
10479
  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
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
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
10495
10482
  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
10496
10483
  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
10497
10484
  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
@@ -10506,6 +10493,7 @@
10506
10493
  texture_sheet_animation_module: texture_sheet_animation_module,
10507
10494
  force_over_lifetime_module: force_over_lifetime_module,
10508
10495
  limit_velocity_over_lifetime_module: limit_velocity_over_lifetime_module,
10496
+ noise_module: noise_module,
10509
10497
  particle_feedback_simulation: particle_feedback_simulation,
10510
10498
  sphere_billboard: sphere_billboard,
10511
10499
  stretched_billboard: stretched_billboard,
@@ -10545,21 +10533,7 @@
10545
10533
  begin_viewdir_frag: begin_viewdir_frag,
10546
10534
  mobile_blinnphong_frag: mobile_blinnphong_frag,
10547
10535
  noise_common: noise_common,
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
10536
+ noise_simplex_3D_grad: noise_simplex_3D_grad
10563
10537
  }, ShadowLib, PBRShaderLib, {
10564
10538
  normal_get: normal_get
10565
10539
  }, ParticleShaderLib);
@@ -29665,8 +29639,7 @@
29665
29639
  /** Plain text. */ AssetType["Text"] = "Text";
29666
29640
  /** JSON. */ AssetType["JSON"] = "JSON";
29667
29641
  /** ArrayBuffer. */ AssetType["Buffer"] = "Buffer";
29668
- /** 2D Texture. */ AssetType["Texture2D"] = "Texture2D";
29669
- /** Cube Texture. */ AssetType["TextureCube"] = "TextureCube";
29642
+ /** Texture. */ AssetType["Texture"] = "Texture";
29670
29643
  /** Material. */ AssetType["Material"] = "Material";
29671
29644
  /** Shader. */ AssetType["Shader"] = "Shader";
29672
29645
  /** Mesh. */ AssetType["Mesh"] = "Mesh";
@@ -31865,14 +31838,14 @@
31865
31838
  var depthOnlyFs = "void main() {\n}"; // eslint-disable-line
31866
31839
  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
31867
31840
  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
31868
- 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
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
31869
31842
  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
31870
31843
  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
31871
31844
  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
31872
31845
  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
31873
31846
  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
31874
31847
  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
31875
- 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
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
31876
31849
  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
31877
31850
  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
31878
31851
  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
@@ -34690,7 +34663,7 @@
34690
34663
  for(var _len = arguments.length, signalArgs = new Array(_len), _key = 0; _key < _len; _key++){
34691
34664
  signalArgs[_key] = arguments[_key];
34692
34665
  }
34693
- return (_target = target)[methodName].apply(_target, [].concat(args, signalArgs));
34666
+ return (_target = target)[methodName].apply(_target, [].concat(signalArgs, args));
34694
34667
  } : function() {
34695
34668
  for(var _len = arguments.length, signalArgs = new Array(_len), _key = 0; _key < _len; _key++){
34696
34669
  signalArgs[_key] = arguments[_key];
@@ -39317,6 +39290,7 @@
39317
39290
  ParticleRandomSubSeeds[ParticleRandomSubSeeds["GravityModifier"] = 2759560269] = "GravityModifier";
39318
39291
  ParticleRandomSubSeeds[ParticleRandomSubSeeds["ForceOverLifetime"] = 3875246972] = "ForceOverLifetime";
39319
39292
  ParticleRandomSubSeeds[ParticleRandomSubSeeds["LimitVelocityOverLifetime"] = 3047300990] = "LimitVelocityOverLifetime";
39293
+ ParticleRandomSubSeeds[ParticleRandomSubSeeds["Noise"] = 4105357473] = "Noise";
39320
39294
  return ParticleRandomSubSeeds;
39321
39295
  }({});
39322
39296
  /**
@@ -40106,30 +40080,48 @@
40106
40080
  }
40107
40081
  this._emitBySubBurst(middleTime, playTime, duration);
40108
40082
  } else {
40109
- this._emitBySubBurst(lastPlayTime, playTime, duration);
40083
+ if (lastPlayTime < duration) {
40084
+ this._emitBySubBurst(lastPlayTime, Math.min(playTime, duration), duration);
40085
+ }
40110
40086
  }
40111
40087
  };
40112
40088
  _proto._emitBySubBurst = function _emitBySubBurst(lastPlayTime, playTime, duration) {
40113
- var generator = this._generator;
40114
- var rand = this._burstRand;
40115
- var bursts = this.bursts;
40116
- // Calculate the relative time of the burst
40089
+ var _this = this, generator = _this._generator, rand = _this._burstRand, bursts = _this.bursts;
40117
40090
  var baseTime = Math.floor(lastPlayTime / duration) * duration;
40118
40091
  var startTime = lastPlayTime % duration;
40119
40092
  var endTime = startTime + (playTime - lastPlayTime);
40093
+ var pendingIndex = -1;
40120
40094
  var index = this._currentBurstIndex;
40121
40095
  for(var n = bursts.length; index < n; index++){
40122
40096
  var burst = bursts[index];
40123
40097
  var burstTime = burst.time;
40124
- if (burstTime > endTime) {
40125
- break;
40126
- }
40127
- if (burstTime >= startTime) {
40128
- var count = burst.count.evaluate(undefined, rand.random());
40129
- generator._emit(baseTime + burstTime, count);
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
+ }
40130
40122
  }
40131
40123
  }
40132
- this._currentBurstIndex = index;
40124
+ this._currentBurstIndex = pendingIndex >= 0 ? pendingIndex : index;
40133
40125
  };
40134
40126
  _create_class$2(EmissionModule, [
40135
40127
  {
@@ -40692,7 +40684,7 @@
40692
40684
  return;
40693
40685
  }
40694
40686
  this._enabled = value;
40695
- this._generator._setTransformFeedback(value);
40687
+ this._generator._setTransformFeedback();
40696
40688
  this._generator._renderer._onGeneratorParamsChanged();
40697
40689
  }
40698
40690
  }
@@ -40777,9 +40769,9 @@
40777
40769
  /**
40778
40770
  * Control how Particle Generator apply transform scale.
40779
40771
  */ var ParticleScaleMode = /*#__PURE__*/ function(ParticleScaleMode) {
40780
- /** Scale the Particle Generator using the entire transform hierarchy. */ ParticleScaleMode[ParticleScaleMode["Hierarchy"] = 0] = "Hierarchy";
40781
- /** Scale the Particle Generator using only its own transform scale. (Ignores parent scale). */ ParticleScaleMode[ParticleScaleMode["Local"] = 1] = "Local";
40782
- /** 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";
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";
40783
40775
  return ParticleScaleMode;
40784
40776
  }({});
40785
40777
  var MainModule = /*#__PURE__*/ function() {
@@ -40830,8 +40822,8 @@
40830
40822
  */ _proto._getPositionScale = function _getPositionScale() {
40831
40823
  var transform = this._generator._renderer.entity.transform;
40832
40824
  switch(this.scalingMode){
40833
- case ParticleScaleMode.Hierarchy:
40834
40825
  case ParticleScaleMode.World:
40826
+ case ParticleScaleMode.Shape:
40835
40827
  return transform.lossyWorldScale;
40836
40828
  case ParticleScaleMode.Local:
40837
40829
  return transform.scale;
@@ -40855,7 +40847,7 @@
40855
40847
  throw new Error("ParticleRenderer: SimulationSpace value is invalid.");
40856
40848
  }
40857
40849
  switch(this.scalingMode){
40858
- case ParticleScaleMode.Hierarchy:
40850
+ case ParticleScaleMode.World:
40859
40851
  var scale = transform.lossyWorldScale;
40860
40852
  shaderData.setVector3(MainModule._positionScale, scale);
40861
40853
  shaderData.setVector3(MainModule._sizeScale, scale);
@@ -40865,7 +40857,7 @@
40865
40857
  shaderData.setVector3(MainModule._positionScale, scale);
40866
40858
  shaderData.setVector3(MainModule._sizeScale, scale);
40867
40859
  break;
40868
- case ParticleScaleMode.World:
40860
+ case ParticleScaleMode.Shape:
40869
40861
  shaderData.setVector3(MainModule._positionScale, transform.lossyWorldScale);
40870
40862
  shaderData.setVector3(MainModule._sizeScale, MainModule._vector3One);
40871
40863
  break;
@@ -41631,6 +41623,297 @@
41631
41623
  __decorate$1([
41632
41624
  ignoreClone
41633
41625
  ], 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);
41634
41917
  /**
41635
41918
  * Velocity over lifetime module.
41636
41919
  */ var VelocityOverLifetimeModule = /*#__PURE__*/ function(ParticleGeneratorModule) {
@@ -41836,6 +42119,7 @@
41836
42119
  this.forceOverLifetime = new ForceOverLifetimeModule(this);
41837
42120
  this.sizeOverLifetime = new SizeOverLifetimeModule(this);
41838
42121
  this.limitVelocityOverLifetime = new LimitVelocityOverLifetimeModule(this);
42122
+ this.noise = new NoiseModule(this);
41839
42123
  this.emission.enabled = true;
41840
42124
  }
41841
42125
  var _proto = ParticleGenerator.prototype;
@@ -42143,6 +42427,7 @@
42143
42427
  this.sizeOverLifetime._updateShaderData(shaderData);
42144
42428
  this.rotationOverLifetime._updateShaderData(shaderData);
42145
42429
  this.colorOverLifetime._updateShaderData(shaderData);
42430
+ this.noise._updateShaderData(shaderData);
42146
42431
  };
42147
42432
  /**
42148
42433
  * @internal
@@ -42156,16 +42441,19 @@
42156
42441
  this.limitVelocityOverLifetime._resetRandomSeed(seed);
42157
42442
  this.rotationOverLifetime._resetRandomSeed(seed);
42158
42443
  this.colorOverLifetime._resetRandomSeed(seed);
42444
+ this.noise._resetRandomSeed(seed);
42159
42445
  };
42160
42446
  /**
42161
42447
  * @internal
42162
- */ _proto._setTransformFeedback = function _setTransformFeedback(enabled) {
42163
- this._useTransformFeedback = enabled;
42448
+ */ _proto._setTransformFeedback = function _setTransformFeedback() {
42449
+ var needed = this.limitVelocityOverLifetime.enabled || this.noise.enabled;
42450
+ if (needed === this._useTransformFeedback) return;
42451
+ this._useTransformFeedback = needed;
42164
42452
  // Switching TF mode invalidates all active particle state: feedback buffers and instance
42165
42453
  // buffer layout are incompatible between the two paths. Clear rather than show a one-frame
42166
42454
  // jump; new particles will fill in naturally from the next emit cycle.
42167
42455
  this._clearActiveParticles();
42168
- if (enabled) {
42456
+ if (needed) {
42169
42457
  if (!this._feedbackSimulator) {
42170
42458
  this._feedbackSimulator = new ParticleTransformFeedbackSimulator(this._renderer.engine);
42171
42459
  }
@@ -42215,9 +42503,7 @@
42215
42503
  /**
42216
42504
  * @internal
42217
42505
  */ _proto._cloneTo = function _cloneTo(target) {
42218
- if (target.limitVelocityOverLifetime.enabled) {
42219
- target._setTransformFeedback(true);
42220
- }
42506
+ target._setTransformFeedback();
42221
42507
  };
42222
42508
  /**
42223
42509
  * @internal
@@ -42379,10 +42665,6 @@
42379
42665
  // Start rotation
42380
42666
  var startRotationRand = main._startRotationRand, flipRotation = main.flipRotation;
42381
42667
  var isFlip = flipRotation > startRotationRand.random();
42382
- // @todo:None-Mesh mode should inverse the rotation, maybe should unify it
42383
- if (this._renderer.renderMode !== ParticleRenderMode.Mesh) {
42384
- isFlip = !isFlip;
42385
- }
42386
42668
  var rotationZ = main.startRotationZ.evaluate(undefined, startRotationRand.random());
42387
42669
  if (main.startRotation3D) {
42388
42670
  var rotationX = main.startRotationX.evaluate(undefined, startRotationRand.random());
@@ -42408,7 +42690,9 @@
42408
42690
  if (colorOverLifetime.enabled && colorOverLifetime.color.mode === ParticleGradientMode.TwoGradients) {
42409
42691
  instanceVertices[offset + 20] = colorOverLifetime._colorGradientRand.random();
42410
42692
  }
42411
- // instanceVertices[offset + 21] = rand.random();
42693
+ if (this.noise.enabled) {
42694
+ instanceVertices[offset + 21] = this.noise._noiseRand.random();
42695
+ }
42412
42696
  var rotationOverLifetime = this.rotationOverLifetime;
42413
42697
  if (rotationOverLifetime.enabled && rotationOverLifetime.rotationZ.mode === ParticleCurveMode.TwoConstants) {
42414
42698
  instanceVertices[offset + 22] = rotationOverLifetime._rotationRand.random();
@@ -42601,7 +42885,7 @@
42601
42885
  // StartSpeed's impact
42602
42886
  var shape = this.emission.shape;
42603
42887
  if (shape == null ? void 0 : shape.enabled) {
42604
- shape._getPositionRange(min, max);
42888
+ shape._getPositionRange(bounds);
42605
42889
  shape._getDirectionRange(directionMin, directionMax);
42606
42890
  } else {
42607
42891
  min.set(0, 0, 0);
@@ -42696,6 +42980,21 @@
42696
42980
  out.transform(rotateMat);
42697
42981
  min.add(worldOffsetMin);
42698
42982
  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
+ }
42699
42998
  min.add(worldPosition);
42700
42999
  max.add(worldPosition);
42701
43000
  };
@@ -42793,6 +43092,9 @@
42793
43092
  __decorate$1([
42794
43093
  deepClone
42795
43094
  ], ParticleGenerator.prototype, "textureSheetAnimation", void 0);
43095
+ __decorate$1([
43096
+ deepClone
43097
+ ], ParticleGenerator.prototype, "noise", void 0);
42796
43098
  __decorate$1([
42797
43099
  ignoreClone
42798
43100
  ], ParticleGenerator.prototype, "_playTime", void 0);
@@ -42955,10 +43257,39 @@
42955
43257
  }(EffectMaterial);
42956
43258
  /**
42957
43259
  * A burst is a particle emission event, where a number of particles are all emitted at the same time
42958
- */ var Burst = function Burst(time, count) {
42959
- this.time = time;
42960
- this.count = count;
42961
- };
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
+ }();
42962
43293
  __decorate$1([
42963
43294
  deepClone
42964
43295
  ], Burst.prototype, "count", void 0);
@@ -42966,9 +43297,28 @@
42966
43297
  * Base class for all particle shapes.
42967
43298
  */ var BaseShape = /*#__PURE__*/ function() {
42968
43299
  function BaseShape() {
43300
+ var _this = this;
42969
43301
  this._updateManager = new UpdateFlagManager();
42970
43302
  this._enabled = true;
42971
43303
  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;
42972
43322
  }
42973
43323
  var _proto = BaseShape.prototype;
42974
43324
  /**
@@ -42981,6 +43331,53 @@
42981
43331
  */ _proto._unRegisterOnValueChanged = function _unRegisterOnValueChanged(listener) {
42982
43332
  this._updateManager.removeListener(listener);
42983
43333
  };
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
+ };
42984
43381
  _create_class$2(BaseShape, [
42985
43382
  {
42986
43383
  key: "enabled",
@@ -43009,13 +43406,78 @@
43009
43406
  this._updateManager.dispatch();
43010
43407
  }
43011
43408
  }
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
+ }
43012
43448
  }
43013
43449
  ]);
43014
43450
  return BaseShape;
43015
43451
  }();
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();
43016
43457
  __decorate$1([
43017
43458
  ignoreClone
43018
43459
  ], 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);
43019
43481
  /**
43020
43482
  * @internal
43021
43483
  */ var ShapeUtils = /*#__PURE__*/ function() {
@@ -43078,11 +43540,11 @@
43078
43540
  }({});
43079
43541
  /**
43080
43542
  * Particle shape that emits particles from a box.
43081
- */ var BoxShape = /*#__PURE__*/ function(BaseShape) {
43082
- _inherits$2(BoxShape, BaseShape);
43543
+ */ var BoxShape = /*#__PURE__*/ function(BaseShape1) {
43544
+ _inherits$2(BoxShape, BaseShape1);
43083
43545
  function BoxShape() {
43084
43546
  var _this;
43085
- _this = BaseShape.call(this) || this, _this.shapeType = ParticleShapeType.Box, _this._size = new Vector3(1, 1, 1);
43547
+ _this = BaseShape1.call(this) || this, _this.shapeType = ParticleShapeType.Box, _this._size = new Vector3(1, 1, 1);
43086
43548
  // @ts-ignore
43087
43549
  _this._size._onValueChanged = _this._updateManager.dispatch.bind(_this._updateManager);
43088
43550
  return _this;
@@ -43090,17 +43552,17 @@
43090
43552
  var _proto = BoxShape.prototype;
43091
43553
  /**
43092
43554
  * @internal
43093
- */ _proto._generatePositionAndDirection = function _generatePositionAndDirection(rand, emitTime, position, direction) {
43555
+ */ _proto._generateLocalPositionAndDirection = function _generateLocalPositionAndDirection(rand, emitTime, position, direction) {
43094
43556
  ShapeUtils._randomPointInsideHalfUnitBox(position, rand);
43095
43557
  position.multiply(this.size);
43096
- var defaultDirection = BoxShape._tempVector30;
43558
+ var defaultDirection = BaseShape._tempVector30;
43097
43559
  defaultDirection.set(0.0, 0.0, -1.0);
43098
43560
  ShapeUtils._randomPointUnitSphere(direction, rand);
43099
43561
  Vector3.lerp(defaultDirection, direction, this.randomDirectionAmount, direction);
43100
43562
  };
43101
43563
  /**
43102
43564
  * @internal
43103
- */ _proto._getDirectionRange = function _getDirectionRange(outMin, outMax) {
43565
+ */ _proto._getLocalDirectionRange = function _getLocalDirectionRange(outMin, outMax) {
43104
43566
  var radian = Math.PI * this.randomDirectionAmount;
43105
43567
  if (this.randomDirectionAmount < 0.5) {
43106
43568
  var dirSin = Math.sin(radian);
@@ -43114,7 +43576,7 @@
43114
43576
  };
43115
43577
  /**
43116
43578
  * @internal
43117
- */ _proto._getPositionRange = function _getPositionRange(outMin, outMax) {
43579
+ */ _proto._getLocalPositionRange = function _getLocalPositionRange(outMin, outMax) {
43118
43580
  var _this__size = this._size, x = _this__size.x, y = _this__size.y, z = _this__size.z;
43119
43581
  outMin.set(-x * 0.5, -y * 0.5, -z * 0.5);
43120
43582
  outMax.set(x * 0.5, y * 0.5, z * 0.5);
@@ -43136,7 +43598,6 @@
43136
43598
  ]);
43137
43599
  return BoxShape;
43138
43600
  }(BaseShape);
43139
- BoxShape._tempVector30 = new Vector3();
43140
43601
  __decorate$1([
43141
43602
  deepClone
43142
43603
  ], BoxShape.prototype, "_size", void 0);
@@ -43149,18 +43610,18 @@
43149
43610
  }({});
43150
43611
  /**
43151
43612
  * Particle shape that emits particles from a circle.
43152
- */ var CircleShape = /*#__PURE__*/ function(BaseShape) {
43153
- _inherits$2(CircleShape, BaseShape);
43613
+ */ var CircleShape = /*#__PURE__*/ function(BaseShape1) {
43614
+ _inherits$2(CircleShape, BaseShape1);
43154
43615
  function CircleShape() {
43155
43616
  var _this;
43156
- _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;
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;
43157
43618
  return _this;
43158
43619
  }
43159
43620
  var _proto = CircleShape.prototype;
43160
43621
  /**
43161
43622
  * @internal
43162
- */ _proto._generatePositionAndDirection = function _generatePositionAndDirection(rand, emitTime, position, direction) {
43163
- var positionPoint = CircleShape._tempPositionPoint;
43623
+ */ _proto._generateLocalPositionAndDirection = function _generateLocalPositionAndDirection(rand, emitTime, position, direction) {
43624
+ var positionPoint = BaseShape._tempVector20;
43164
43625
  switch(this.arcMode){
43165
43626
  case ParticleShapeArcMode.Loop:
43166
43627
  var normalizedEmitTime = emitTime * this.arcSpeed * (360 / this.arc) % 1;
@@ -43179,7 +43640,7 @@
43179
43640
  };
43180
43641
  /**
43181
43642
  * @internal
43182
- */ _proto._getDirectionRange = function _getDirectionRange(outMin, outMax) {
43643
+ */ _proto._getLocalDirectionRange = function _getLocalDirectionRange(outMin, outMax) {
43183
43644
  var randomDirZ = this.randomDirectionAmount > 0.5 ? 1 : Math.sin(this.randomDirectionAmount * Math.PI);
43184
43645
  var randomDegreeOnXY = 0.5 * (360 - this._arc) * this.randomDirectionAmount;
43185
43646
  var randomDirY = randomDegreeOnXY > 90 ? -1 : -Math.sin(randomDegreeOnXY);
@@ -43187,7 +43648,7 @@
43187
43648
  };
43188
43649
  /**
43189
43650
  * @internal
43190
- */ _proto._getPositionRange = function _getPositionRange(outMin, outMax) {
43651
+ */ _proto._getLocalPositionRange = function _getLocalPositionRange(outMin, outMax) {
43191
43652
  this._getUnitArcRange(this._arc, outMin, outMax, 0, 0);
43192
43653
  outMin.scale(this._radius);
43193
43654
  outMax.scale(this._radius);
@@ -43270,21 +43731,20 @@
43270
43731
  ]);
43271
43732
  return CircleShape;
43272
43733
  }(BaseShape);
43273
- CircleShape._tempPositionPoint = new Vector2();
43274
43734
  /**
43275
43735
  * Cone shape.
43276
- */ var ConeShape = /*#__PURE__*/ function(BaseShape) {
43277
- _inherits$2(ConeShape, BaseShape);
43736
+ */ var ConeShape = /*#__PURE__*/ function(BaseShape1) {
43737
+ _inherits$2(ConeShape, BaseShape1);
43278
43738
  function ConeShape() {
43279
43739
  var _this;
43280
- _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;
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;
43281
43741
  return _this;
43282
43742
  }
43283
43743
  var _proto = ConeShape.prototype;
43284
43744
  /**
43285
43745
  * @internal
43286
- */ _proto._generatePositionAndDirection = function _generatePositionAndDirection(rand, emitTime, position, direction) {
43287
- var unitPosition = ConeShape._tempVector20;
43746
+ */ _proto._generateLocalPositionAndDirection = function _generateLocalPositionAndDirection(rand, emitTime, position, direction) {
43747
+ var unitPosition = BaseShape._tempVector20;
43288
43748
  var radian = MathUtil.degreeToRadian(this.angle);
43289
43749
  var dirSinA = Math.sin(radian);
43290
43750
  var dirCosA = Math.cos(radian);
@@ -43292,7 +43752,7 @@
43292
43752
  case 0:
43293
43753
  ShapeUtils.randomPointInsideUnitCircle(unitPosition, rand);
43294
43754
  position.set(unitPosition.x * this.radius, unitPosition.y * this.radius, 0);
43295
- var unitDirection = ConeShape._tempVector21;
43755
+ var unitDirection = BaseShape._tempVector21;
43296
43756
  ShapeUtils.randomPointInsideUnitCircle(unitDirection, rand);
43297
43757
  Vector2.lerp(unitPosition, unitDirection, this.randomDirectionAmount, unitDirection);
43298
43758
  direction.set(unitDirection.x * dirSinA, unitDirection.y * dirSinA, -dirCosA);
@@ -43302,10 +43762,10 @@
43302
43762
  position.set(unitPosition.x * this.radius, unitPosition.y * this.radius, 0);
43303
43763
  direction.set(unitPosition.x * dirSinA, unitPosition.y * dirSinA, -dirCosA);
43304
43764
  direction.normalize();
43305
- var distance = ConeShape._tempVector30;
43765
+ var distance = BaseShape._tempVector30;
43306
43766
  Vector3.scale(direction, this.length * rand.random(), distance);
43307
43767
  position.add(distance);
43308
- var randomDirection = ConeShape._tempVector31;
43768
+ var randomDirection = BaseShape._tempVector31;
43309
43769
  ShapeUtils._randomPointUnitSphere(randomDirection, rand);
43310
43770
  Vector3.lerp(direction, randomDirection, this.randomDirectionAmount, direction);
43311
43771
  break;
@@ -43313,7 +43773,7 @@
43313
43773
  };
43314
43774
  /**
43315
43775
  * @internal
43316
- */ _proto._getDirectionRange = function _getDirectionRange(outMin, outMax) {
43776
+ */ _proto._getLocalDirectionRange = function _getLocalDirectionRange(outMin, outMax) {
43317
43777
  var radian = 0;
43318
43778
  switch(this.emitType){
43319
43779
  case 0:
@@ -43330,7 +43790,7 @@
43330
43790
  };
43331
43791
  /**
43332
43792
  * @internal
43333
- */ _proto._getPositionRange = function _getPositionRange(outMin, outMax) {
43793
+ */ _proto._getLocalPositionRange = function _getLocalPositionRange(outMin, outMax) {
43334
43794
  var radius = this.radius;
43335
43795
  switch(this.emitType){
43336
43796
  case 0:
@@ -43405,10 +43865,6 @@
43405
43865
  ]);
43406
43866
  return ConeShape;
43407
43867
  }(BaseShape);
43408
- ConeShape._tempVector20 = new Vector2();
43409
- ConeShape._tempVector21 = new Vector2();
43410
- ConeShape._tempVector30 = new Vector3();
43411
- ConeShape._tempVector31 = new Vector3();
43412
43868
  /**
43413
43869
  * Cone emitter type.
43414
43870
  */ var ConeEmitType = /*#__PURE__*/ function(ConeEmitType) {
@@ -43428,7 +43884,7 @@
43428
43884
  var _proto = HemisphereShape.prototype;
43429
43885
  /**
43430
43886
  * @internal
43431
- */ _proto._generatePositionAndDirection = function _generatePositionAndDirection(rand, emitTime, position, direction) {
43887
+ */ _proto._generateLocalPositionAndDirection = function _generateLocalPositionAndDirection(rand, emitTime, position, direction) {
43432
43888
  ShapeUtils._randomPointInsideUnitSphere(position, rand);
43433
43889
  position.scale(this.radius);
43434
43890
  var z = position.z;
@@ -43438,14 +43894,14 @@
43438
43894
  };
43439
43895
  /**
43440
43896
  * @internal
43441
- */ _proto._getDirectionRange = function _getDirectionRange(outMin, outMax) {
43897
+ */ _proto._getLocalDirectionRange = function _getLocalDirectionRange(outMin, outMax) {
43442
43898
  var randomDir = Math.sin(0.5 * this.randomDirectionAmount * Math.PI);
43443
43899
  outMin.set(-1, -1, -1);
43444
43900
  outMax.set(1, 1, randomDir);
43445
43901
  };
43446
43902
  /**
43447
43903
  * @internal
43448
- */ _proto._getPositionRange = function _getPositionRange(outMin, outMax) {
43904
+ */ _proto._getLocalPositionRange = function _getLocalPositionRange(outMin, outMax) {
43449
43905
  var radius = this._radius;
43450
43906
  outMin.set(-radius, -radius, -radius);
43451
43907
  outMax.set(radius, radius, 0);
@@ -43482,7 +43938,7 @@
43482
43938
  var _proto = MeshShape.prototype;
43483
43939
  /**
43484
43940
  * @internal
43485
- */ _proto._generatePositionAndDirection = function _generatePositionAndDirection(rand, emitTime, position, direction) {
43941
+ */ _proto._generateLocalPositionAndDirection = function _generateLocalPositionAndDirection(rand, emitTime, position, direction) {
43486
43942
  var _this = this, positions = _this._positionBuffer, positionInfo = _this._positionElementInfo, normals = _this._normalBuffer, normalInfo = _this._normalElementInfo;
43487
43943
  var randomIndex = Math.floor(rand.random() * this._mesh.vertexCount);
43488
43944
  // index = randomIndex * stride + offset
@@ -43495,14 +43951,14 @@
43495
43951
  };
43496
43952
  /**
43497
43953
  * @internal
43498
- */ _proto._getPositionRange = function _getPositionRange(outMin, outMax) {
43954
+ */ _proto._getLocalPositionRange = function _getLocalPositionRange(outMin, outMax) {
43499
43955
  var bounds = this._mesh.bounds;
43500
43956
  bounds.min.copyTo(outMin);
43501
43957
  bounds.max.copyTo(outMax);
43502
43958
  };
43503
43959
  /**
43504
43960
  * @internal
43505
- */ _proto._getDirectionRange = function _getDirectionRange(outMin, outMax) {
43961
+ */ _proto._getLocalDirectionRange = function _getLocalDirectionRange(outMin, outMax) {
43506
43962
  // @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.
43507
43963
  var bounds = this._mesh.bounds;
43508
43964
  bounds.min.copyTo(outMin);
@@ -43616,7 +44072,7 @@
43616
44072
  var _proto = SphereShape.prototype;
43617
44073
  /**
43618
44074
  * @internal
43619
- */ _proto._generatePositionAndDirection = function _generatePositionAndDirection(rand, emitTime, position, direction) {
44075
+ */ _proto._generateLocalPositionAndDirection = function _generateLocalPositionAndDirection(rand, emitTime, position, direction) {
43620
44076
  ShapeUtils._randomPointInsideUnitSphere(position, rand);
43621
44077
  position.scale(this.radius);
43622
44078
  ShapeUtils._randomPointUnitSphere(direction, rand);
@@ -43624,13 +44080,13 @@
43624
44080
  };
43625
44081
  /**
43626
44082
  * @internal
43627
- */ _proto._getDirectionRange = function _getDirectionRange(outMin, outMax) {
44083
+ */ _proto._getLocalDirectionRange = function _getLocalDirectionRange(outMin, outMax) {
43628
44084
  outMin.set(-1, -1, -1);
43629
44085
  outMax.set(1, 1, 1);
43630
44086
  };
43631
44087
  /**
43632
44088
  * @internal
43633
- */ _proto._getPositionRange = function _getPositionRange(outMin, outMax) {
44089
+ */ _proto._getLocalPositionRange = function _getLocalPositionRange(outMin, outMax) {
43634
44090
  var radius = this._radius;
43635
44091
  outMin.set(-radius, -radius, -radius);
43636
44092
  outMax.set(radius, radius, radius);
@@ -44382,7 +44838,7 @@
44382
44838
  * Suspend the audio context.
44383
44839
  * @returns A promise that resolves when the audio context is suspended
44384
44840
  */ AudioManager.suspend = function suspend() {
44385
- return AudioManager._context.suspend();
44841
+ return AudioManager.getContext().suspend();
44386
44842
  };
44387
44843
  /**
44388
44844
  * Resume the audio context.
@@ -44391,7 +44847,7 @@
44391
44847
  */ AudioManager.resume = function resume() {
44392
44848
  var _AudioManager;
44393
44849
  var __resumePromise;
44394
- return (__resumePromise = (_AudioManager = AudioManager)._resumePromise) != null ? __resumePromise : _AudioManager._resumePromise = AudioManager._context.resume().then(function() {
44850
+ return (__resumePromise = (_AudioManager = AudioManager)._resumePromise) != null ? __resumePromise : _AudioManager._resumePromise = AudioManager.getContext().resume().then(function() {
44395
44851
  AudioManager._needsUserGestureResume = false;
44396
44852
  }).finally(function() {
44397
44853
  AudioManager._resumePromise = null;
@@ -44991,6 +45447,7 @@
44991
45447
  MeshShape: MeshShape,
44992
45448
  MeshTopology: MeshTopology,
44993
45449
  ModelMesh: ModelMesh,
45450
+ NoiseModule: NoiseModule,
44994
45451
  OverflowMode: OverflowMode,
44995
45452
  PBRMaterial: PBRMaterial,
44996
45453
  ParticleCompositeCurve: ParticleCompositeCurve,
@@ -46184,7 +46641,7 @@
46184
46641
  };
46185
46642
  case TextureFormat.ETC2_RGBA5:
46186
46643
  return {
46187
- internalFormat: GLCompressedTextureInternalFormat.RGB8_PUNCHTHROUGH_ALPHA1_ETC2,
46644
+ internalFormat: isSRGBColorSpace ? GLCompressedTextureInternalFormat.SRGB8_PUNCHTHROUGH_ALPHA1_ETC2 : GLCompressedTextureInternalFormat.RGB8_PUNCHTHROUGH_ALPHA1_ETC2,
46188
46645
  isCompressed: true
46189
46646
  };
46190
46647
  case TextureFormat.ETC2_RGBA8:
@@ -46219,27 +46676,27 @@
46219
46676
  };
46220
46677
  case TextureFormat.ASTC_5x5:
46221
46678
  return {
46222
- internalFormat: GLCompressedTextureInternalFormat.RGBA_ASTC_5X5_KHR,
46679
+ internalFormat: isSRGBColorSpace ? GLCompressedTextureInternalFormat.SRGB8_ALPHA8_ASTC_5X5_KHR : GLCompressedTextureInternalFormat.RGBA_ASTC_5X5_KHR,
46223
46680
  isCompressed: true
46224
46681
  };
46225
46682
  case TextureFormat.ASTC_6x6:
46226
46683
  return {
46227
- internalFormat: GLCompressedTextureInternalFormat.RGBA_ASTC_6X6_KHR,
46684
+ internalFormat: isSRGBColorSpace ? GLCompressedTextureInternalFormat.SRGB8_ALPHA8_ASTC_6X6_KHR : GLCompressedTextureInternalFormat.RGBA_ASTC_6X6_KHR,
46228
46685
  isCompressed: true
46229
46686
  };
46230
46687
  case TextureFormat.ASTC_8x8:
46231
46688
  return {
46232
- internalFormat: GLCompressedTextureInternalFormat.RGBA_ASTC_8X8_KHR,
46689
+ internalFormat: isSRGBColorSpace ? GLCompressedTextureInternalFormat.SRGB8_ALPHA8_ASTC_8X8_KHR : GLCompressedTextureInternalFormat.RGBA_ASTC_8X8_KHR,
46233
46690
  isCompressed: true
46234
46691
  };
46235
46692
  case TextureFormat.ASTC_10x10:
46236
46693
  return {
46237
- internalFormat: GLCompressedTextureInternalFormat.RGBA_ASTC_10X10_KHR,
46694
+ internalFormat: isSRGBColorSpace ? GLCompressedTextureInternalFormat.SRGB8_ALPHA8_ASTC_10X10_KHR : GLCompressedTextureInternalFormat.RGBA_ASTC_10X10_KHR,
46238
46695
  isCompressed: true
46239
46696
  };
46240
46697
  case TextureFormat.ASTC_12x12:
46241
46698
  return {
46242
- internalFormat: GLCompressedTextureInternalFormat.RGBA_ASTC_12X12_KHR,
46699
+ internalFormat: isSRGBColorSpace ? GLCompressedTextureInternalFormat.SRGB8_ALPHA8_ASTC_12X12_KHR : GLCompressedTextureInternalFormat.RGBA_ASTC_12X12_KHR,
46243
46700
  isCompressed: true
46244
46701
  };
46245
46702
  case TextureFormat.Depth:
@@ -48521,11 +48978,189 @@
48521
48978
  };
48522
48979
  return ReflectionParser;
48523
48980
  }();
48524
- exports.Texture2DDecoder = /*#__PURE__*/ function() {
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() {
48525
49160
  function Texture2DDecoder() {}
48526
49161
  Texture2DDecoder.decode = function decode(engine, bufferReader, restoredTexture) {
48527
49162
  return new AssetPromise(function(resolve, reject) {
48528
- var url = bufferReader.nextStr();
49163
+ bufferReader.nextStr();
48529
49164
  var mipmap = !!bufferReader.nextUint8();
48530
49165
  var filterMode = bufferReader.nextUint8();
48531
49166
  var anisoLevel = bufferReader.nextUint8();
@@ -48534,58 +49169,34 @@
48534
49169
  var format = bufferReader.nextUint8();
48535
49170
  var width = bufferReader.nextUint16();
48536
49171
  var height = bufferReader.nextUint16();
48537
- var isPixelBuffer = bufferReader.nextUint8();
48538
49172
  var isSRGBColorSpace = !!bufferReader.nextUint8();
48539
- var mipCount = bufferReader.nextUint8();
48540
- var imagesData = bufferReader.nextImagesData(mipCount);
48541
- var texture2D = restoredTexture || new Texture2D(engine, width, height, format, mipmap, isSRGBColorSpace);
48542
- texture2D.filterMode = filterMode;
48543
- texture2D.anisoLevel = anisoLevel;
48544
- texture2D.wrapModeU = wrapModeU;
48545
- texture2D.wrapModeV = wrapModeV;
48546
- if (isPixelBuffer) {
48547
- var pixelBuffer = imagesData[0];
48548
- texture2D.setPixelBuffer(pixelBuffer);
48549
- if (mipmap) {
48550
- texture2D.generateMipmaps();
48551
- for(var i = 1; i < mipCount; i++){
48552
- var pixelBuffer1 = imagesData[i];
48553
- texture2D.setPixelBuffer(pixelBuffer1, i);
48554
- }
48555
- }
48556
- // @ts-ignore
48557
- engine.resourceManager._objectPool[url] = texture2D;
48558
- resolve(texture2D);
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);
48559
49186
  } else {
48560
- var blob = new window.Blob([
48561
- imagesData[0]
49187
+ var blob = new Blob([
49188
+ imageData
48562
49189
  ]);
48563
49190
  var img = new Image();
48564
49191
  img.onload = function() {
48565
- texture2D.setImageSource(img);
48566
- var completedCount = 0;
48567
- var onComplete = function onComplete() {
48568
- completedCount++;
48569
- if (completedCount >= mipCount) {
48570
- resolve(texture2D);
48571
- }
48572
- };
48573
- onComplete();
48574
- if (mipmap) {
48575
- var _loop = function _loop(i) {
48576
- var blob = new window.Blob([
48577
- imagesData[i]
48578
- ]);
48579
- var img = new Image();
48580
- img.onload = function() {
48581
- texture2D.setImageSource(img, i);
48582
- onComplete();
48583
- };
48584
- img.src = URL.createObjectURL(blob);
48585
- };
48586
- texture2D.generateMipmaps();
48587
- for(var i = 1; i < mipCount; i++)_loop(i);
48588
- }
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);
48589
49200
  };
48590
49201
  img.src = URL.createObjectURL(blob);
48591
49202
  }
@@ -48593,9 +49204,71 @@
48593
49204
  };
48594
49205
  return Texture2DDecoder;
48595
49206
  }();
48596
- exports.Texture2DDecoder = __decorate([
49207
+ Texture2DDecoder = __decorate([
48597
49208
  decoder("Texture2D")
48598
- ], exports.Texture2DDecoder);
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);
48599
49272
  function _instanceof1(left, right) {
48600
49273
  if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
48601
49274
  return !!right[Symbol.hasInstance](left);
@@ -51166,11 +51839,13 @@
51166
51839
  });
51167
51840
  var img = new Image();
51168
51841
  img.onerror = function() {
51842
+ URL.revokeObjectURL(img.src);
51169
51843
  reject(new Error("Failed to load image buffer"));
51170
51844
  };
51171
51845
  img.onload = function() {
51172
51846
  // Call requestAnimationFrame to avoid iOS's bug.
51173
51847
  requestAnimationFrame(function() {
51848
+ URL.revokeObjectURL(img.src);
51174
51849
  resolve(img);
51175
51850
  img.onload = null;
51176
51851
  img.onerror = null;
@@ -52623,7 +53298,7 @@
52623
53298
  if (uri) {
52624
53299
  var extIndex = uri.lastIndexOf(".");
52625
53300
  var ext = uri.substring(extIndex + 1);
52626
- var type = ext.startsWith("ktx") ? AssetType.KTX : AssetType.Texture2D;
53301
+ var type = ext.startsWith("ktx") ? AssetType.KTX : AssetType.Texture;
52627
53302
  texture = engine.resourceManager.load({
52628
53303
  url: Utils.resolveAbsoluteUrl(url, uri),
52629
53304
  type: type,
@@ -53480,7 +54155,7 @@
53480
54155
  var _atlasItem_type;
53481
54156
  chainPromises.push(resourceManager.load({
53482
54157
  url: Utils.resolveAbsoluteUrl(item.url, atlasItem.img),
53483
- type: (_atlasItem_type = atlasItem.type) != null ? _atlasItem_type : AssetType.Texture2D,
54158
+ type: (_atlasItem_type = atlasItem.type) != null ? _atlasItem_type : AssetType.Texture,
53484
54159
  params: {
53485
54160
  format: format,
53486
54161
  mipmap: mipmap
@@ -53615,26 +54290,12 @@
53615
54290
  "txt"
53616
54291
  ])
53617
54292
  ], TextLoader);
53618
- function loadImageFromBuffer(buffer) {
53619
- return new AssetPromise(function(resolve, reject) {
53620
- var blob = new Blob([
53621
- buffer
53622
- ]);
53623
- var img = new Image();
53624
- img.onload = function() {
53625
- URL.revokeObjectURL(img.src);
53626
- resolve(img);
53627
- };
53628
- img.onerror = reject;
53629
- img.src = URL.createObjectURL(blob);
53630
- });
53631
- }
53632
- var Texture2DLoader = /*#__PURE__*/ function(Loader) {
53633
- _inherits(Texture2DLoader, Loader);
53634
- function Texture2DLoader() {
54293
+ var TextureLoader = /*#__PURE__*/ function(Loader) {
54294
+ _inherits(TextureLoader, Loader);
54295
+ function TextureLoader() {
53635
54296
  return Loader.apply(this, arguments) || this;
53636
54297
  }
53637
- var _proto = Texture2DLoader.prototype;
54298
+ var _proto = TextureLoader.prototype;
53638
54299
  _proto.load = function load(item, resourceManager) {
53639
54300
  var _this = this;
53640
54301
  var url = item.url;
@@ -53644,427 +54305,136 @@
53644
54305
  return new AssetPromise(function(resolve, reject, setTaskCompleteProgress, setTaskDetailProgress) {
53645
54306
  resourceManager // @ts-ignore
53646
54307
  ._request(url, requestConfig).onProgress(setTaskCompleteProgress, setTaskDetailProgress).then(function(buffer) {
53647
- if (FileHeader.checkMagic(buffer)) {
53648
- decode(buffer, resourceManager.engine).then(function(texture) {
53649
- resourceManager.addContentRestorer(new Texture2DContentRestorer(texture, url, requestConfig));
53650
- resolve(texture);
53651
- }, reject);
53652
- } else {
53653
- loadImageFromBuffer(buffer).then(function(img) {
53654
- var texture = _this._createTexture(img, item, resourceManager);
53655
- resourceManager.addContentRestorer(new Texture2DContentRestorer(texture, url, requestConfig));
53656
- resolve(texture);
53657
- }, reject);
53658
- }
54308
+ _this._decode(buffer, item, resourceManager).then(function(texture) {
54309
+ resourceManager.addContentRestorer(new TextureContentRestorer(texture, url, requestConfig));
54310
+ resolve(texture);
54311
+ }, reject);
53659
54312
  }).catch(reject);
53660
54313
  });
53661
54314
  };
53662
- _proto._createTexture = function _createTexture(img, item, resourceManager) {
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) {
53663
54372
  var _item_params;
53664
- 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;
53665
- var width = img.width, height = img.height;
53666
- var engine = resourceManager.engine;
53667
- var generateMipmap = TextureUtils.supportGenerateMipmapsWithCorrection(engine, width, height, format, mipmap, isSRGBColorSpace);
53668
- var texture = new Texture2D(engine, width, height, format, generateMipmap, isSRGBColorSpace);
54373
+ var _ref = (_item_params = item.params) != null ? _item_params : {}, anisoLevel = _ref.anisoLevel, wrapModeU = _ref.wrapModeU, wrapModeV = _ref.wrapModeV, filterMode = _ref.filterMode;
53669
54374
  texture.anisoLevel = anisoLevel != null ? anisoLevel : texture.anisoLevel;
53670
54375
  texture.filterMode = filterMode != null ? filterMode : texture.filterMode;
53671
54376
  texture.wrapModeU = wrapModeU != null ? wrapModeU : texture.wrapModeU;
53672
54377
  texture.wrapModeV = wrapModeV != null ? wrapModeV : texture.wrapModeV;
53673
- texture.setImageSource(img);
53674
- generateMipmap && texture.generateMipmaps();
53675
54378
  var url = item.url;
53676
54379
  if (url.indexOf("data:") !== 0) {
53677
54380
  texture.name = url.substring(url.lastIndexOf("/") + 1);
53678
54381
  }
53679
- return texture;
53680
54382
  };
53681
- return Texture2DLoader;
54383
+ return TextureLoader;
53682
54384
  }(Loader);
53683
- Texture2DLoader = __decorate([
53684
- resourceLoader(AssetType.Texture2D, [
54385
+ TextureLoader = __decorate([
54386
+ resourceLoader(AssetType.Texture, [
54387
+ "tex",
53685
54388
  "png",
53686
54389
  "jpg",
53687
54390
  "webp",
53688
54391
  "jpeg",
53689
- "tex"
54392
+ "hdr"
53690
54393
  ])
53691
- ], Texture2DLoader);
53692
- var Texture2DContentRestorer = /*#__PURE__*/ function(ContentRestorer) {
53693
- _inherits(Texture2DContentRestorer, ContentRestorer);
53694
- function Texture2DContentRestorer(resource, url, requestConfig) {
54394
+ ], TextureLoader);
54395
+ var TextureContentRestorer = /*#__PURE__*/ function(ContentRestorer) {
54396
+ _inherits(TextureContentRestorer, ContentRestorer);
54397
+ function TextureContentRestorer(resource, url, requestConfig) {
53695
54398
  var _this;
53696
54399
  _this = ContentRestorer.call(this, resource) || this, _this.url = url, _this.requestConfig = requestConfig;
53697
54400
  return _this;
53698
54401
  }
53699
- var _proto = Texture2DContentRestorer.prototype;
54402
+ var _proto = TextureContentRestorer.prototype;
53700
54403
  _proto.restoreContent = function restoreContent() {
53701
- var texture = this.resource;
53702
- var engine = texture.engine;
53703
- return engine.resourceManager // @ts-ignore
54404
+ var _this = this;
54405
+ return this.resource.engine.resourceManager // @ts-ignore
53704
54406
  ._request(this.url, this.requestConfig).then(function(buffer) {
53705
54407
  if (FileHeader.checkMagic(buffer)) {
53706
- return decode(buffer, engine, texture);
53707
- } else {
53708
- return loadImageFromBuffer(buffer).then(function(img) {
53709
- texture.setImageSource(img);
53710
- texture.generateMipmaps();
53711
- return texture;
53712
- });
53713
- }
53714
- });
53715
- };
53716
- return Texture2DContentRestorer;
53717
- }(ContentRestorer);
53718
- /**
53719
- * HDR panorama to cubemap decoder.
53720
- */ var HDRDecoder = /*#__PURE__*/ function() {
53721
- function HDRDecoder() {}
53722
- HDRDecoder.parseHeader = function parseHeader(uint8array) {
53723
- var line = this._readStringLine(uint8array, 0);
53724
- if (line[0] !== "#" || line[1] !== "?") {
53725
- throw "HDRDecoder: invalid file header";
53726
- }
53727
- var endOfHeader = false;
53728
- var findFormat = false;
53729
- var lineIndex = 0;
53730
- do {
53731
- lineIndex += line.length + 1;
53732
- line = this._readStringLine(uint8array, lineIndex);
53733
- if (line === "FORMAT=32-bit_rle_rgbe") findFormat = true;
53734
- else if (line.length === 0) endOfHeader = true;
53735
- }while (!endOfHeader);
53736
- if (!findFormat) {
53737
- throw "HDRDecoder: unsupported format, expected 32-bit_rle_rgbe";
53738
- }
53739
- lineIndex += line.length + 1;
53740
- line = this._readStringLine(uint8array, lineIndex);
53741
- var match = /^\-Y (.*) \+X (.*)$/g.exec(line);
53742
- if (!match || match.length < 3) {
53743
- throw "HDRDecoder: missing image size, only -Y +X layout is supported";
53744
- }
53745
- var width = parseInt(match[2]);
53746
- var height = parseInt(match[1]);
53747
- if (width < 8 || width > 0x7fff) {
53748
- throw "HDRDecoder: unsupported image width, must be between 8 and 32767";
53749
- }
53750
- return {
53751
- height: height,
53752
- width: width,
53753
- dataPosition: lineIndex + line.length + 1
53754
- };
53755
- };
53756
- HDRDecoder.decodeFaces = function decodeFaces(bufferArray, header, onFace) {
53757
- var width = header.width, height = header.height, dataPosition = header.dataPosition;
53758
- var cubeSize = height >> 1;
53759
- var pixels = HDRDecoder._readPixels(bufferArray.subarray(dataPosition), width, height);
53760
- var faces = HDRDecoder._faces;
53761
- var faceBuffer = new Uint16Array(cubeSize * cubeSize * 4);
53762
- for(var faceIndex = 0; faceIndex < 6; faceIndex++){
53763
- HDRDecoder._createCubemapData(cubeSize, faces[faceIndex], pixels, width, height, faceBuffer);
53764
- onFace(faceIndex, faceBuffer);
53765
- }
53766
- };
53767
- HDRDecoder._generateFloat2HalfTables = function _generateFloat2HalfTables() {
53768
- var baseTable = new Uint32Array(512);
53769
- var shiftTable = new Uint32Array(512);
53770
- for(var i = 0; i < 256; ++i){
53771
- var e = i - 127;
53772
- if (e < -27) {
53773
- baseTable[i] = 0x0000;
53774
- baseTable[i | 0x100] = 0x8000;
53775
- shiftTable[i] = 24;
53776
- shiftTable[i | 0x100] = 24;
53777
- } else if (e < -14) {
53778
- baseTable[i] = 0x0400 >> -e - 14;
53779
- baseTable[i | 0x100] = 0x0400 >> -e - 14 | 0x8000;
53780
- shiftTable[i] = -e - 1;
53781
- shiftTable[i | 0x100] = -e - 1;
53782
- } else if (e <= 15) {
53783
- baseTable[i] = e + 15 << 10;
53784
- baseTable[i | 0x100] = e + 15 << 10 | 0x8000;
53785
- shiftTable[i] = 13;
53786
- shiftTable[i | 0x100] = 13;
53787
- } else if (e < 128) {
53788
- baseTable[i] = 0x7c00;
53789
- baseTable[i | 0x100] = 0xfc00;
53790
- shiftTable[i] = 24;
53791
- shiftTable[i | 0x100] = 24;
53792
- } else {
53793
- baseTable[i] = 0x7c00;
53794
- baseTable[i | 0x100] = 0xfc00;
53795
- shiftTable[i] = 13;
53796
- shiftTable[i | 0x100] = 13;
53797
- }
53798
- }
53799
- return {
53800
- baseTable: baseTable,
53801
- shiftTable: shiftTable
53802
- };
53803
- };
53804
- HDRDecoder._createCubemapData = function _createCubemapData(texSize, face, pixels, inputWidth, inputHeight, facePixels) {
53805
- var invSize = 1 / texSize;
53806
- var rotDX1X = (face[3] - face[0]) * invSize;
53807
- var rotDX1Y = (face[4] - face[1]) * invSize;
53808
- var rotDX1Z = (face[5] - face[2]) * invSize;
53809
- var rotDX2X = (face[9] - face[6]) * invSize;
53810
- var rotDX2Y = (face[10] - face[7]) * invSize;
53811
- var rotDX2Z = (face[11] - face[8]) * invSize;
53812
- var floatView = HDRDecoder._floatView;
53813
- var uint32View = HDRDecoder._uint32View;
53814
- var _HDRDecoder__float2HalfTables = HDRDecoder._float2HalfTables, baseTable = _HDRDecoder__float2HalfTables.baseTable, shiftTable = _HDRDecoder__float2HalfTables.shiftTable;
53815
- var one = HDRDecoder._one;
53816
- var fy = 0;
53817
- for(var y = 0; y < texSize; y++){
53818
- var xv1X = face[0], xv1Y = face[1], xv1Z = face[2];
53819
- var xv2X = face[6], xv2Y = face[7], xv2Z = face[8];
53820
- for(var x = 0; x < texSize; x++){
53821
- var dirX = xv1X + (xv2X - xv1X) * fy;
53822
- var dirY = xv1Y + (xv2Y - xv1Y) * fy;
53823
- var dirZ = xv1Z + (xv2Z - xv1Z) * fy;
53824
- var invLen = 1 / Math.sqrt(dirX * dirX + dirY * dirY + dirZ * dirZ);
53825
- dirX *= invLen;
53826
- dirY *= invLen;
53827
- dirZ *= invLen;
53828
- var px = Math.round((Math.atan2(dirZ, dirX) / Math.PI * 0.5 + 0.5) * inputWidth);
53829
- if (px < 0) px = 0;
53830
- else if (px >= inputWidth) px = inputWidth - 1;
53831
- var py = Math.round(Math.acos(dirY) / Math.PI * inputHeight);
53832
- if (py < 0) py = 0;
53833
- else if (py >= inputHeight) py = inputHeight - 1;
53834
- var srcIndex = (inputHeight - py - 1) * inputWidth * 4 + px * 4;
53835
- var scaleFactor = Math.pow(2, pixels[srcIndex + 3] - 128) / 255;
53836
- var dstIndex = y * texSize * 4 + x * 4;
53837
- for(var c = 0; c < 3; c++){
53838
- // Clamp to half-float max (65504) to prevent Infinity in R16G16B16A16
53839
- floatView[0] = Math.min(pixels[srcIndex + c] * scaleFactor, 65504);
53840
- var f = uint32View[0];
53841
- var e = f >> 23 & 0x1ff;
53842
- facePixels[dstIndex + c] = baseTable[e] + ((f & 0x007fffff) >> shiftTable[e]);
53843
- }
53844
- facePixels[dstIndex + 3] = one;
53845
- xv1X += rotDX1X;
53846
- xv1Y += rotDX1Y;
53847
- xv1Z += rotDX1Z;
53848
- xv2X += rotDX2X;
53849
- xv2Y += rotDX2Y;
53850
- xv2Z += rotDX2Z;
53851
- }
53852
- fy += invSize;
53853
- }
53854
- };
53855
- HDRDecoder._readStringLine = function _readStringLine(uint8array, startIndex) {
53856
- var line = "";
53857
- for(var i = startIndex, n = uint8array.length; i < n; i++){
53858
- var character = String.fromCharCode(uint8array[i]);
53859
- if (character === "\n") break;
53860
- line += character;
53861
- }
53862
- return line;
53863
- };
53864
- HDRDecoder._readPixels = function _readPixels(buffer, width, height) {
53865
- var byteLength = buffer.byteLength;
53866
- var dataRGBA = new Uint8Array(4 * width * height);
53867
- var offset = 0;
53868
- var pos = 0;
53869
- var ptrEnd = 4 * width;
53870
- var scanLineBuffer = new Uint8Array(ptrEnd);
53871
- var numScanLines = height;
53872
- while(numScanLines > 0 && pos < byteLength){
53873
- var a = buffer[pos++];
53874
- var b = buffer[pos++];
53875
- var c = buffer[pos++];
53876
- var d = buffer[pos++];
53877
- if (a !== 2 || b !== 2 || c & 0x80 || width < 8 || width > 32767) return buffer;
53878
- if ((c << 8 | d) !== width) throw "HDRDecoder: wrong scanline width";
53879
- var ptr = 0;
53880
- while(ptr < ptrEnd && pos < byteLength){
53881
- var count = buffer[pos++];
53882
- var isEncodedRun = count > 128;
53883
- if (isEncodedRun) count -= 128;
53884
- if (count === 0 || ptr + count > ptrEnd) throw "HDRDecoder: bad scanline data";
53885
- if (isEncodedRun) {
53886
- var byteValue = buffer[pos++];
53887
- for(var i = 0; i < count; i++)scanLineBuffer[ptr++] = byteValue;
53888
- } else {
53889
- scanLineBuffer.set(buffer.subarray(pos, pos + count), ptr);
53890
- ptr += count;
53891
- pos += count;
53892
- }
53893
- }
53894
- for(var i1 = 0; i1 < width; i1++, offset += 4){
53895
- dataRGBA[offset] = scanLineBuffer[i1];
53896
- dataRGBA[offset + 1] = scanLineBuffer[i1 + width];
53897
- dataRGBA[offset + 2] = scanLineBuffer[i1 + width * 2];
53898
- dataRGBA[offset + 3] = scanLineBuffer[i1 + width * 3];
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;
53899
54417
  }
53900
- numScanLines--;
53901
- }
53902
- return dataRGBA;
53903
- };
53904
- return HDRDecoder;
53905
- }();
53906
- // Float32 to Float16 lookup tables (http://www.fox-toolkit.org/ftp/fasthalffloatconversion.pdf)
53907
- HDRDecoder._float2HalfTables = HDRDecoder._generateFloat2HalfTables();
53908
- HDRDecoder._floatView = new Float32Array(1);
53909
- HDRDecoder._uint32View = new Uint32Array(HDRDecoder._floatView.buffer);
53910
- HDRDecoder._one = 0x3c00 // Half float for 1.0
53911
- ;
53912
- // prettier-ignore
53913
- HDRDecoder._faces = [
53914
- /* +X */ [
53915
- 1,
53916
- -1,
53917
- -1,
53918
- 1,
53919
- -1,
53920
- 1,
53921
- 1,
53922
- 1,
53923
- -1,
53924
- 1,
53925
- 1,
53926
- 1
53927
- ],
53928
- /* -X */ [
53929
- -1,
53930
- -1,
53931
- 1,
53932
- -1,
53933
- -1,
53934
- -1,
53935
- -1,
53936
- 1,
53937
- 1,
53938
- -1,
53939
- 1,
53940
- -1
53941
- ],
53942
- /* +Y */ [
53943
- -1,
53944
- -1,
53945
- 1,
53946
- 1,
53947
- -1,
53948
- 1,
53949
- -1,
53950
- -1,
53951
- -1,
53952
- 1,
53953
- -1,
53954
- -1
53955
- ],
53956
- /* -Y */ [
53957
- -1,
53958
- 1,
53959
- -1,
53960
- 1,
53961
- 1,
53962
- -1,
53963
- -1,
53964
- 1,
53965
- 1,
53966
- 1,
53967
- 1,
53968
- 1
53969
- ],
53970
- /* +Z */ [
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
- /* -Z */ [
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
- ];
53999
- var TextureCubeLoader = /*#__PURE__*/ function(Loader) {
54000
- _inherits(TextureCubeLoader, Loader);
54001
- function TextureCubeLoader() {
54002
- return Loader.apply(this, arguments) || this;
54003
- }
54004
- var _proto = TextureCubeLoader.prototype;
54005
- _proto.load = function load(item, resourceManager) {
54006
- return new AssetPromise(function(resolve, reject) {
54007
- var engine = resourceManager.engine;
54008
- var url = item.url;
54009
- var requestConfig = _extends({}, item, {
54010
- type: "arraybuffer"
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);
54425
+ 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);
54011
54434
  });
54012
- resourceManager // @ts-ignore
54013
- ._request(url, requestConfig).then(function(buffer) {
54014
- if (!SystemInfo.supportsTextureFormat(engine, TextureFormat.R16G16B16A16)) {
54015
- reject(new Error("TextureCubeLoader: HDR texture requires half float support."));
54016
- return;
54017
- }
54018
- var _item_params;
54019
- 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;
54020
- var bufferArray = new Uint8Array(buffer);
54021
- var header = HDRDecoder.parseHeader(bufferArray);
54022
- var texture = new TextureCube(engine, header.height >> 1, TextureFormat.R16G16B16A16, mipmap, false);
54023
- HDRDecoder.decodeFaces(bufferArray, header, function(faceIndex, data) {
54024
- texture.setPixelBuffer(TextureCubeFace.PositiveX + faceIndex, data, 0);
54025
- });
54026
- texture.generateMipmaps();
54027
- texture.anisoLevel = anisoLevel != null ? anisoLevel : texture.anisoLevel;
54028
- texture.filterMode = filterMode != null ? filterMode : texture.filterMode;
54029
- texture.wrapModeU = wrapModeU != null ? wrapModeU : texture.wrapModeU;
54030
- texture.wrapModeV = wrapModeV != null ? wrapModeV : texture.wrapModeV;
54031
- resourceManager.addContentRestorer(new HDRContentRestorer(texture, url, requestConfig));
54032
- resolve(texture);
54033
- }).catch(reject);
54034
- });
54035
- };
54036
- return TextureCubeLoader;
54037
- }(Loader);
54038
- TextureCubeLoader = __decorate([
54039
- resourceLoader(AssetType.TextureCube, [
54040
- "texCube",
54041
- "hdr"
54042
- ])
54043
- ], TextureCubeLoader);
54044
- var HDRContentRestorer = /*#__PURE__*/ function(ContentRestorer) {
54045
- _inherits(HDRContentRestorer, ContentRestorer);
54046
- function HDRContentRestorer(resource, url, requestConfig) {
54047
- var _this;
54048
- _this = ContentRestorer.call(this, resource) || this, _this.url = url, _this.requestConfig = requestConfig;
54049
- return _this;
54050
- }
54051
- var _proto = HDRContentRestorer.prototype;
54052
- _proto.restoreContent = function restoreContent() {
54053
- var _this = this;
54054
- return new AssetPromise(function(resolve, reject) {
54055
- var resource = _this.resource;
54056
- resource.engine.resourceManager // @ts-ignore
54057
- ._request(_this.url, _this.requestConfig).then(function(buffer) {
54058
- var bufferArray = new Uint8Array(buffer);
54059
- HDRDecoder.decodeFaces(bufferArray, HDRDecoder.parseHeader(bufferArray), function(faceIndex, data) {
54060
- resource.setPixelBuffer(TextureCubeFace.PositiveX + faceIndex, data, 0);
54061
- });
54062
- resource.generateMipmaps();
54063
- resolve(resource);
54064
- }).catch(reject);
54065
54435
  });
54066
54436
  };
54067
- return HDRContentRestorer;
54437
+ return TextureContentRestorer;
54068
54438
  }(ContentRestorer);
54069
54439
  var AudioLoader = /*#__PURE__*/ function(Loader) {
54070
54440
  _inherits(AudioLoader, Loader);
@@ -54896,7 +55266,7 @@
54896
55266
  ], EXT_texture_webp);
54897
55267
 
54898
55268
  //@ts-ignore
54899
- var version = "0.0.0-experimental-2.0-game";
55269
+ var version = "0.0.0-experimental-2.0-game.2";
54900
55270
  console.log("Galacean Engine Version: " + version);
54901
55271
  for(var key in CoreObjects){
54902
55272
  Loader.registerClass(key, CoreObjects[key]);
@@ -55061,6 +55431,7 @@
55061
55431
  exports.MeshShape = MeshShape;
55062
55432
  exports.MeshTopology = MeshTopology;
55063
55433
  exports.ModelMesh = ModelMesh;
55434
+ exports.NoiseModule = NoiseModule;
55064
55435
  exports.OverflowMode = OverflowMode;
55065
55436
  exports.PBRMaterial = PBRMaterial;
55066
55437
  exports.ParserContext = ParserContext;