@galacean/engine 2.0.0-alpha.16 → 2.0.0-alpha.18

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.
@@ -9874,13 +9874,15 @@ var ShadowLib = {
9874
9874
  ShadowVertexDeclaration: ShadowVertexDeclaration,
9875
9875
  ShadowVertex: ShadowVertex
9876
9876
  };
9877
- var particle_common = "vec3 rotationByQuaternions(in vec3 v, in vec4 q) {\n return v + 2.0 * cross(q.xyz, cross(q.xyz, v) + q.w * v);\n}\n\nvec3 rotationByEuler(in vec3 vector, in vec3 rot) {\n float halfRoll = rot.z * 0.5;\n float halfPitch = rot.x * 0.5;\n float halfYaw = rot.y * 0.5;\n\n float sinRoll = sin(halfRoll);\n float cosRoll = cos(halfRoll);\n float sinPitch = sin(halfPitch);\n float cosPitch = cos(halfPitch);\n float sinYaw = sin(halfYaw);\n float cosYaw = cos(halfYaw);\n\n float cosYawPitch = cosYaw * cosPitch;\n float sinYawPitch = sinYaw * sinPitch;\n\n float quaX = (cosYaw * sinPitch * cosRoll) + (sinYaw * cosPitch * sinRoll);\n float quaY = (sinYaw * cosPitch * cosRoll) - (cosYaw * sinPitch * sinRoll);\n float quaZ = (cosYawPitch * sinRoll) - (sinYawPitch * cosRoll);\n float quaW = (cosYawPitch * cosRoll) + (sinYawPitch * sinRoll);\n\n return rotationByQuaternions(vector, vec4(quaX, quaY, quaZ, quaW));\n}\n\n// Assume axis is normalized\nvec3 rotationByAxis(in vec3 vector, in vec3 axis, in float angle) {\n float halfAngle = angle * 0.5;\n float s = sin(halfAngle);\n\n return rotationByQuaternions(vector, vec4(axis * s, cos(halfAngle)));\n}\n\n\nfloat evaluateParticleCurve(in vec2 keys[4], in float normalizedAge) {\n float value;\n for (int i = 1; i < 4; i++) {\n vec2 key = keys[i];\n float time = key.x;\n if (time >= normalizedAge) {\n vec2 lastKey = keys[i - 1];\n float lastTime = lastKey.x;\n float age = (normalizedAge - lastTime) / (time - lastTime);\n value = mix(lastKey.y, key.y, age);\n break;\n }\n }\n return value;\n}\n\nfloat evaluateParticleCurveCumulative(in vec2 keys[4], in float normalizedAge, out float currentValue){\n float cumulativeValue = 0.0;\n for (int i = 1; i < 4; i++){\n\t vec2 key = keys[i];\n\t float time = key.x;\n\t vec2 lastKey = keys[i - 1];\n\t float lastValue = lastKey.y;\n\n\t if (time >= normalizedAge){\n\t\t float lastTime = lastKey.x;\n float offsetTime = normalizedAge - lastTime;\n\t\t float age = offsetTime / (time - lastTime);\n currentValue = mix(lastValue, key.y, age);\n\t\t cumulativeValue += (lastValue + currentValue) * 0.5 * offsetTime;\n\t\t break;\n\t\t}\n\t else{\n\t\t cumulativeValue += (lastValue + key.y) * 0.5 * (time - lastKey.x);\n\t\t}\n\t}\n return cumulativeValue;\n}\n\nvec4 evaluateParticleGradient(in vec4 colorKeys[4], in float colorMaxTime, in vec2 alphaKeys[4], in float alphaMaxTime, in float t) {\n vec4 value;\n\n float alphaT = min(t, alphaMaxTime);\n for (int i = 0; i < 4; i++) {\n vec2 key = alphaKeys[i];\n if (alphaT <= key.x) {\n if (i == 0) {\n value.a = alphaKeys[0].y;\n } else {\n vec2 lastKey = alphaKeys[i - 1];\n float age = (alphaT - lastKey.x) / (key.x - lastKey.x);\n value.a = mix(lastKey.y, key.y, age);\n }\n break;\n }\n }\n\n float colorT = min(t, colorMaxTime);\n for (int i = 0; i < 4; i++) {\n vec4 key = colorKeys[i];\n if (colorT <= key.x) {\n if (i == 0) {\n value.rgb = colorKeys[0].yzw;\n } else {\n vec4 lastKey = colorKeys[i - 1];\n float age = (colorT - lastKey.x) / (key.x - lastKey.x);\n value.rgb = mix(lastKey.yzw, key.yzw, age);\n }\n break;\n }\n }\n\n return value;\n}"; // eslint-disable-line
9877
+ var particle_common = "vec3 rotationByQuaternions(in vec3 v, in vec4 q) {\n return v + 2.0 * cross(q.xyz, cross(q.xyz, v) + q.w * v);\n}\n\nvec4 quaternionConjugate(in vec4 q) {\n return vec4(-q.xyz, q.w);\n}\n\nvec3 rotationByEuler(in vec3 vector, in vec3 rot) {\n float halfRoll = rot.z * 0.5;\n float halfPitch = rot.x * 0.5;\n float halfYaw = rot.y * 0.5;\n\n float sinRoll = sin(halfRoll);\n float cosRoll = cos(halfRoll);\n float sinPitch = sin(halfPitch);\n float cosPitch = cos(halfPitch);\n float sinYaw = sin(halfYaw);\n float cosYaw = cos(halfYaw);\n\n float cosYawPitch = cosYaw * cosPitch;\n float sinYawPitch = sinYaw * sinPitch;\n\n float quaX = (cosYaw * sinPitch * cosRoll) + (sinYaw * cosPitch * sinRoll);\n float quaY = (sinYaw * cosPitch * cosRoll) - (cosYaw * sinPitch * sinRoll);\n float quaZ = (cosYawPitch * sinRoll) - (sinYawPitch * cosRoll);\n float quaW = (cosYawPitch * cosRoll) + (sinYawPitch * sinRoll);\n\n return rotationByQuaternions(vector, vec4(quaX, quaY, quaZ, quaW));\n}\n\n// Assume axis is normalized\nvec3 rotationByAxis(in vec3 vector, in vec3 axis, in float angle) {\n float halfAngle = angle * 0.5;\n float s = sin(halfAngle);\n\n return rotationByQuaternions(vector, vec4(axis * s, cos(halfAngle)));\n}\n\n\nfloat evaluateParticleCurve(in vec2 keys[4], in float normalizedAge) {\n float value;\n for (int i = 1; i < 4; i++) {\n vec2 key = keys[i];\n float time = key.x;\n if (time >= normalizedAge) {\n vec2 lastKey = keys[i - 1];\n float lastTime = lastKey.x;\n float age = (normalizedAge - lastTime) / (time - lastTime);\n value = mix(lastKey.y, key.y, age);\n break;\n }\n }\n return value;\n}\n\nfloat evaluateParticleCurveCumulative(in vec2 keys[4], in float normalizedAge, out float currentValue){\n float cumulativeValue = 0.0;\n for (int i = 1; i < 4; i++){\n\t vec2 key = keys[i];\n\t float time = key.x;\n\t vec2 lastKey = keys[i - 1];\n\t float lastValue = lastKey.y;\n\n\t if (time >= normalizedAge){\n\t\t float lastTime = lastKey.x;\n float offsetTime = normalizedAge - lastTime;\n\t\t float age = offsetTime / (time - lastTime);\n currentValue = mix(lastValue, key.y, age);\n\t\t cumulativeValue += (lastValue + currentValue) * 0.5 * offsetTime;\n\t\t break;\n\t\t}\n\t else{\n\t\t cumulativeValue += (lastValue + key.y) * 0.5 * (time - lastKey.x);\n\t\t}\n\t}\n return cumulativeValue;\n}\n\nvec4 evaluateParticleGradient(in vec4 colorKeys[4], in float colorMaxTime, in vec2 alphaKeys[4], in float alphaMaxTime, in float t) {\n vec4 value;\n\n float alphaT = min(t, alphaMaxTime);\n for (int i = 0; i < 4; i++) {\n vec2 key = alphaKeys[i];\n if (alphaT <= key.x) {\n if (i == 0) {\n value.a = alphaKeys[0].y;\n } else {\n vec2 lastKey = alphaKeys[i - 1];\n float age = (alphaT - lastKey.x) / (key.x - lastKey.x);\n value.a = mix(lastKey.y, key.y, age);\n }\n break;\n }\n }\n\n float colorT = min(t, colorMaxTime);\n for (int i = 0; i < 4; i++) {\n vec4 key = colorKeys[i];\n if (colorT <= key.x) {\n if (i == 0) {\n value.rgb = colorKeys[0].yzw;\n } else {\n vec4 lastKey = colorKeys[i - 1];\n float age = (colorT - lastKey.x) / (key.x - lastKey.x);\n value.rgb = mix(lastKey.yzw, key.yzw, age);\n }\n break;\n }\n }\n\n return value;\n}"; // eslint-disable-line
9878
9878
  var velocity_over_lifetime_module = "#if defined(RENDERER_VOL_CONSTANT_MODE) || defined(RENDERER_VOL_CURVE_MODE)\n #define _VOL_MODULE_ENABLED\n#endif\n\n#ifdef _VOL_MODULE_ENABLED\n uniform int renderer_VOLSpace;\n\n #ifdef RENDERER_VOL_CONSTANT_MODE\n uniform vec3 renderer_VOLMaxConst;\n\n #ifdef RENDERER_VOL_IS_RANDOM_TWO\n uniform vec3 renderer_VOLMinConst;\n #endif\n #endif\n\n #ifdef RENDERER_VOL_CURVE_MODE\n uniform vec2 renderer_VOLMaxGradientX[4]; // x:time y:value\n uniform vec2 renderer_VOLMaxGradientY[4]; // x:time y:value\n uniform vec2 renderer_VOLMaxGradientZ[4]; // x:time y:value\n\n #ifdef RENDERER_VOL_IS_RANDOM_TWO\n uniform vec2 renderer_VOLMinGradientX[4]; // x:time y:value\n uniform vec2 renderer_VOLMinGradientY[4]; // x:time y:value\n uniform vec2 renderer_VOLMinGradientZ[4]; // x:time y:value\n #endif\n #endif\n\n\n vec3 computeVelocityPositionOffset(in float normalizedAge, in float age, out vec3 currentVelocity) {\n vec3 velocityPosition;\n\n #ifdef RENDERER_VOL_CONSTANT_MODE\n currentVelocity = renderer_VOLMaxConst;\n #ifdef RENDERER_VOL_IS_RANDOM_TWO\n currentVelocity = mix(renderer_VOLMinConst, currentVelocity, a_Random1.yzw);\n #endif\n\n velocityPosition = currentVelocity * age;\n #endif\n\n #ifdef RENDERER_VOL_CURVE_MODE\n velocityPosition = vec3(\n evaluateParticleCurveCumulative(renderer_VOLMaxGradientX, normalizedAge, currentVelocity.x),\n evaluateParticleCurveCumulative(renderer_VOLMaxGradientY, normalizedAge, currentVelocity.y),\n evaluateParticleCurveCumulative(renderer_VOLMaxGradientZ, normalizedAge, currentVelocity.z));\n\n #ifdef RENDERER_VOL_IS_RANDOM_TWO\n vec3 minCurrentVelocity;\n vec3 minVelocityPosition = vec3(\n evaluateParticleCurveCumulative(renderer_VOLMinGradientX, normalizedAge, minCurrentVelocity.x),\n evaluateParticleCurveCumulative(renderer_VOLMinGradientY, normalizedAge, minCurrentVelocity.y),\n evaluateParticleCurveCumulative(renderer_VOLMinGradientZ, normalizedAge, minCurrentVelocity.z));\n\n currentVelocity = mix(minCurrentVelocity, currentVelocity, a_Random1.yzw);\n velocityPosition = mix(minVelocityPosition, velocityPosition, a_Random1.yzw);\n #endif\n\n velocityPosition *= vec3(a_ShapePositionStartLifeTime.w);\n #endif\n return velocityPosition;\n }\n#endif\n"; // eslint-disable-line
9879
9879
  var rotation_over_lifetime_module = "#if defined(RENDERER_ROL_CONSTANT_MODE) || defined(RENDERER_ROL_CURVE_MODE)\n #ifdef RENDERER_ROL_CURVE_MODE\n uniform vec2 renderer_ROLMaxCurveZ[4];\n #ifdef RENDERER_ROL_IS_SEPARATE\n uniform vec2 renderer_ROLMaxCurveX[4];\n uniform vec2 renderer_ROLMaxCurveY[4];\n #endif\n #ifdef RENDERER_ROL_IS_RANDOM_TWO\n uniform vec2 renderer_ROLMinCurveZ[4];\n #ifdef RENDERER_ROL_IS_SEPARATE\n uniform vec2 renderer_ROLMinCurveX[4];\n uniform vec2 renderer_ROLMinCurveY[4];\n #endif\n #endif\n #else\n uniform vec3 renderer_ROLMaxConst;\n #ifdef RENDERER_ROL_IS_RANDOM_TWO\n uniform vec3 renderer_ROLMinConst;\n #endif\n #endif\n#endif\n\nfloat computeParticleRotationFloat(in float rotation, in float age, in float normalizedAge) {\n #if defined(RENDERER_ROL_CONSTANT_MODE) || defined(RENDERER_ROL_CURVE_MODE)\n #ifdef RENDERER_ROL_CURVE_MODE\n float currentValue;\n float lifeRotation = evaluateParticleCurveCumulative(renderer_ROLMaxCurveZ, normalizedAge, currentValue);\n #ifdef RENDERER_ROL_IS_RANDOM_TWO\n lifeRotation = mix(evaluateParticleCurveCumulative(renderer_ROLMinCurveZ, normalizedAge, currentValue), lifeRotation, a_Random0.w);\n #endif\n rotation += lifeRotation * a_ShapePositionStartLifeTime.w;\n #else\n float lifeRotation = renderer_ROLMaxConst.z;\n #ifdef RENDERER_ROL_IS_RANDOM_TWO\n lifeRotation = mix(renderer_ROLMinConst.z, lifeRotation, a_Random0.w);\n #endif\n rotation += lifeRotation * age;\n #endif\n #endif\n return rotation;\n}\n\n\n#if defined(RENDERER_MODE_MESH) && (defined(RENDERER_ROL_CONSTANT_MODE) || defined(RENDERER_ROL_CURVE_MODE))\nvec3 computeParticleRotationVec3(in vec3 rotation, in float age, in float normalizedAge) {\n #ifdef RENDERER_ROL_IS_SEPARATE\n #ifdef RENDERER_ROL_CONSTANT_MODE\n #ifdef RENDERER_ROL_IS_RANDOM_TWO\n vec3 ageRot = mix(renderer_ROLMinConst, renderer_ROLMaxConst, a_Random0.w) * age;\n #else\n vec3 ageRot = renderer_ROLMaxConst * age;\n #endif\n rotation += ageRot;\n #endif\n #ifdef RENDERER_ROL_CURVE_MODE\n float currentValue;\n float lifetime = a_ShapePositionStartLifeTime.w;\n #ifdef RENDERER_ROL_IS_RANDOM_TWO\n rotation += vec3(\n mix(evaluateParticleCurveCumulative(renderer_ROLMinCurveX, normalizedAge, currentValue),\n evaluateParticleCurveCumulative(renderer_ROLMaxCurveX, normalizedAge, currentValue), a_Random0.w),\n mix(evaluateParticleCurveCumulative(renderer_ROLMinCurveY, normalizedAge, currentValue),\n evaluateParticleCurveCumulative(renderer_ROLMaxCurveY, normalizedAge, currentValue), a_Random0.w),\n mix(evaluateParticleCurveCumulative(renderer_ROLMinCurveZ, normalizedAge, currentValue),\n evaluateParticleCurveCumulative(renderer_ROLMaxCurveZ, normalizedAge, currentValue), a_Random0.w)) * lifetime;\n #else\n rotation += vec3(\n evaluateParticleCurveCumulative(renderer_ROLMaxCurveX, normalizedAge, currentValue),\n evaluateParticleCurveCumulative(renderer_ROLMaxCurveY, normalizedAge, currentValue),\n evaluateParticleCurveCumulative(renderer_ROLMaxCurveZ, normalizedAge, currentValue)) * lifetime;\n #endif\n #endif\n #else\n #ifdef RENDERER_ROL_CONSTANT_MODE\n #ifdef RENDERER_ROL_IS_RANDOM_TWO\n float ageRot = mix(renderer_ROLMinConst.z, renderer_ROLMaxConst.z, a_Random0.w) * age;\n #else\n float ageRot = renderer_ROLMaxConst.z * age;\n #endif\n rotation += ageRot;\n #endif\n\n #ifdef RENDERER_ROL_CURVE_MODE\n float currentValue;\n float lifeRotation = evaluateParticleCurveCumulative(renderer_ROLMaxCurveZ, normalizedAge, currentValue);\n #ifdef RENDERER_ROL_IS_RANDOM_TWO\n lifeRotation = mix(evaluateParticleCurveCumulative(renderer_ROLMinCurveZ, normalizedAge, currentValue), lifeRotation, a_Random0.w);\n #endif\n rotation += lifeRotation * a_ShapePositionStartLifeTime.w;\n #endif\n #endif\n return rotation;\n}\n#endif\n"; // eslint-disable-line
9880
9880
  var size_over_lifetime_module = "#ifdef RENDERER_SOL_CURVE_MODE\n uniform vec2 renderer_SOLMaxCurveX[4]; // x:time y:value\n #ifdef RENDERER_SOL_IS_SEPARATE\n uniform vec2 renderer_SOLMaxCurveY[4]; // x:time y:value\n uniform vec2 renderer_SOLMaxCurveZ[4]; // x:time y:value\n #endif\n\n #ifdef RENDERER_SOL_IS_RANDOM_TWO\n uniform vec2 renderer_SOLMinCurveX[4]; // x:time y:value\n #ifdef RENDERER_SOL_IS_SEPARATE\n uniform vec2 renderer_SOLMinCurveY[4]; // x:time y:value\n uniform vec2 renderer_SOLMinCurveZ[4]; // x:time y:value\n #endif\n #endif\n#endif\n\nvec2 computeParticleSizeBillboard(in vec2 size, in float normalizedAge) {\n #ifdef RENDERER_SOL_CURVE_MODE\n float lifeSizeX = evaluateParticleCurve(renderer_SOLMaxCurveX, normalizedAge);\n #ifdef RENDERER_SOL_IS_RANDOM_TWO\n lifeSizeX = mix(evaluateParticleCurve(renderer_SOLMinCurveX, normalizedAge), lifeSizeX, a_Random0.z);\n #endif\n\n #ifdef RENDERER_SOL_IS_SEPARATE\n float lifeSizeY = evaluateParticleCurve(renderer_SOLMaxCurveY, normalizedAge);\n #ifdef RENDERER_SOL_IS_RANDOM_TWO\n lifeSizeY = mix(evaluateParticleCurve(renderer_SOLMinCurveY, normalizedAge), lifeSizeY, a_Random0.z);\n #endif\n size *= vec2(lifeSizeX, lifeSizeY);\n #else\n size *= lifeSizeX;\n #endif\n #endif\n return size;\n}\n\n#ifdef RENDERER_MODE_MESH\n vec3 computeParticleSizeMesh(in vec3 size, in float normalizedAge) {\n #ifdef RENDERER_SOL_CURVE\n size *= evaluateParticleCurve(renderer_SOLMaxCurveX, normalizedAge);\n #endif\n #ifdef RENDERER_SOL_RANDOM_CURVES\n size *= mix(evaluateParticleCurve(renderer_SOLMaxCurveX, normalizedAge),\n evaluateParticleCurve(u_SOLSizeGradientMax, normalizedAge),\n a_Random0.z);\n #endif\n #ifdef RENDERER_SOL_CURVE_SEPARATE\n size *= vec3(evaluateParticleCurve(renderer_SOLMinCurveX, normalizedAge),\n evaluateParticleCurve(renderer_SOLMinCurveY, normalizedAge),\n evaluateParticleCurve(renderer_SOLMinCurveZ, normalizedAge));\n #endif\n #ifdef RENDERER_SOL_RANDOM_CURVES_SEPARATE\n size *= vec3(mix(evaluateParticleCurve(renderer_SOLMinCurveX, normalizedAge),\n evaluateParticleCurve(renderer_SOLMaxCurveX, normalizedAge),\n a_Random0.z),\n mix(evaluateParticleCurve(renderer_SOLMinCurveY, normalizedAge),\n evaluateParticleCurve(renderer_SOLMaxCurveY, normalizedAge),\n a_Random0.z),\n mix(evaluateParticleCurve(renderer_SOLMinCurveZ, normalizedAge),\n evaluateParticleCurve(renderer_SOLMaxCurveZ, normalizedAge),\n a_Random0.z));\n #endif\n return size;\n }\n#endif"; // eslint-disable-line
9881
9881
  var color_over_lifetime_module = "#if defined(RENDERER_COL_GRADIENT) || defined(RENDERER_COL_RANDOM_GRADIENTS)\n uniform vec4 renderer_COLMaxGradientColor[4]; // x:time y:r z:g w:b\n uniform vec2 renderer_COLMaxGradientAlpha[4]; // x:time y:alpha\n\n #ifdef RENDERER_COL_RANDOM_GRADIENTS\n uniform vec4 renderer_COLMinGradientColor[4]; // x:time y:r z:g w:b\n uniform vec2 renderer_COLMinGradientAlpha[4]; // x:time y:alpha\n #endif\n\n uniform vec4 renderer_COLGradientKeysMaxTime; // x: minColorKeysMaxTime, y: minAlphaKeysMaxTime, z: maxColorKeysMaxTime, w: maxAlphaKeysMaxTime\n#endif\n\n\nvec4 computeParticleColor(in vec4 color, in float normalizedAge) {\n #if defined(RENDERER_COL_GRADIENT) || defined(RENDERER_COL_RANDOM_GRADIENTS)\n vec4 gradientColor = evaluateParticleGradient(renderer_COLMaxGradientColor, renderer_COLGradientKeysMaxTime.z, renderer_COLMaxGradientAlpha, renderer_COLGradientKeysMaxTime.w, normalizedAge);\n #endif\n\n #ifdef RENDERER_COL_RANDOM_GRADIENTS\n gradientColor = mix(evaluateParticleGradient(renderer_COLMinGradientColor,renderer_COLGradientKeysMaxTime.x, renderer_COLMinGradientAlpha, renderer_COLGradientKeysMaxTime.y, normalizedAge), gradientColor, a_Random0.y);\n #endif\n\n #if defined(RENDERER_COL_GRADIENT) || defined(RENDERER_COL_RANDOM_GRADIENTS)\n color *= gradientColor;\n #endif\n\n return color;\n}\n"; // eslint-disable-line
9882
9882
  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
9883
- 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 attribute vec4 a_Random2;\n\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
9883
+ 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
9884
+ 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
9885
+ 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
9884
9886
  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
9885
9887
  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
9886
9888
  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
@@ -9894,6 +9896,8 @@ var ParticleShaderLib = {
9894
9896
  color_over_lifetime_module: color_over_lifetime_module,
9895
9897
  texture_sheet_animation_module: texture_sheet_animation_module,
9896
9898
  force_over_lifetime_module: force_over_lifetime_module,
9899
+ limit_velocity_over_lifetime_module: limit_velocity_over_lifetime_module,
9900
+ particle_feedback_simulation: particle_feedback_simulation,
9897
9901
  sphere_billboard: sphere_billboard,
9898
9902
  stretched_billboard: stretched_billboard,
9899
9903
  vertical_billboard: vertical_billboard,
@@ -9957,6 +9961,41 @@ var ShaderFactory = /*#__PURE__*/ function() {
9957
9961
  return "#define " + (m.value ? m.name + " " + m.value : m.name) + "\n";
9958
9962
  }).join("");
9959
9963
  };
9964
+ /**
9965
+ * @internal
9966
+ * Compile vertex and fragment source with standard macros, includes, and version header.
9967
+ * @param engine - Engine instance
9968
+ * @param macroCollection - Current macro collection
9969
+ * @param vertexSource - Raw vertex shader source (may contain #include)
9970
+ * @param fragmentSource - Raw fragment shader source
9971
+ * @returns Compiled { vertexSource, fragmentSource } ready for ShaderProgram
9972
+ */ ShaderFactory.compilePlatformSource = function compilePlatformSource(engine, macroCollection, vertexSource, fragmentSource) {
9973
+ var isWebGL2 = engine._hardwareRenderer.isWebGL2;
9974
+ var shaderMacroList = new Array();
9975
+ ShaderMacro._getMacrosElements(macroCollection, shaderMacroList);
9976
+ shaderMacroList.push(ShaderMacro.getByName(isWebGL2 ? "GRAPHICS_API_WEBGL2" : "GRAPHICS_API_WEBGL1"));
9977
+ if (engine._hardwareRenderer.canIUse(GLCapabilityType.shaderTextureLod)) {
9978
+ shaderMacroList.push(ShaderMacro.getByName("HAS_TEX_LOD"));
9979
+ }
9980
+ if (engine._hardwareRenderer.canIUse(GLCapabilityType.standardDerivatives)) {
9981
+ shaderMacroList.push(ShaderMacro.getByName("HAS_DERIVATIVES"));
9982
+ }
9983
+ var noIncludeVertex = ShaderFactory.parseIncludes(vertexSource);
9984
+ var noIncludeFrag = ShaderFactory.parseIncludes(fragmentSource);
9985
+ var macroStr = ShaderFactory.parseCustomMacros(shaderMacroList);
9986
+ noIncludeVertex = macroStr + noIncludeVertex;
9987
+ noIncludeFrag = macroStr + noIncludeFrag;
9988
+ if (isWebGL2) {
9989
+ noIncludeVertex = ShaderFactory.convertTo300(noIncludeVertex);
9990
+ noIncludeFrag = ShaderFactory.convertTo300(noIncludeFrag, true);
9991
+ }
9992
+ var versionStr = isWebGL2 ? "#version 300 es" : "#version 100";
9993
+ var precisionStr = "\n#ifdef GL_FRAGMENT_PRECISION_HIGH\n precision highp float;\n precision highp int;\n#else\n precision mediump float;\n precision mediump int;\n#endif\n";
9994
+ return {
9995
+ vertexSource: versionStr + "\nprecision highp float;\n" + noIncludeVertex,
9996
+ fragmentSource: versionStr + "\n" + (isWebGL2 ? "" : ShaderFactory._shaderExtension) + precisionStr + noIncludeFrag
9997
+ };
9998
+ };
9960
9999
  ShaderFactory.registerInclude = function registerInclude(includeName, includeSource) {
9961
10000
  if (ShaderLib[includeName]) {
9962
10001
  throw 'The "' + includeName + '" shader include already exist';
@@ -10284,7 +10323,7 @@ ShaderTagKey._nameMap = Object.create(null);
10284
10323
  * Shader program, corresponding to the GPU shader program.
10285
10324
  * @internal
10286
10325
  */ var ShaderProgram = /*#__PURE__*/ function() {
10287
- function ShaderProgram(engine, vertexSource, fragmentSource) {
10326
+ function ShaderProgram(engine, vertexSource, fragmentSource, transformFeedbackVaryings) {
10288
10327
  this.sceneUniformBlock = new ShaderUniformBlock();
10289
10328
  this.cameraUniformBlock = new ShaderUniformBlock();
10290
10329
  this.rendererUniformBlock = new ShaderUniformBlock();
@@ -10300,7 +10339,7 @@ ShaderTagKey._nameMap = Object.create(null);
10300
10339
  this._activeTextureUint = 0;
10301
10340
  this._engine = engine;
10302
10341
  this._gl = engine._hardwareRenderer.gl;
10303
- this._glProgram = this._createProgram(vertexSource, fragmentSource);
10342
+ this._glProgram = this._createProgram(vertexSource, fragmentSource, transformFeedbackVaryings);
10304
10343
  if (this._glProgram) {
10305
10344
  this._isValid = true;
10306
10345
  this._recordLocation();
@@ -10446,7 +10485,7 @@ ShaderTagKey._nameMap = Object.create(null);
10446
10485
  };
10447
10486
  /**
10448
10487
  * Init and link program with shader.
10449
- */ _proto._createProgram = function _createProgram(vertexSource, fragmentSource) {
10488
+ */ _proto._createProgram = function _createProgram(vertexSource, fragmentSource, transformFeedbackVaryings) {
10450
10489
  var gl = this._gl;
10451
10490
  // Create and compile shader
10452
10491
  var vertexShader = this._createShader(gl.VERTEX_SHADER, vertexSource);
@@ -10464,6 +10503,10 @@ ShaderTagKey._nameMap = Object.create(null);
10464
10503
  }
10465
10504
  gl.attachShader(program, vertexShader);
10466
10505
  gl.attachShader(program, fragmentShader);
10506
+ // Set Transform Feedback varyings before linking (WebGL2 only)
10507
+ if (transformFeedbackVaryings == null ? void 0 : transformFeedbackVaryings.length) {
10508
+ gl.transformFeedbackVaryings(program, transformFeedbackVaryings, gl.INTERLEAVED_ATTRIBS);
10509
+ }
10467
10510
  gl.linkProgram(program);
10468
10511
  gl.validateProgram(program);
10469
10512
  gl.deleteShader(vertexShader);
@@ -10726,7 +10769,7 @@ var precisionStr = "\n #ifdef GL_FRAGMENT_PRECISION_HIGH\n precision hig
10726
10769
  /**
10727
10770
  * @internal
10728
10771
  */ _proto._getShaderProgram = function _getShaderProgram(engine, macroCollection) {
10729
- var shaderProgramPool = engine._getShaderProgramPool(this);
10772
+ var shaderProgramPool = engine._getShaderProgramPool(this._shaderPassId, this._shaderProgramPools);
10730
10773
  var shaderProgram = shaderProgramPool.get(macroCollection);
10731
10774
  if (shaderProgram) {
10732
10775
  return shaderProgram;
@@ -10748,6 +10791,13 @@ var precisionStr = "\n #ifdef GL_FRAGMENT_PRECISION_HIGH\n precision hig
10748
10791
  shaderProgramPools.length = 0;
10749
10792
  };
10750
10793
  _proto._getCanonicalShaderProgram = function _getCanonicalShaderProgram(engine, macroCollection) {
10794
+ if (this._platformTarget != undefined) {
10795
+ return this._getShaderLabProgram(engine, macroCollection);
10796
+ }
10797
+ var _ShaderFactory_compilePlatformSource = ShaderFactory.compilePlatformSource(engine, macroCollection, this._vertexSource, this._fragmentSource), vertexSource = _ShaderFactory_compilePlatformSource.vertexSource, fragmentSource = _ShaderFactory_compilePlatformSource.fragmentSource;
10798
+ return new ShaderProgram(engine, vertexSource, fragmentSource);
10799
+ };
10800
+ _proto._getShaderLabProgram = function _getShaderLabProgram(engine, macroCollection) {
10751
10801
  var isWebGL2 = engine._hardwareRenderer.isWebGL2;
10752
10802
  var shaderMacroList = new Array();
10753
10803
  ShaderMacro._getMacrosElements(macroCollection, shaderMacroList);
@@ -10758,32 +10808,22 @@ var precisionStr = "\n #ifdef GL_FRAGMENT_PRECISION_HIGH\n precision hig
10758
10808
  if (engine._hardwareRenderer.canIUse(GLCapabilityType.standardDerivatives)) {
10759
10809
  shaderMacroList.push(ShaderMacro.getByName("HAS_DERIVATIVES"));
10760
10810
  }
10761
- // Compatible with non-shaderlab syntax
10762
10811
  var noIncludeVertex = ShaderFactory.parseIncludes(this._vertexSource);
10763
10812
  var noIncludeFrag = ShaderFactory.parseIncludes(this._fragmentSource);
10764
- // Parse macros when use shaderlab
10765
- if (this._platformTarget != undefined) {
10766
- noIncludeVertex = Shader._shaderLab._parseMacros(noIncludeVertex, shaderMacroList);
10767
- noIncludeFrag = Shader._shaderLab._parseMacros(noIncludeFrag, shaderMacroList);
10768
- } else {
10769
- var macroNameStr = ShaderFactory.parseCustomMacros(shaderMacroList);
10770
- noIncludeVertex = macroNameStr + noIncludeVertex;
10771
- noIncludeFrag = macroNameStr + noIncludeFrag;
10772
- }
10773
- // Need to convert to 300 es when the target is GLSL ES 100 or unkdown
10774
- if (isWebGL2 && (this._platformTarget == undefined || this._platformTarget === ShaderLanguage.GLSLES100)) {
10813
+ noIncludeVertex = Shader._shaderLab._parseMacros(noIncludeVertex, shaderMacroList);
10814
+ noIncludeFrag = Shader._shaderLab._parseMacros(noIncludeFrag, shaderMacroList);
10815
+ if (isWebGL2 && this._platformTarget === ShaderLanguage.GLSLES100) {
10775
10816
  noIncludeVertex = ShaderFactory.convertTo300(noIncludeVertex);
10776
10817
  noIncludeFrag = ShaderFactory.convertTo300(noIncludeFrag, true);
10777
10818
  }
10778
10819
  var versionStr = isWebGL2 ? "#version 300 es" : "#version 100";
10779
- var vertexSource = " " + versionStr + " \n " + noIncludeVertex + "\n ";
10820
+ var vertexSource = " " + versionStr + "\n " + noIncludeVertex + "\n ";
10780
10821
  var fragmentSource = " " + versionStr + "\n " + (isWebGL2 ? "" : ShaderFactory._shaderExtension) + "\n " + precisionStr + "\n " + noIncludeFrag + "\n ";
10781
- var shaderProgram = new ShaderProgram(engine, vertexSource, fragmentSource);
10782
- return shaderProgram;
10822
+ return new ShaderProgram(engine, vertexSource, fragmentSource);
10783
10823
  };
10784
10824
  return ShaderPass;
10785
10825
  }(ShaderPart);
10786
- ShaderPass._shaderPassCounter = 0;
10826
+ /** @internal */ ShaderPass._shaderPassCounter = 0;
10787
10827
  /** @internal */ ShaderPass._shaderRootPath = "shaders://root/";
10788
10828
  /**
10789
10829
  * Sub shader.
@@ -23298,6 +23338,15 @@ var TextChunk = function TextChunk() {
23298
23338
  this._platformBuffer.getData(data, bufferByteOffset, dataOffset, dataLength);
23299
23339
  };
23300
23340
  /**
23341
+ * Copy data from another buffer on the GPU.
23342
+ * @param srcBuffer - Source buffer
23343
+ * @param srcByteOffset - Byte offset in the source buffer
23344
+ * @param dstByteOffset - Byte offset in this buffer
23345
+ * @param byteLength - Number of bytes to copy
23346
+ */ _proto.copyFromBuffer = function copyFromBuffer(srcBuffer, srcByteOffset, dstByteOffset, byteLength) {
23347
+ this._platformBuffer.copyFromBuffer(srcBuffer._platformBuffer, srcByteOffset, dstByteOffset, byteLength);
23348
+ };
23349
+ /**
23301
23350
  * Mark buffer as readable, the `data` property will be not accessible anymore.
23302
23351
  */ _proto.markAsUnreadable = function markAsUnreadable() {
23303
23352
  this._data = null;
@@ -23587,8 +23636,8 @@ var BufferUtil = /*#__PURE__*/ function() {
23587
23636
  /**
23588
23637
  * Buffer binding flag.
23589
23638
  */ var BufferBindFlag = /*#__PURE__*/ function(BufferBindFlag) {
23590
- /** Vertex buffer binding flag */ BufferBindFlag[BufferBindFlag["VertexBuffer"] = 0] = "VertexBuffer";
23591
- /** Index buffer binding flag */ BufferBindFlag[BufferBindFlag["IndexBuffer"] = 1] = "IndexBuffer";
23639
+ /** Vertex buffer binding flag. */ BufferBindFlag[BufferBindFlag["VertexBuffer"] = 0] = "VertexBuffer";
23640
+ /** Index buffer binding flag. */ BufferBindFlag[BufferBindFlag["IndexBuffer"] = 1] = "IndexBuffer";
23592
23641
  return BufferBindFlag;
23593
23642
  }({});
23594
23643
  /**
@@ -30960,6 +31009,14 @@ PointerEventEmitter._tempRay = new Ray();
30960
31009
  ParticleBillboardVertexAttribute["cornerTextureCoordinate"] = "a_CornerTextureCoordinate";
30961
31010
  return ParticleBillboardVertexAttribute;
30962
31011
  }({});
31012
+ /**
31013
+ * @internal
31014
+ * Vertex attributes for the Transform Feedback buffer.
31015
+ */ var ParticleFeedbackVertexAttribute = /*#__PURE__*/ function(ParticleFeedbackVertexAttribute) {
31016
+ ParticleFeedbackVertexAttribute["Position"] = "a_FeedbackPosition";
31017
+ ParticleFeedbackVertexAttribute["Velocity"] = "a_FeedbackVelocity";
31018
+ return ParticleFeedbackVertexAttribute;
31019
+ }({});
30963
31020
  /**
30964
31021
  * @internal
30965
31022
  */ var ParticleInstanceVertexAttribute = /*#__PURE__*/ function(ParticleInstanceVertexAttribute) {
@@ -31052,6 +31109,22 @@ PointerEventEmitter._tempRay = new Ray();
31052
31109
  return _class;
31053
31110
  }(ContentRestorer))());
31054
31111
  };
31112
+ ParticleBufferUtils.feedbackVertexStride = 24;
31113
+ ParticleBufferUtils.feedbackVertexElements = [
31114
+ new VertexElement(ParticleFeedbackVertexAttribute.Position, 0, VertexElementFormat.Vector3, 0),
31115
+ new VertexElement(ParticleFeedbackVertexAttribute.Velocity, 12, VertexElementFormat.Vector3, 0)
31116
+ ];
31117
+ ParticleBufferUtils.feedbackInstanceElements = [
31118
+ new VertexElement(ParticleInstanceVertexAttribute.ShapePositionStartLifeTime, 0, VertexElementFormat.Vector4, 0),
31119
+ new VertexElement(ParticleInstanceVertexAttribute.DirectionTime, 16, VertexElementFormat.Vector4, 0),
31120
+ new VertexElement(ParticleInstanceVertexAttribute.StartSize, 48, VertexElementFormat.Vector3, 0),
31121
+ new VertexElement(ParticleInstanceVertexAttribute.StartSpeed, 72, VertexElementFormat.Float, 0),
31122
+ new VertexElement(ParticleInstanceVertexAttribute.Random0, 76, VertexElementFormat.Vector4, 0),
31123
+ new VertexElement(ParticleInstanceVertexAttribute.Random1, 92, VertexElementFormat.Vector4, 0),
31124
+ new VertexElement(ParticleInstanceVertexAttribute.SimulationWorldPosition, 108, VertexElementFormat.Vector3, 0),
31125
+ new VertexElement(ParticleInstanceVertexAttribute.SimulationWorldRotation, 120, VertexElementFormat.Vector4, 0),
31126
+ new VertexElement(ParticleInstanceVertexAttribute.Random2, 152, VertexElementFormat.Vector4, 0)
31127
+ ];
31055
31128
  ParticleBufferUtils.instanceVertexStride = 168;
31056
31129
  ParticleBufferUtils.instanceVertexFloatStride = ParticleBufferUtils.instanceVertexStride / 4;
31057
31130
  ParticleBufferUtils.startLifeTimeOffset = 3;
@@ -31072,7 +31145,7 @@ var blinnPhongVs = "#include <common>\n#include <common_vert>\n#include <blendSh
31072
31145
  var depthOnlyFs = "void main() {\n}"; // eslint-disable-line
31073
31146
  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
31074
31147
  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
31075
- 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\nattribute vec3 a_SimulationWorldPosition;\nattribute vec4 a_SimulationWorldRotation;\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 vec2 u_DragConstant;\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 getStartPosition(vec3 startVelocity, float age, vec3 dragData) {\n vec3 startPosition;\n float lastTime = min(startVelocity.x / dragData.x, age); // todo 0/0\n startPosition = lastTime * (startVelocity - 0.5 * dragData * lastTime);\n return startPosition;\n}\n\nvec3 computeParticlePosition(in vec3 startVelocity, in float age, in float normalizedAge, vec3 gravityVelocity, vec4 worldRotation, vec3 dragData, inout vec3 localVelocity, inout vec3 worldVelocity) {\n vec3 startPosition = getStartPosition(startVelocity, age, dragData);\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 if (normalizedAge < 1.0) {\n vec3 startVelocity = a_DirectionTime.xyz * a_StartSpeed;\n vec3 gravityVelocity = renderer_Gravity * a_Random0.x * age;\n\n vec4 worldRotation;\n if (renderer_SimulationSpace == 0) {\n worldRotation = renderer_WorldRotation;\n } else {\n worldRotation = a_SimulationWorldRotation;\n }\n\n vec3 localVelocity = startVelocity;\n vec3 worldVelocity = gravityVelocity;\n\n //drag\n vec3 dragData = a_DirectionTime.xyz * mix(u_DragConstant.x, u_DragConstant.y, a_Random0.x);\n vec3 center = computeParticlePosition(startVelocity, age, normalizedAge, gravityVelocity, worldRotation, dragData, localVelocity, worldVelocity);\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
31148
+ 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
31076
31149
  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
31077
31150
  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
31078
31151
  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
@@ -31090,12 +31163,45 @@ var trailFs = "#include <common>\n\nvarying vec2 v_uv;\nvarying vec4 v_color;\n\
31090
31163
  var trailVs = "attribute vec4 a_PositionBirthTime; // xyz: World position, w: Birth time (used by CPU only)\nattribute vec4 a_CornerTangent; // x: Corner (-1 or 1), yzw: Tangent direction\nattribute float a_Distance; // Absolute cumulative distance (written once per point)\n\nuniform vec4 renderer_TrailParams; // x: TextureMode (0: Stretch, 1: Tile), y: TextureScaleX, z: TextureScaleY\nuniform vec2 renderer_DistanceParams; // x: HeadDistance, y: TailDistance\nuniform vec3 camera_Position;\nuniform mat4 camera_ViewMat;\nuniform mat4 camera_ProjMat;\nuniform vec2 renderer_WidthCurve[4]; // Width curve (4 keyframes max: x=time, y=value)\nuniform vec4 renderer_ColorKeys[4]; // Color gradient (x=time, yzw=rgb)\nuniform vec2 renderer_AlphaKeys[4]; // Alpha gradient (x=time, y=alpha)\nuniform vec4 renderer_CurveMaxTime; // x: colorMaxTime, y: alphaMaxTime, z: widthMaxTime\n\nvarying vec2 v_uv;\nvarying vec4 v_color;\n\n#include <particle_common>\n\nvoid main() {\n vec3 position = a_PositionBirthTime.xyz;\n float corner = a_CornerTangent.x;\n vec3 tangent = a_CornerTangent.yzw;\n\n // Distance-based relative position: 0=head(newest), 1=tail(oldest)\n float distFromHead = renderer_DistanceParams.x - a_Distance;\n float totalDist = renderer_DistanceParams.x - renderer_DistanceParams.y;\n float relativePos = totalDist > 0.0 ? distFromHead / totalDist : 0.0;\n\n // Billboard: expand perpendicular to tangent and view direction\n vec3 toCamera = normalize(camera_Position - position);\n vec3 right = cross(tangent, toCamera);\n float rightLenSq = dot(right, right);\n if (rightLenSq < 0.000001) {\n right = cross(tangent, vec3(0.0, 1.0, 0.0));\n rightLenSq = dot(right, right);\n if (rightLenSq < 0.000001) {\n right = cross(tangent, vec3(1.0, 0.0, 0.0));\n rightLenSq = dot(right, right);\n }\n }\n right = right * inversesqrt(rightLenSq);\n\n float width = evaluateParticleCurve(renderer_WidthCurve, min(relativePos, renderer_CurveMaxTime.z));\n vec3 worldPosition = position + right * width * 0.5 * corner;\n\n gl_Position = camera_ProjMat * camera_ViewMat * vec4(worldPosition, 1.0);\n\n // u = position along trail (affected by textureMode), v = corner side.\n float u = renderer_TrailParams.x == 0.0 ? relativePos : distFromHead;\n float v = corner * 0.5 + 0.5;\n v_uv = vec2(u * renderer_TrailParams.y, v * renderer_TrailParams.z);\n\n v_color = evaluateParticleGradient(renderer_ColorKeys, renderer_CurveMaxTime.x, renderer_AlphaKeys, renderer_CurveMaxTime.y, relativePos);\n}\n"; // eslint-disable-line
31091
31164
  var unlitFs = "#include <common>\n#include <uv_share>\n#include <FogFragmentDeclaration>\n\nuniform vec4 material_BaseColor;\nuniform float material_AlphaCutoff;\n\n#ifdef MATERIAL_HAS_BASETEXTURE\n uniform sampler2D material_BaseTexture;\n#endif\n\nvoid main() {\n vec4 baseColor = material_BaseColor;\n\n #ifdef MATERIAL_HAS_BASETEXTURE\n baseColor *= texture2DSRGB(material_BaseTexture, v_uv);\n #endif\n\n #ifdef MATERIAL_IS_ALPHA_CUTOFF\n if( baseColor.a < material_AlphaCutoff ) {\n discard;\n }\n #endif\n\n gl_FragColor = baseColor;\n\n #ifndef MATERIAL_IS_TRANSPARENT\n gl_FragColor.a = 1.0;\n #endif\n\n #include <FogFragment>\n}\n"; // eslint-disable-line
31092
31165
  var unlitVs = "#include <common>\n#include <common_vert>\n#include <blendShape_input>\n#include <uv_share>\n#include <FogVertexDeclaration>\n\nvoid main() {\n\n #include <begin_position_vert>\n #include <blendShape_vert>\n #include <skinning_vert>\n #include <uv_vert>\n #include <position_vert>\n\n #include <FogVertex>\n}\n"; // eslint-disable-line
31166
+ /**
31167
+ * @internal
31168
+ * Shared shader definition for Transform Feedback simulation.
31169
+ * Multiple simulators using the same shader share a single program pool per engine.
31170
+ */ var TransformFeedbackShader = /*#__PURE__*/ function() {
31171
+ function TransformFeedbackShader(vertexSource, fragmentSource, feedbackVaryings) {
31172
+ this._id = ShaderPass._shaderPassCounter++;
31173
+ this.vertexSource = vertexSource;
31174
+ this.fragmentSource = fragmentSource;
31175
+ this.feedbackVaryings = feedbackVaryings;
31176
+ }
31177
+ var _proto = TransformFeedbackShader.prototype;
31178
+ /**
31179
+ * Get or compile a shader program for the given engine and macro combination.
31180
+ */ _proto.getProgram = function getProgram(engine, macroCollection) {
31181
+ var pool = engine._getShaderProgramPool(this._id);
31182
+ var program = pool.get(macroCollection);
31183
+ if (program) return program;
31184
+ var _ShaderFactory_compilePlatformSource = ShaderFactory.compilePlatformSource(engine, macroCollection, this.vertexSource, this.fragmentSource), vertexSource = _ShaderFactory_compilePlatformSource.vertexSource, fragmentSource = _ShaderFactory_compilePlatformSource.fragmentSource;
31185
+ program = new ShaderProgram(engine, vertexSource, fragmentSource, this.feedbackVaryings);
31186
+ if (!program.isValid) {
31187
+ Logger.error("TransformFeedbackShader: Failed to compile shader program.");
31188
+ return null;
31189
+ }
31190
+ pool.cache(program);
31191
+ return program;
31192
+ };
31193
+ return TransformFeedbackShader;
31194
+ }();
31093
31195
  /**
31094
31196
  * Internal shader pool.
31095
31197
  * @internal
31096
31198
  */ var ShaderPool = /*#__PURE__*/ function() {
31097
31199
  function ShaderPool() {}
31098
31200
  ShaderPool.init = function init() {
31201
+ ShaderPool.particleFeedbackShader = new TransformFeedbackShader("#include <particle_feedback_simulation>", "void main() { discard; }", [
31202
+ "v_FeedbackPosition",
31203
+ "v_FeedbackVelocity"
31204
+ ]);
31099
31205
  var shadowCasterPass = new ShaderPass("ShadowCaster", shadowMapVs, shadowMapFs, {
31100
31206
  pipelineStage: PipelineStage.ShadowCaster
31101
31207
  });
@@ -31586,8 +31692,7 @@ ShaderPool.init();
31586
31692
  };
31587
31693
  /**
31588
31694
  * @internal
31589
- */ _proto._getShaderProgramPool = function _getShaderProgramPool(shaderPass) {
31590
- var index = shaderPass._shaderPassId;
31695
+ */ _proto._getShaderProgramPool = function _getShaderProgramPool(index, trackPools) {
31591
31696
  var shaderProgramPools = this._shaderProgramPools;
31592
31697
  var pool = shaderProgramPools[index];
31593
31698
  if (!pool) {
@@ -31596,7 +31701,7 @@ ShaderPool.init();
31596
31701
  shaderProgramPools.length = length;
31597
31702
  }
31598
31703
  shaderProgramPools[index] = pool = new ShaderProgramPool(this);
31599
- shaderPass._shaderProgramPools.push(pool);
31704
+ trackPools == null ? void 0 : trackPools.push(pool);
31600
31705
  }
31601
31706
  return pool;
31602
31707
  };
@@ -33470,24 +33575,24 @@ AmbientOcclusion._enableMacro = ShaderMacro.getByName("SCENE_ENABLE_AMBIENT_OCCL
33470
33575
  Scene._fogColorProperty = ShaderProperty.getByName("scene_FogColor");
33471
33576
  Scene._fogParamsProperty = ShaderProperty.getByName("scene_FogParams");
33472
33577
  Scene._prefilterdDFGProperty = ShaderProperty.getByName("scene_PrefilteredDFG");
33473
- function _array_like_to_array$1(arr, len) {
33578
+ function _array_like_to_array$2(arr, len) {
33474
33579
  if (len == null || len > arr.length) len = arr.length;
33475
33580
  for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
33476
33581
  return arr2;
33477
33582
  }
33478
- function _unsupported_iterable_to_array$1(o, minLen) {
33583
+ function _unsupported_iterable_to_array$2(o, minLen) {
33479
33584
  if (!o) return;
33480
- if (typeof o === "string") return _array_like_to_array$1(o, minLen);
33585
+ if (typeof o === "string") return _array_like_to_array$2(o, minLen);
33481
33586
  var n = Object.prototype.toString.call(o).slice(8, -1);
33482
33587
  if (n === "Object" && o.constructor) n = o.constructor.name;
33483
33588
  if (n === "Map" || n === "Set") return Array.from(n);
33484
- if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array$1(o, minLen);
33589
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array$2(o, minLen);
33485
33590
  }
33486
- function _create_for_of_iterator_helper_loose$1(o, allowArrayLike) {
33591
+ function _create_for_of_iterator_helper_loose$2(o, allowArrayLike) {
33487
33592
  var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
33488
33593
  if (it) return (it = it.call(o)).next.bind(it);
33489
33594
  // Fallback for engines without symbol support
33490
- if (Array.isArray(o) || (it = _unsupported_iterable_to_array$1(o)) || allowArrayLike && o && typeof o.length === "number") {
33595
+ if (Array.isArray(o) || (it = _unsupported_iterable_to_array$2(o)) || allowArrayLike && o && typeof o.length === "number") {
33491
33596
  if (it) o = it;
33492
33597
  var i = 0;
33493
33598
  return function() {
@@ -33642,7 +33747,7 @@ function _create_for_of_iterator_helper_loose$1(o, allowArrayLike) {
33642
33747
  if (this.onPhysicsUpdate !== prototype.onPhysicsUpdate) {
33643
33748
  componentsManager.addOnPhysicsUpdateScript(this);
33644
33749
  }
33645
- for(var _iterator = _create_for_of_iterator_helper_loose$1(Object.values(PointerMethods)), _step; !(_step = _iterator()).done;){
33750
+ for(var _iterator = _create_for_of_iterator_helper_loose$2(Object.values(PointerMethods)), _step; !(_step = _iterator()).done;){
33646
33751
  var pointerMethod = _step.value;
33647
33752
  if (this[pointerMethod] === prototype[pointerMethod]) {
33648
33753
  this[pointerMethod] = null;
@@ -37896,6 +38001,10 @@ var ParticleStopMode = /*#__PURE__*/ function(ParticleStopMode) {
37896
38001
  shaderData.setFloat(ParticleRenderer._currentTime, this.generator._playTime);
37897
38002
  shaderData.setVector3(ParticleRenderer._pivotOffsetProperty, this.pivot);
37898
38003
  this.generator._updateShaderData(shaderData);
38004
+ // Run Transform Feedback simulation after shader data is up to date
38005
+ if (generator._useTransformFeedback) {
38006
+ generator._updateFeedback(shaderData, this.engine.time.deltaTime * generator.main.simulationSpeed);
38007
+ }
37899
38008
  };
37900
38009
  _proto._render = function _render(context) {
37901
38010
  var generator = this.generator;
@@ -37904,7 +38013,9 @@ var ParticleStopMode = /*#__PURE__*/ function(ParticleStopMode) {
37904
38013
  if (!aliveParticleCount) {
37905
38014
  return;
37906
38015
  }
37907
- generator._primitive.instanceCount = aliveParticleCount;
38016
+ // Transform Feedback: render all slots (instance buffer not compacted, dead particles discarded in shader)
38017
+ // Non-Transform Feedback: render only alive particles (instance buffer compacted)
38018
+ generator._primitive.instanceCount = generator._useTransformFeedback ? generator._firstActiveElement <= generator._firstFreeElement ? generator._firstFreeElement : generator._currentParticleCount : aliveParticleCount;
37908
38019
  var material = this.getMaterial();
37909
38020
  if (!material || this._renderMode === ParticleRenderMode.Mesh && !this._mesh) {
37910
38021
  return;
@@ -38059,6 +38170,327 @@ __decorate$1([
38059
38170
  /** On Generator Bounds Related Params Changed */ ParticleUpdateFlags[ParticleUpdateFlags["GeneratorVolume"] = 4] = "GeneratorVolume";
38060
38171
  return ParticleUpdateFlags;
38061
38172
  }({});
38173
+ /**
38174
+ * Transform Feedback object for GPU-based data capture.
38175
+ * @internal
38176
+ */ var TransformFeedback = /*#__PURE__*/ function(GraphicsResource) {
38177
+ _inherits$2(TransformFeedback, GraphicsResource);
38178
+ function TransformFeedback(engine) {
38179
+ var _this;
38180
+ _this = GraphicsResource.call(this, engine) || this;
38181
+ _this._platformTransformFeedback = engine._hardwareRenderer.createPlatformTransformFeedback();
38182
+ return _this;
38183
+ }
38184
+ var _proto = TransformFeedback.prototype;
38185
+ /**
38186
+ * Bind this Transform Feedback object as active.
38187
+ */ _proto.bind = function bind() {
38188
+ this._platformTransformFeedback.bind();
38189
+ };
38190
+ /**
38191
+ * Bind a buffer range as output at the given index.
38192
+ * @param index - Output binding point index (corresponds to varying index in shader)
38193
+ * @param buffer - Output buffer to capture data into
38194
+ * @param byteOffset - Starting byte offset in the buffer
38195
+ * @param byteSize - Size in bytes of the capture range
38196
+ */ _proto.bindBufferRange = function bindBufferRange(index, buffer, byteOffset, byteSize) {
38197
+ this._platformTransformFeedback.bindBufferRange(index, buffer._platformBuffer, byteOffset, byteSize);
38198
+ };
38199
+ /**
38200
+ * Begin a Transform Feedback pass.
38201
+ * @param primitiveMode - Primitive topology mode
38202
+ */ _proto.begin = function begin(primitiveMode) {
38203
+ this._platformTransformFeedback.begin(primitiveMode);
38204
+ };
38205
+ /**
38206
+ * End the current Transform Feedback pass.
38207
+ */ _proto.end = function end() {
38208
+ this._platformTransformFeedback.end();
38209
+ };
38210
+ /**
38211
+ * Unbind the output buffer at the given index from the Transform Feedback target.
38212
+ * @param index - Output binding point index
38213
+ */ _proto.unbindBuffer = function unbindBuffer(index) {
38214
+ this._platformTransformFeedback.unbindBuffer(index);
38215
+ };
38216
+ /**
38217
+ * Unbind this Transform Feedback object.
38218
+ */ _proto.unbind = function unbind() {
38219
+ this._platformTransformFeedback.unbind();
38220
+ };
38221
+ _proto._rebuild = function _rebuild() {
38222
+ this._platformTransformFeedback = this._engine._hardwareRenderer.createPlatformTransformFeedback();
38223
+ };
38224
+ _proto._onDestroy = function _onDestroy() {
38225
+ GraphicsResource.prototype._onDestroy.call(this);
38226
+ this._platformTransformFeedback.destroy();
38227
+ };
38228
+ return TransformFeedback;
38229
+ }(GraphicsResource);
38230
+ /**
38231
+ * @internal
38232
+ * Primitive for Transform Feedback simulation with read/write buffer swapping.
38233
+ */ var TransformFeedbackPrimitive = /*#__PURE__*/ function(GraphicsResource) {
38234
+ _inherits$2(TransformFeedbackPrimitive, GraphicsResource);
38235
+ function TransformFeedbackPrimitive(engine, byteStride) {
38236
+ var _this;
38237
+ _this = GraphicsResource.call(this, engine) || this, _this._readIsA = true;
38238
+ _this._byteStride = byteStride;
38239
+ _this._transformFeedback = new TransformFeedback(engine);
38240
+ _this._transformFeedback.isGCIgnored = true;
38241
+ _this._platformPrimitive = engine._hardwareRenderer.createPlatformTransformFeedbackPrimitive();
38242
+ _this.isGCIgnored = true;
38243
+ return _this;
38244
+ }
38245
+ var _proto = TransformFeedbackPrimitive.prototype;
38246
+ /**
38247
+ * Resize read and write buffers.
38248
+ * @param vertexCount - Number of vertices to allocate
38249
+ */ _proto.resize = function resize(vertexCount) {
38250
+ var byteLength = this._byteStride * vertexCount;
38251
+ var bufferA = new Buffer(this._engine, BufferBindFlag.VertexBuffer, byteLength, BufferUsage.Dynamic, false);
38252
+ bufferA.isGCIgnored = true;
38253
+ var bufferB = new Buffer(this._engine, BufferBindFlag.VertexBuffer, byteLength, BufferUsage.Dynamic, false);
38254
+ bufferB.isGCIgnored = true;
38255
+ this._bindingA = new VertexBufferBinding(bufferA, this._byteStride);
38256
+ this._bindingB = new VertexBufferBinding(bufferB, this._byteStride);
38257
+ this._readIsA = true;
38258
+ this._platformPrimitive.invalidate();
38259
+ };
38260
+ /**
38261
+ * Update vertex layout, only rebuilds when program changes.
38262
+ * @param program - Shader program for attribute locations
38263
+ * @param feedbackElements - Vertex elements describing the read/write buffer
38264
+ * @param inputBinding - Additional input buffer binding
38265
+ * @param inputElements - Vertex elements describing the input buffer
38266
+ */ _proto.updateVertexLayout = function updateVertexLayout(program, feedbackElements, inputBinding, inputElements) {
38267
+ this._platformPrimitive.updateVertexLayout(program, this._bindingA, this._bindingB, feedbackElements, inputBinding, inputElements);
38268
+ };
38269
+ /**
38270
+ * Bind state before issuing draw calls.
38271
+ */ _proto.beginDraw = function beginDraw() {
38272
+ this._engine._hardwareRenderer.enableRasterizerDiscard();
38273
+ this._transformFeedback.bind();
38274
+ this._platformPrimitive.bind(this._readIsA);
38275
+ };
38276
+ /**
38277
+ * Issue a draw call for a vertex range, capturing output to the write buffer.
38278
+ * @param mode - Primitive topology
38279
+ * @param first - First vertex index
38280
+ * @param count - Number of vertices
38281
+ */ _proto.draw = function draw(mode, first, count) {
38282
+ var transformFeedback = this._transformFeedback;
38283
+ transformFeedback.bindBufferRange(0, this.writeBinding.buffer, first * this._byteStride, count * this._byteStride);
38284
+ transformFeedback.begin(mode);
38285
+ this._platformPrimitive.draw(mode, first, count);
38286
+ transformFeedback.end();
38287
+ };
38288
+ /**
38289
+ * Unbind state after draw calls.
38290
+ */ _proto.endDraw = function endDraw() {
38291
+ this._platformPrimitive.unbind();
38292
+ this._transformFeedback.unbindBuffer(0);
38293
+ this._transformFeedback.unbind();
38294
+ this._engine._hardwareRenderer.disableRasterizerDiscard();
38295
+ this._engine._hardwareRenderer.invalidateShaderProgramState();
38296
+ };
38297
+ /**
38298
+ * Swap read and write buffers.
38299
+ */ _proto.swap = function swap() {
38300
+ this._readIsA = !this._readIsA;
38301
+ };
38302
+ _proto._rebuild = function _rebuild() {
38303
+ this._platformPrimitive = this._engine._hardwareRenderer.createPlatformTransformFeedbackPrimitive();
38304
+ };
38305
+ _proto._onDestroy = function _onDestroy() {
38306
+ var _this__platformPrimitive, _this__bindingA, _this__bindingB, _this__transformFeedback;
38307
+ GraphicsResource.prototype._onDestroy.call(this);
38308
+ (_this__platformPrimitive = this._platformPrimitive) == null ? void 0 : _this__platformPrimitive.destroy();
38309
+ (_this__bindingA = this._bindingA) == null ? void 0 : _this__bindingA.buffer.destroy();
38310
+ (_this__bindingB = this._bindingB) == null ? void 0 : _this__bindingB.buffer.destroy();
38311
+ (_this__transformFeedback = this._transformFeedback) == null ? void 0 : _this__transformFeedback.destroy();
38312
+ };
38313
+ _create_class$2(TransformFeedbackPrimitive, [
38314
+ {
38315
+ key: "readBinding",
38316
+ get: /**
38317
+ * The current read buffer binding.
38318
+ */ function get() {
38319
+ return this._readIsA ? this._bindingA : this._bindingB;
38320
+ }
38321
+ },
38322
+ {
38323
+ key: "writeBinding",
38324
+ get: /**
38325
+ * The current write buffer binding.
38326
+ */ function get() {
38327
+ return this._readIsA ? this._bindingB : this._bindingA;
38328
+ }
38329
+ }
38330
+ ]);
38331
+ return TransformFeedbackPrimitive;
38332
+ }(GraphicsResource);
38333
+ /**
38334
+ * @internal
38335
+ * General-purpose Transform Feedback simulator.
38336
+ * Manages per-frame simulation with shared shader program caching.
38337
+ */ var TransformFeedbackSimulator = /*#__PURE__*/ function() {
38338
+ function TransformFeedbackSimulator(engine, byteStride, shader) {
38339
+ this._engine = engine;
38340
+ this._primitive = new TransformFeedbackPrimitive(engine, byteStride);
38341
+ this._shader = shader;
38342
+ }
38343
+ var _proto = TransformFeedbackSimulator.prototype;
38344
+ /**
38345
+ * Resize feedback buffers.
38346
+ * @param vertexCount - Number of vertices to allocate
38347
+ */ _proto.resize = function resize(vertexCount) {
38348
+ this._primitive.resize(vertexCount);
38349
+ };
38350
+ /**
38351
+ * Begin a simulation step: get/compile program, bind, upload uniforms, update layout.
38352
+ * @param shaderData - Shader data with current macros and uniforms
38353
+ * @param feedbackElements - Vertex elements for the feedback buffer
38354
+ * @param inputBinding - Input buffer binding
38355
+ * @param inputElements - Vertex elements for the input buffer
38356
+ */ _proto.beginUpdate = function beginUpdate(shaderData, feedbackElements, inputBinding, inputElements) {
38357
+ var program = this._shader.getProgram(this._engine, shaderData._macroCollection);
38358
+ if (!program) return false;
38359
+ program.bind();
38360
+ program.uploadUniforms(program.rendererUniformBlock, shaderData);
38361
+ program.uploadUniforms(program.otherUniformBlock, shaderData);
38362
+ this._primitive.updateVertexLayout(program, feedbackElements, inputBinding, inputElements);
38363
+ this._primitive.beginDraw();
38364
+ return true;
38365
+ };
38366
+ /**
38367
+ * Issue a draw call for a vertex range.
38368
+ * @param mode - Primitive topology
38369
+ * @param first - First vertex index
38370
+ * @param count - Number of vertices
38371
+ */ _proto.draw = function draw(mode, first, count) {
38372
+ this._primitive.draw(mode, first, count);
38373
+ };
38374
+ /**
38375
+ * End the simulation step: unbind state and swap buffers.
38376
+ */ _proto.endUpdate = function endUpdate() {
38377
+ this._primitive.endDraw();
38378
+ this._primitive.swap();
38379
+ };
38380
+ _proto.destroy = function destroy() {
38381
+ var _this__primitive;
38382
+ (_this__primitive = this._primitive) == null ? void 0 : _this__primitive.destroy();
38383
+ };
38384
+ _create_class$2(TransformFeedbackSimulator, [
38385
+ {
38386
+ key: "readBinding",
38387
+ get: /**
38388
+ * The current read buffer binding.
38389
+ */ function get() {
38390
+ return this._primitive.readBinding;
38391
+ }
38392
+ },
38393
+ {
38394
+ key: "writeBinding",
38395
+ get: /**
38396
+ * The current write buffer binding.
38397
+ */ function get() {
38398
+ return this._primitive.writeBinding;
38399
+ }
38400
+ }
38401
+ ]);
38402
+ return TransformFeedbackSimulator;
38403
+ }();
38404
+ /**
38405
+ * @internal
38406
+ * Particle-specific Transform Feedback simulation.
38407
+ */ var ParticleTransformFeedbackSimulator = /*#__PURE__*/ function() {
38408
+ function ParticleTransformFeedbackSimulator(engine) {
38409
+ this._particleInitData = new Float32Array(6);
38410
+ this._simulator = new TransformFeedbackSimulator(engine, ParticleBufferUtils.feedbackVertexStride, ShaderPool.particleFeedbackShader);
38411
+ }
38412
+ var _proto = ParticleTransformFeedbackSimulator.prototype;
38413
+ /**
38414
+ * Resize feedback buffers.
38415
+ * Saves pre-resize buffers internally for subsequent `copyOldBufferData` / `destroyOldBuffers` calls.
38416
+ * @param particleCount - Number of particles to allocate
38417
+ * @param instanceBinding - New instance vertex buffer binding
38418
+ */ _proto.resize = function resize(particleCount, instanceBinding) {
38419
+ var _this__simulator_readBinding, _this__simulator_writeBinding;
38420
+ this._oldReadBuffer = (_this__simulator_readBinding = this._simulator.readBinding) == null ? void 0 : _this__simulator_readBinding.buffer;
38421
+ this._oldWriteBuffer = (_this__simulator_writeBinding = this._simulator.writeBinding) == null ? void 0 : _this__simulator_writeBinding.buffer;
38422
+ this._simulator.resize(particleCount);
38423
+ this._instanceBinding = instanceBinding;
38424
+ };
38425
+ /**
38426
+ * Write initial position and velocity for a newly emitted particle.
38427
+ */ _proto.writeParticleData = function writeParticleData(index, position, vx, vy, vz) {
38428
+ var data = this._particleInitData;
38429
+ data[0] = position.x;
38430
+ data[1] = position.y;
38431
+ data[2] = position.z;
38432
+ data[3] = vx;
38433
+ data[4] = vy;
38434
+ data[5] = vz;
38435
+ var simulator = this._simulator;
38436
+ var byteOffset = index * ParticleBufferUtils.feedbackVertexStride;
38437
+ simulator.readBinding.buffer.setData(data, byteOffset);
38438
+ simulator.writeBinding.buffer.setData(data, byteOffset);
38439
+ };
38440
+ /**
38441
+ * Copy data from pre-resize buffers to current buffers.
38442
+ * Must be called after `resize` which saves the old buffers.
38443
+ */ _proto.copyOldBufferData = function copyOldBufferData(srcByteOffset, dstByteOffset, byteLength) {
38444
+ this._simulator.readBinding.buffer.copyFromBuffer(this._oldReadBuffer, srcByteOffset, dstByteOffset, byteLength);
38445
+ this._simulator.writeBinding.buffer.copyFromBuffer(this._oldWriteBuffer, srcByteOffset, dstByteOffset, byteLength);
38446
+ };
38447
+ /**
38448
+ * Destroy pre-resize buffers saved during `resize`.
38449
+ */ _proto.destroyOldBuffers = function destroyOldBuffers() {
38450
+ var _this__oldReadBuffer, _this__oldWriteBuffer;
38451
+ (_this__oldReadBuffer = this._oldReadBuffer) == null ? void 0 : _this__oldReadBuffer.destroy();
38452
+ (_this__oldWriteBuffer = this._oldWriteBuffer) == null ? void 0 : _this__oldWriteBuffer.destroy();
38453
+ this._oldReadBuffer = null;
38454
+ this._oldWriteBuffer = null;
38455
+ };
38456
+ /**
38457
+ * Run one simulation step.
38458
+ * @param shaderData - Shader data with current macros and uniforms
38459
+ * @param particleCount - Total particle slot count
38460
+ * @param firstActive - First active particle index in ring buffer
38461
+ * @param firstFree - First free particle index in ring buffer
38462
+ * @param deltaTime - Frame delta time
38463
+ */ _proto.update = function update(shaderData, particleCount, firstActive, firstFree, deltaTime) {
38464
+ if (firstActive === firstFree) return;
38465
+ shaderData.setFloat(ParticleTransformFeedbackSimulator._deltaTimeProperty, deltaTime);
38466
+ if (!this._simulator.beginUpdate(shaderData, ParticleBufferUtils.feedbackVertexElements, this._instanceBinding, ParticleBufferUtils.feedbackInstanceElements)) return;
38467
+ if (firstActive < firstFree) {
38468
+ this._simulator.draw(MeshTopology.Points, firstActive, firstFree - firstActive);
38469
+ } else {
38470
+ this._simulator.draw(MeshTopology.Points, firstActive, particleCount - firstActive);
38471
+ if (firstFree > 0) {
38472
+ this._simulator.draw(MeshTopology.Points, 0, firstFree);
38473
+ }
38474
+ }
38475
+ this._simulator.endUpdate();
38476
+ };
38477
+ _proto.destroy = function destroy() {
38478
+ var _this__simulator;
38479
+ (_this__simulator = this._simulator) == null ? void 0 : _this__simulator.destroy();
38480
+ };
38481
+ _create_class$2(ParticleTransformFeedbackSimulator, [
38482
+ {
38483
+ key: "readBinding",
38484
+ get: /**
38485
+ * The current read buffer binding for the render pass.
38486
+ */ function get() {
38487
+ return this._simulator.readBinding;
38488
+ }
38489
+ }
38490
+ ]);
38491
+ return ParticleTransformFeedbackSimulator;
38492
+ }();
38493
+ ParticleTransformFeedbackSimulator._deltaTimeProperty = ShaderProperty.getByName("renderer_DeltaTime");
38062
38494
  /**
38063
38495
  * Particle curve mode.
38064
38496
  */ var ParticleCurveMode = /*#__PURE__*/ function(ParticleCurveMode) {
@@ -38096,6 +38528,7 @@ __decorate$1([
38096
38528
  ParticleRandomSubSeeds[ParticleRandomSubSeeds["Shape"] = 2941263940] = "Shape";
38097
38529
  ParticleRandomSubSeeds[ParticleRandomSubSeeds["GravityModifier"] = 2759560269] = "GravityModifier";
38098
38530
  ParticleRandomSubSeeds[ParticleRandomSubSeeds["ForceOverLifetime"] = 3875246972] = "ForceOverLifetime";
38531
+ ParticleRandomSubSeeds[ParticleRandomSubSeeds["LimitVelocityOverLifetime"] = 3047300990] = "LimitVelocityOverLifetime";
38099
38532
  return ParticleRandomSubSeeds;
38100
38533
  }({});
38101
38534
  /**
@@ -39145,6 +39578,414 @@ __decorate$1([
39145
39578
  __decorate$1([
39146
39579
  deepClone
39147
39580
  ], ForceOverLifetimeModule.prototype, "_forceZ", void 0);
39581
+ /**
39582
+ * Limit velocity over lifetime module.
39583
+ */ var LimitVelocityOverLifetimeModule = /*#__PURE__*/ function(ParticleGeneratorModule) {
39584
+ _inherits$2(LimitVelocityOverLifetimeModule, ParticleGeneratorModule);
39585
+ function LimitVelocityOverLifetimeModule(generator) {
39586
+ var _this;
39587
+ _this = ParticleGeneratorModule.call(this, generator) || this, /** @internal */ _this._speedRand = new Rand(0, ParticleRandomSubSeeds.LimitVelocityOverLifetime), _this._speedMinConstantVec = new Vector3(), _this._speedMaxConstantVec = new Vector3(), _this._dragConstantVec = new Vector2(), _this._separateAxes = false, _this._dampen = 0, _this._multiplyDragByParticleSize = false, _this._multiplyDragByParticleVelocity = false, _this._space = ParticleSimulationSpace.Local;
39588
+ _this.speedX = new ParticleCompositeCurve(1);
39589
+ _this.speedY = new ParticleCompositeCurve(1);
39590
+ _this.speedZ = new ParticleCompositeCurve(1);
39591
+ _this.drag = new ParticleCompositeCurve(0);
39592
+ return _this;
39593
+ }
39594
+ var _proto = LimitVelocityOverLifetimeModule.prototype;
39595
+ /**
39596
+ * @internal
39597
+ */ _proto._isDragRandomMode = function _isDragRandomMode() {
39598
+ return this._drag.mode === ParticleCurveMode.TwoConstants || this._drag.mode === ParticleCurveMode.TwoCurves;
39599
+ };
39600
+ /**
39601
+ * @internal
39602
+ */ _proto._isSpeedRandomMode = function _isSpeedRandomMode() {
39603
+ if (this._separateAxes) {
39604
+ return (this._speedX.mode === ParticleCurveMode.TwoConstants || this._speedX.mode === ParticleCurveMode.TwoCurves) && (this._speedY.mode === ParticleCurveMode.TwoConstants || this._speedY.mode === ParticleCurveMode.TwoCurves) && (this._speedZ.mode === ParticleCurveMode.TwoConstants || this._speedZ.mode === ParticleCurveMode.TwoCurves);
39605
+ }
39606
+ return this._speedX.mode === ParticleCurveMode.TwoConstants || this._speedX.mode === ParticleCurveMode.TwoCurves;
39607
+ };
39608
+ /**
39609
+ * @internal
39610
+ */ _proto._updateShaderData = function _updateShaderData(shaderData) {
39611
+ var enabledModuleMacro = null;
39612
+ var separateAxesMacro = null;
39613
+ var speedModeMacro = null;
39614
+ var speedRandomMacro = null;
39615
+ var dragCurveMacro = null;
39616
+ var dragRandomMacro = null;
39617
+ var dragSizeMacro = null;
39618
+ var dragVelocityMacro = null;
39619
+ if (this.enabled) {
39620
+ enabledModuleMacro = LimitVelocityOverLifetimeModule._enabledMacro;
39621
+ // Dampen
39622
+ shaderData.setFloat(LimitVelocityOverLifetimeModule._dampenProperty, this._dampen);
39623
+ // Space
39624
+ shaderData.setInt(LimitVelocityOverLifetimeModule._spaceProperty, this._space);
39625
+ // Limit speed
39626
+ if (this._separateAxes) {
39627
+ separateAxesMacro = LimitVelocityOverLifetimeModule._separateAxesMacro;
39628
+ var result = this._uploadSeparateAxisSpeeds(shaderData);
39629
+ speedModeMacro = result.modeMacro;
39630
+ speedRandomMacro = result.randomMacro;
39631
+ } else {
39632
+ var result1 = this._uploadScalarSpeed(shaderData);
39633
+ speedModeMacro = result1.modeMacro;
39634
+ speedRandomMacro = result1.randomMacro;
39635
+ }
39636
+ // Drag
39637
+ var dragResult = this._uploadDrag(shaderData);
39638
+ dragCurveMacro = dragResult.curveMacro;
39639
+ dragRandomMacro = dragResult.randomMacro;
39640
+ // Drag modifiers
39641
+ if (this._multiplyDragByParticleSize) {
39642
+ dragSizeMacro = LimitVelocityOverLifetimeModule._multiplyDragBySizeMacro;
39643
+ }
39644
+ if (this._multiplyDragByParticleVelocity) {
39645
+ dragVelocityMacro = LimitVelocityOverLifetimeModule._multiplyDragByVelocityMacro;
39646
+ }
39647
+ }
39648
+ this._enabledModuleMacro = this._enableMacro(shaderData, this._enabledModuleMacro, enabledModuleMacro);
39649
+ this._separateAxesCachedMacro = this._enableMacro(shaderData, this._separateAxesCachedMacro, separateAxesMacro);
39650
+ this._speedModeMacro = this._enableMacro(shaderData, this._speedModeMacro, speedModeMacro);
39651
+ this._speedRandomMacro = this._enableMacro(shaderData, this._speedRandomMacro, speedRandomMacro);
39652
+ this._dragCurveCachedMacro = this._enableMacro(shaderData, this._dragCurveCachedMacro, dragCurveMacro);
39653
+ this._dragRandomCachedMacro = this._enableMacro(shaderData, this._dragRandomCachedMacro, dragRandomMacro);
39654
+ this._dragSizeMacro = this._enableMacro(shaderData, this._dragSizeMacro, dragSizeMacro);
39655
+ this._dragVelocityMacro = this._enableMacro(shaderData, this._dragVelocityMacro, dragVelocityMacro);
39656
+ };
39657
+ /**
39658
+ * @internal
39659
+ */ _proto._resetRandomSeed = function _resetRandomSeed(seed) {
39660
+ this._speedRand.reset(seed, ParticleRandomSubSeeds.LimitVelocityOverLifetime);
39661
+ };
39662
+ _proto._uploadScalarSpeed = function _uploadScalarSpeed(shaderData) {
39663
+ var speedX = this._speedX;
39664
+ var modeMacro = null;
39665
+ var randomMacro = null;
39666
+ var isRandomCurveMode = speedX.mode === ParticleCurveMode.TwoCurves;
39667
+ if (isRandomCurveMode || speedX.mode === ParticleCurveMode.Curve) {
39668
+ shaderData.setFloatArray(LimitVelocityOverLifetimeModule._speedMaxCurveProperty, speedX.curveMax._getTypeArray());
39669
+ modeMacro = LimitVelocityOverLifetimeModule._speedCurveModeMacro;
39670
+ if (isRandomCurveMode) {
39671
+ shaderData.setFloatArray(LimitVelocityOverLifetimeModule._speedMinCurveProperty, speedX.curveMin._getTypeArray());
39672
+ randomMacro = LimitVelocityOverLifetimeModule._speedIsRandomMacro;
39673
+ }
39674
+ } else {
39675
+ shaderData.setFloat(LimitVelocityOverLifetimeModule._speedMaxConstProperty, speedX.constantMax);
39676
+ modeMacro = LimitVelocityOverLifetimeModule._speedConstantModeMacro;
39677
+ if (speedX.mode === ParticleCurveMode.TwoConstants) {
39678
+ shaderData.setFloat(LimitVelocityOverLifetimeModule._speedMinConstProperty, speedX.constantMin);
39679
+ randomMacro = LimitVelocityOverLifetimeModule._speedIsRandomMacro;
39680
+ }
39681
+ }
39682
+ return {
39683
+ modeMacro: modeMacro,
39684
+ randomMacro: randomMacro
39685
+ };
39686
+ };
39687
+ _proto._uploadSeparateAxisSpeeds = function _uploadSeparateAxisSpeeds(shaderData) {
39688
+ var speedX = this._speedX;
39689
+ var speedY = this._speedY;
39690
+ var speedZ = this._speedZ;
39691
+ var modeMacro = null;
39692
+ var randomMacro = null;
39693
+ var isRandomCurveMode = speedX.mode === ParticleCurveMode.TwoCurves && speedY.mode === ParticleCurveMode.TwoCurves && speedZ.mode === ParticleCurveMode.TwoCurves;
39694
+ if (isRandomCurveMode || speedX.mode === ParticleCurveMode.Curve && speedY.mode === ParticleCurveMode.Curve && speedZ.mode === ParticleCurveMode.Curve) {
39695
+ shaderData.setFloatArray(LimitVelocityOverLifetimeModule._speedXMaxCurveProperty, speedX.curveMax._getTypeArray());
39696
+ shaderData.setFloatArray(LimitVelocityOverLifetimeModule._speedYMaxCurveProperty, speedY.curveMax._getTypeArray());
39697
+ shaderData.setFloatArray(LimitVelocityOverLifetimeModule._speedZMaxCurveProperty, speedZ.curveMax._getTypeArray());
39698
+ modeMacro = LimitVelocityOverLifetimeModule._speedCurveModeMacro;
39699
+ if (isRandomCurveMode) {
39700
+ shaderData.setFloatArray(LimitVelocityOverLifetimeModule._speedXMinCurveProperty, speedX.curveMin._getTypeArray());
39701
+ shaderData.setFloatArray(LimitVelocityOverLifetimeModule._speedYMinCurveProperty, speedY.curveMin._getTypeArray());
39702
+ shaderData.setFloatArray(LimitVelocityOverLifetimeModule._speedZMinCurveProperty, speedZ.curveMin._getTypeArray());
39703
+ randomMacro = LimitVelocityOverLifetimeModule._speedIsRandomMacro;
39704
+ }
39705
+ } else {
39706
+ var constantMax = this._speedMaxConstantVec;
39707
+ constantMax.set(speedX.constantMax, speedY.constantMax, speedZ.constantMax);
39708
+ shaderData.setVector3(LimitVelocityOverLifetimeModule._speedMaxConstVecProperty, constantMax);
39709
+ modeMacro = LimitVelocityOverLifetimeModule._speedConstantModeMacro;
39710
+ if (speedX.mode === ParticleCurveMode.TwoConstants && speedY.mode === ParticleCurveMode.TwoConstants && speedZ.mode === ParticleCurveMode.TwoConstants) {
39711
+ var constantMin = this._speedMinConstantVec;
39712
+ constantMin.set(speedX.constantMin, speedY.constantMin, speedZ.constantMin);
39713
+ shaderData.setVector3(LimitVelocityOverLifetimeModule._speedMinConstVecProperty, constantMin);
39714
+ randomMacro = LimitVelocityOverLifetimeModule._speedIsRandomMacro;
39715
+ }
39716
+ }
39717
+ return {
39718
+ modeMacro: modeMacro,
39719
+ randomMacro: randomMacro
39720
+ };
39721
+ };
39722
+ _proto._uploadDrag = function _uploadDrag(shaderData) {
39723
+ var drag = this._drag;
39724
+ var curveMacro = null;
39725
+ var randomMacro = null;
39726
+ var isRandomCurveMode = drag.mode === ParticleCurveMode.TwoCurves;
39727
+ if (isRandomCurveMode || drag.mode === ParticleCurveMode.Curve) {
39728
+ shaderData.setFloatArray(LimitVelocityOverLifetimeModule._dragMaxCurveProperty, drag.curveMax._getTypeArray());
39729
+ curveMacro = LimitVelocityOverLifetimeModule._dragCurveModeMacro;
39730
+ if (isRandomCurveMode) {
39731
+ shaderData.setFloatArray(LimitVelocityOverLifetimeModule._dragMinCurveProperty, drag.curveMin._getTypeArray());
39732
+ randomMacro = LimitVelocityOverLifetimeModule._dragIsRandomMacro;
39733
+ }
39734
+ } else {
39735
+ var dragVec = this._dragConstantVec;
39736
+ if (drag.mode === ParticleCurveMode.TwoConstants) {
39737
+ dragVec.set(drag.constantMin, drag.constantMax);
39738
+ } else {
39739
+ dragVec.set(drag.constantMax, drag.constantMax);
39740
+ }
39741
+ shaderData.setVector2(LimitVelocityOverLifetimeModule._dragConstantProperty, dragVec);
39742
+ }
39743
+ return {
39744
+ curveMacro: curveMacro,
39745
+ randomMacro: randomMacro
39746
+ };
39747
+ };
39748
+ _create_class$2(LimitVelocityOverLifetimeModule, [
39749
+ {
39750
+ key: "separateAxes",
39751
+ get: /**
39752
+ * Whether to limit velocity on each axis separately.
39753
+ */ function get() {
39754
+ return this._separateAxes;
39755
+ },
39756
+ set: function set(value) {
39757
+ if (value !== this._separateAxes) {
39758
+ this._separateAxes = value;
39759
+ this._generator._renderer._onGeneratorParamsChanged();
39760
+ }
39761
+ }
39762
+ },
39763
+ {
39764
+ key: "speed",
39765
+ get: /**
39766
+ * Speed limit when separateAxes is false.
39767
+ */ function get() {
39768
+ return this._speedX;
39769
+ },
39770
+ set: function set(value) {
39771
+ this.speedX = value;
39772
+ }
39773
+ },
39774
+ {
39775
+ key: "speedX",
39776
+ get: /**
39777
+ * Speed limit for the x-axis (or overall limit when separateAxes is false).
39778
+ */ function get() {
39779
+ return this._speedX;
39780
+ },
39781
+ set: function set(value) {
39782
+ var lastValue = this._speedX;
39783
+ if (value !== lastValue) {
39784
+ this._speedX = value;
39785
+ this._onCompositeCurveChange(lastValue, value);
39786
+ }
39787
+ }
39788
+ },
39789
+ {
39790
+ key: "speedY",
39791
+ get: /**
39792
+ * Speed limit for the y-axis.
39793
+ */ function get() {
39794
+ return this._speedY;
39795
+ },
39796
+ set: function set(value) {
39797
+ var lastValue = this._speedY;
39798
+ if (value !== lastValue) {
39799
+ this._speedY = value;
39800
+ this._onCompositeCurveChange(lastValue, value);
39801
+ }
39802
+ }
39803
+ },
39804
+ {
39805
+ key: "speedZ",
39806
+ get: /**
39807
+ * Speed limit for the z-axis.
39808
+ */ function get() {
39809
+ return this._speedZ;
39810
+ },
39811
+ set: function set(value) {
39812
+ var lastValue = this._speedZ;
39813
+ if (value !== lastValue) {
39814
+ this._speedZ = value;
39815
+ this._onCompositeCurveChange(lastValue, value);
39816
+ }
39817
+ }
39818
+ },
39819
+ {
39820
+ key: "dampen",
39821
+ get: /**
39822
+ * Controls how much the velocity is dampened when it exceeds the limit.
39823
+ * @remarks Value is clamped to [0, 1]. 0 means no damping, 1 means full damping.
39824
+ */ function get() {
39825
+ return this._dampen;
39826
+ },
39827
+ set: function set(value) {
39828
+ value = Math.max(0, Math.min(1, value));
39829
+ if (value !== this._dampen) {
39830
+ this._dampen = value;
39831
+ this._generator._renderer._onGeneratorParamsChanged();
39832
+ }
39833
+ }
39834
+ },
39835
+ {
39836
+ key: "drag",
39837
+ get: /**
39838
+ * Controls the amount of drag applied to particle velocities.
39839
+ */ function get() {
39840
+ return this._drag;
39841
+ },
39842
+ set: function set(value) {
39843
+ var lastValue = this._drag;
39844
+ if (value !== lastValue) {
39845
+ this._drag = value;
39846
+ this._onCompositeCurveChange(lastValue, value);
39847
+ }
39848
+ }
39849
+ },
39850
+ {
39851
+ key: "multiplyDragByParticleSize",
39852
+ get: /**
39853
+ * Adjust the amount of drag based on particle sizes.
39854
+ */ function get() {
39855
+ return this._multiplyDragByParticleSize;
39856
+ },
39857
+ set: function set(value) {
39858
+ if (value !== this._multiplyDragByParticleSize) {
39859
+ this._multiplyDragByParticleSize = value;
39860
+ this._generator._renderer._onGeneratorParamsChanged();
39861
+ }
39862
+ }
39863
+ },
39864
+ {
39865
+ key: "multiplyDragByParticleVelocity",
39866
+ get: /**
39867
+ * Adjust the amount of drag based on particle speeds.
39868
+ */ function get() {
39869
+ return this._multiplyDragByParticleVelocity;
39870
+ },
39871
+ set: function set(value) {
39872
+ if (value !== this._multiplyDragByParticleVelocity) {
39873
+ this._multiplyDragByParticleVelocity = value;
39874
+ this._generator._renderer._onGeneratorParamsChanged();
39875
+ }
39876
+ }
39877
+ },
39878
+ {
39879
+ key: "space",
39880
+ get: /**
39881
+ * Specifies if the velocity limits are in local space or world space.
39882
+ * @remarks Only takes effect when 'separateAxes' is enabled.
39883
+ */ function get() {
39884
+ return this._space;
39885
+ },
39886
+ set: function set(value) {
39887
+ if (value !== this._space) {
39888
+ this._space = value;
39889
+ this._generator._renderer._onGeneratorParamsChanged();
39890
+ }
39891
+ }
39892
+ },
39893
+ {
39894
+ key: "enabled",
39895
+ get: /**
39896
+ * Specifies whether the module is enabled.
39897
+ * @remarks This module requires WebGL2, On WebGL1, enabling will be silently ignored.
39898
+ */ function get() {
39899
+ return this._enabled;
39900
+ },
39901
+ set: function set(value) {
39902
+ if (value !== this._enabled) {
39903
+ if (value && !this._generator._renderer.engine._hardwareRenderer.isWebGL2) {
39904
+ return;
39905
+ }
39906
+ this._enabled = value;
39907
+ this._generator._setTransformFeedback(value);
39908
+ this._generator._renderer._onGeneratorParamsChanged();
39909
+ }
39910
+ }
39911
+ }
39912
+ ]);
39913
+ return LimitVelocityOverLifetimeModule;
39914
+ }(ParticleGeneratorModule);
39915
+ LimitVelocityOverLifetimeModule._enabledMacro = ShaderMacro.getByName("RENDERER_LVL_MODULE_ENABLED");
39916
+ LimitVelocityOverLifetimeModule._separateAxesMacro = ShaderMacro.getByName("RENDERER_LVL_SEPARATE_AXES");
39917
+ LimitVelocityOverLifetimeModule._speedConstantModeMacro = ShaderMacro.getByName("RENDERER_LVL_SPEED_CONSTANT_MODE");
39918
+ LimitVelocityOverLifetimeModule._speedCurveModeMacro = ShaderMacro.getByName("RENDERER_LVL_SPEED_CURVE_MODE");
39919
+ LimitVelocityOverLifetimeModule._speedIsRandomMacro = ShaderMacro.getByName("RENDERER_LVL_SPEED_IS_RANDOM_TWO");
39920
+ LimitVelocityOverLifetimeModule._dragCurveModeMacro = ShaderMacro.getByName("RENDERER_LVL_DRAG_CURVE_MODE");
39921
+ LimitVelocityOverLifetimeModule._dragIsRandomMacro = ShaderMacro.getByName("RENDERER_LVL_DRAG_IS_RANDOM_TWO");
39922
+ LimitVelocityOverLifetimeModule._multiplyDragBySizeMacro = ShaderMacro.getByName("RENDERER_LVL_DRAG_MULTIPLY_SIZE");
39923
+ LimitVelocityOverLifetimeModule._multiplyDragByVelocityMacro = ShaderMacro.getByName("RENDERER_LVL_DRAG_MULTIPLY_VELOCITY");
39924
+ LimitVelocityOverLifetimeModule._speedMaxConstProperty = ShaderProperty.getByName("renderer_LVLSpeedMaxConst");
39925
+ LimitVelocityOverLifetimeModule._speedMinConstProperty = ShaderProperty.getByName("renderer_LVLSpeedMinConst");
39926
+ LimitVelocityOverLifetimeModule._speedMaxCurveProperty = ShaderProperty.getByName("renderer_LVLSpeedMaxCurve");
39927
+ LimitVelocityOverLifetimeModule._speedMinCurveProperty = ShaderProperty.getByName("renderer_LVLSpeedMinCurve");
39928
+ LimitVelocityOverLifetimeModule._speedMaxConstVecProperty = ShaderProperty.getByName("renderer_LVLSpeedMaxConstVector");
39929
+ LimitVelocityOverLifetimeModule._speedMinConstVecProperty = ShaderProperty.getByName("renderer_LVLSpeedMinConstVector");
39930
+ LimitVelocityOverLifetimeModule._speedXMaxCurveProperty = ShaderProperty.getByName("renderer_LVLSpeedXMaxCurve");
39931
+ LimitVelocityOverLifetimeModule._speedXMinCurveProperty = ShaderProperty.getByName("renderer_LVLSpeedXMinCurve");
39932
+ LimitVelocityOverLifetimeModule._speedYMaxCurveProperty = ShaderProperty.getByName("renderer_LVLSpeedYMaxCurve");
39933
+ LimitVelocityOverLifetimeModule._speedYMinCurveProperty = ShaderProperty.getByName("renderer_LVLSpeedYMinCurve");
39934
+ LimitVelocityOverLifetimeModule._speedZMaxCurveProperty = ShaderProperty.getByName("renderer_LVLSpeedZMaxCurve");
39935
+ LimitVelocityOverLifetimeModule._speedZMinCurveProperty = ShaderProperty.getByName("renderer_LVLSpeedZMinCurve");
39936
+ LimitVelocityOverLifetimeModule._dampenProperty = ShaderProperty.getByName("renderer_LVLDampen");
39937
+ LimitVelocityOverLifetimeModule._dragConstantProperty = ShaderProperty.getByName("renderer_LVLDragConstant");
39938
+ LimitVelocityOverLifetimeModule._dragMaxCurveProperty = ShaderProperty.getByName("renderer_LVLDragMaxCurve");
39939
+ LimitVelocityOverLifetimeModule._dragMinCurveProperty = ShaderProperty.getByName("renderer_LVLDragMinCurve");
39940
+ LimitVelocityOverLifetimeModule._spaceProperty = ShaderProperty.getByName("renderer_LVLSpace");
39941
+ __decorate$1([
39942
+ ignoreClone
39943
+ ], LimitVelocityOverLifetimeModule.prototype, "_speedRand", void 0);
39944
+ __decorate$1([
39945
+ ignoreClone
39946
+ ], LimitVelocityOverLifetimeModule.prototype, "_speedMinConstantVec", void 0);
39947
+ __decorate$1([
39948
+ ignoreClone
39949
+ ], LimitVelocityOverLifetimeModule.prototype, "_speedMaxConstantVec", void 0);
39950
+ __decorate$1([
39951
+ ignoreClone
39952
+ ], LimitVelocityOverLifetimeModule.prototype, "_dragConstantVec", void 0);
39953
+ __decorate$1([
39954
+ ignoreClone
39955
+ ], LimitVelocityOverLifetimeModule.prototype, "_enabledModuleMacro", void 0);
39956
+ __decorate$1([
39957
+ ignoreClone
39958
+ ], LimitVelocityOverLifetimeModule.prototype, "_separateAxesCachedMacro", void 0);
39959
+ __decorate$1([
39960
+ ignoreClone
39961
+ ], LimitVelocityOverLifetimeModule.prototype, "_speedModeMacro", void 0);
39962
+ __decorate$1([
39963
+ ignoreClone
39964
+ ], LimitVelocityOverLifetimeModule.prototype, "_speedRandomMacro", void 0);
39965
+ __decorate$1([
39966
+ ignoreClone
39967
+ ], LimitVelocityOverLifetimeModule.prototype, "_dragCurveCachedMacro", void 0);
39968
+ __decorate$1([
39969
+ ignoreClone
39970
+ ], LimitVelocityOverLifetimeModule.prototype, "_dragRandomCachedMacro", void 0);
39971
+ __decorate$1([
39972
+ ignoreClone
39973
+ ], LimitVelocityOverLifetimeModule.prototype, "_dragSizeMacro", void 0);
39974
+ __decorate$1([
39975
+ ignoreClone
39976
+ ], LimitVelocityOverLifetimeModule.prototype, "_dragVelocityMacro", void 0);
39977
+ __decorate$1([
39978
+ deepClone
39979
+ ], LimitVelocityOverLifetimeModule.prototype, "_speedX", void 0);
39980
+ __decorate$1([
39981
+ deepClone
39982
+ ], LimitVelocityOverLifetimeModule.prototype, "_speedY", void 0);
39983
+ __decorate$1([
39984
+ deepClone
39985
+ ], LimitVelocityOverLifetimeModule.prototype, "_speedZ", void 0);
39986
+ __decorate$1([
39987
+ deepClone
39988
+ ], LimitVelocityOverLifetimeModule.prototype, "_drag", void 0);
39148
39989
  /**
39149
39990
  * Control how Particle Generator apply transform scale.
39150
39991
  */ var ParticleScaleMode = /*#__PURE__*/ function(ParticleScaleMode) {
@@ -40186,6 +41027,8 @@ __decorate$1([
40186
41027
  /** @internal */ this._firstRetiredElement = 0;
40187
41028
  /** @internal */ this._vertexBufferBindings = new Array();
40188
41029
  /** @internal */ this._subPrimitive = new SubMesh(0, 0, MeshTopology.Triangles);
41030
+ /** @internal */ this._useTransformFeedback = false;
41031
+ /** @internal */ this._feedbackBindingIndex = -1;
40189
41032
  this._isPlaying = false;
40190
41033
  this._instanceBufferResized = false;
40191
41034
  this._waitProcessRetiredElementCount = 0;
@@ -40204,6 +41047,7 @@ __decorate$1([
40204
41047
  this.velocityOverLifetime = new VelocityOverLifetimeModule(this);
40205
41048
  this.forceOverLifetime = new ForceOverLifetimeModule(this);
40206
41049
  this.sizeOverLifetime = new SizeOverLifetimeModule(this);
41050
+ this.limitVelocityOverLifetime = new LimitVelocityOverLifetimeModule(this);
40207
41051
  this.emission.enabled = true;
40208
41052
  }
40209
41053
  var _proto = ParticleGenerator.prototype;
@@ -40242,11 +41086,7 @@ __decorate$1([
40242
41086
  } else {
40243
41087
  this._isPlaying = false;
40244
41088
  if (stopMode === ParticleStopMode.StopEmittingAndClear) {
40245
- // Move the pointer to free immediately
40246
- var firstFreeElement = this._firstFreeElement;
40247
- this._firstRetiredElement = firstFreeElement;
40248
- this._firstActiveElement = firstFreeElement;
40249
- this._firstNewElement = firstFreeElement;
41089
+ this._clearActiveParticles();
40250
41090
  this._playTime = 0;
40251
41091
  this._firstActiveTransformedBoundingBox = this._firstFreeTransformedBoundingBox;
40252
41092
  this.emission._reset();
@@ -40330,6 +41170,16 @@ __decorate$1([
40330
41170
  this._isPlaying = false;
40331
41171
  }
40332
41172
  }
41173
+ // Retire all particles on device restore before bounds/volume bookkeeping
41174
+ var isContentLost = this._instanceVertexBufferBinding._buffer.isContentLost;
41175
+ if (isContentLost) {
41176
+ this._firstActiveElement = 0;
41177
+ this._firstNewElement = 0;
41178
+ this._firstFreeElement = 0;
41179
+ this._firstRetiredElement = 0;
41180
+ this._waitProcessRetiredElementCount = 0;
41181
+ this._firstActiveTransformedBoundingBox = this._firstFreeTransformedBoundingBox;
41182
+ }
40333
41183
  if (this.isAlive) {
40334
41184
  if (main.simulationSpace === ParticleSimulationSpace.World) {
40335
41185
  this._generateTransformedBounds();
@@ -40343,16 +41193,21 @@ __decorate$1([
40343
41193
  if (this.isAlive !== lastAlive) {
40344
41194
  this._renderer._onWorldVolumeChanged();
40345
41195
  }
40346
- // Add new particles to vertex buffer when has wait process retired element or new particle
40347
- //
40348
- // Another choice is just add new particles to vertex buffer and render all particles ignore the retired particle in shader, especially billboards
40349
- // But webgl don't support map buffer range, so this choice don't have performance advantage even less set data to GPU
40350
- if (this._firstNewElement != this._firstFreeElement || this._waitProcessRetiredElementCount > 0 || this._instanceBufferResized || this._instanceVertexBufferBinding._buffer.isContentLost) {
41196
+ if (this._firstNewElement != this._firstFreeElement || this._waitProcessRetiredElementCount > 0 || this._instanceBufferResized) {
40351
41197
  this._addActiveParticlesToVertexBuffer();
40352
41198
  }
40353
41199
  };
40354
41200
  /**
40355
41201
  * @internal
41202
+ * Run Transform Feedback simulation pass.
41203
+ */ _proto._updateFeedback = function _updateFeedback(shaderData, deltaTime) {
41204
+ this._feedbackSimulator.update(shaderData, this._currentParticleCount, this._firstActiveElement, this._firstFreeElement, deltaTime);
41205
+ // After swap, update the render pass buffer binding to point to the latest output.
41206
+ // VAO is disabled in TF mode so direct assignment is safe (no stale VAO issue).
41207
+ this._primitive.vertexBufferBindings[this._feedbackBindingIndex] = this._feedbackSimulator.readBinding;
41208
+ };
41209
+ /**
41210
+ * @internal
40356
41211
  */ _proto._reorganizeGeometryBuffers = function _reorganizeGeometryBuffers() {
40357
41212
  var _this = this, renderer = _this._renderer, primitive = _this._primitive, vertexBufferBindings = _this._vertexBufferBindings;
40358
41213
  var _renderer_engine = renderer.engine, particleUtils = _renderer_engine._particleBufferUtils;
@@ -40404,6 +41259,15 @@ __decorate$1([
40404
41259
  if (this._instanceVertexBufferBinding) {
40405
41260
  vertexBufferBindings.push(this._instanceVertexBufferBinding);
40406
41261
  }
41262
+ // Add feedback buffer binding for render pass
41263
+ if (this._useTransformFeedback) {
41264
+ this._feedbackBindingIndex = vertexBufferBindings.length;
41265
+ primitive.addVertexElement(new VertexElement(ParticleFeedbackVertexAttribute.Position, 0, VertexElementFormat.Vector3, this._feedbackBindingIndex, 1));
41266
+ primitive.addVertexElement(new VertexElement(ParticleFeedbackVertexAttribute.Velocity, 12, VertexElementFormat.Vector3, this._feedbackBindingIndex, 1));
41267
+ vertexBufferBindings.push(this._feedbackSimulator.readBinding);
41268
+ } else {
41269
+ this._feedbackBindingIndex = -1;
41270
+ }
40407
41271
  primitive.setVertexBufferBindings(vertexBufferBindings);
40408
41272
  };
40409
41273
  /**
@@ -40419,18 +41283,28 @@ __decorate$1([
40419
41283
  vertexInstanceBuffer.isGCIgnored = true;
40420
41284
  var vertexBufferBindings = this._primitive.vertexBufferBindings;
40421
41285
  var vertexBufferBinding = new VertexBufferBinding(vertexInstanceBuffer, stride);
40422
- var instanceVertices = new Float32Array(newByteLength / 4);
40423
41286
  var lastInstanceVertices = this._instanceVertices;
41287
+ var useFeedback = this._useTransformFeedback;
41288
+ var instanceVertices = new Float32Array(newByteLength / 4);
41289
+ if (useFeedback) {
41290
+ this._feedbackSimulator.resize(newParticleCount, vertexBufferBinding);
41291
+ }
40424
41292
  if (lastInstanceVertices) {
40425
- var floatStride = ParticleBufferUtils.instanceVertexFloatStride;
41293
+ var floatStride = ParticleBufferUtils.instanceVertexFloatStride, feedbackVertexStride = ParticleBufferUtils.feedbackVertexStride;
40426
41294
  var firstFreeElement = this._firstFreeElement;
40427
41295
  var firstRetiredElement = this._firstRetiredElement;
40428
41296
  if (isIncrease) {
41297
+ // Copy front segment [0, firstFreeElement)
40429
41298
  instanceVertices.set(new Float32Array(lastInstanceVertices.buffer, 0, firstFreeElement * floatStride));
41299
+ // Copy tail segment shifted by increaseCount
40430
41300
  var nextFreeElement = firstFreeElement + 1;
40431
- var freeEndOffset = (nextFreeElement + increaseCount) * floatStride;
40432
- instanceVertices.set(new Float32Array(lastInstanceVertices.buffer, nextFreeElement * floatStride * 4), freeEndOffset);
40433
- // Maintain expanded pointers
41301
+ var tailCount = this._currentParticleCount - nextFreeElement;
41302
+ var tailDstElement = nextFreeElement + increaseCount;
41303
+ instanceVertices.set(new Float32Array(lastInstanceVertices.buffer, nextFreeElement * floatStride * 4), tailDstElement * floatStride);
41304
+ if (useFeedback) {
41305
+ this._feedbackSimulator.copyOldBufferData(0, 0, firstFreeElement * feedbackVertexStride);
41306
+ this._feedbackSimulator.copyOldBufferData(nextFreeElement * feedbackVertexStride, tailDstElement * feedbackVertexStride, tailCount * feedbackVertexStride);
41307
+ }
40434
41308
  this._firstNewElement > firstFreeElement && (this._firstNewElement += increaseCount);
40435
41309
  this._firstActiveElement > firstFreeElement && (this._firstActiveElement += increaseCount);
40436
41310
  firstRetiredElement > firstFreeElement && (this._firstRetiredElement += increaseCount);
@@ -40439,7 +41313,6 @@ __decorate$1([
40439
41313
  if (firstRetiredElement <= firstFreeElement) {
40440
41314
  migrateCount = firstFreeElement - firstRetiredElement;
40441
41315
  bufferOffset = 0;
40442
- // Maintain expanded pointers
40443
41316
  this._firstFreeElement -= firstRetiredElement;
40444
41317
  this._firstNewElement -= firstRetiredElement;
40445
41318
  this._firstActiveElement -= firstRetiredElement;
@@ -40447,20 +41320,29 @@ __decorate$1([
40447
41320
  } else {
40448
41321
  migrateCount = this._currentParticleCount - firstRetiredElement;
40449
41322
  bufferOffset = firstFreeElement;
40450
- // Maintain expanded pointers
40451
41323
  this._firstNewElement > firstFreeElement && (this._firstNewElement -= firstFreeElement);
40452
41324
  this._firstActiveElement > firstFreeElement && (this._firstActiveElement -= firstFreeElement);
40453
41325
  firstRetiredElement > firstFreeElement && (this._firstRetiredElement -= firstFreeElement);
40454
41326
  }
40455
41327
  instanceVertices.set(new Float32Array(lastInstanceVertices.buffer, firstRetiredElement * floatStride * 4, migrateCount * floatStride), bufferOffset * floatStride);
41328
+ if (useFeedback) {
41329
+ this._feedbackSimulator.copyOldBufferData(firstRetiredElement * feedbackVertexStride, bufferOffset * feedbackVertexStride, migrateCount * feedbackVertexStride);
41330
+ }
41331
+ }
41332
+ if (useFeedback) {
41333
+ this._feedbackSimulator.destroyOldBuffers();
40456
41334
  }
40457
41335
  this._instanceBufferResized = true;
40458
41336
  }
40459
- // Instance buffer always at last
40460
- this._primitive.setVertexBufferBinding(lastInstanceVertices ? vertexBufferBindings.length - 1 : vertexBufferBindings.length, vertexBufferBinding);
41337
+ // Update instance buffer binding
41338
+ var instanceBindingIndex = lastInstanceVertices ? vertexBufferBindings.length - 1 - (useFeedback ? 1 : 0) : vertexBufferBindings.length;
41339
+ this._primitive.setVertexBufferBinding(instanceBindingIndex, vertexBufferBinding);
40461
41340
  this._instanceVertices = instanceVertices;
40462
41341
  this._instanceVertexBufferBinding = vertexBufferBinding;
40463
41342
  this._currentParticleCount = newParticleCount;
41343
+ if (useFeedback) {
41344
+ this._primitive.setVertexBufferBinding(this._feedbackBindingIndex, this._feedbackSimulator.readBinding);
41345
+ }
40464
41346
  };
40465
41347
  /**
40466
41348
  * @internal
@@ -40468,6 +41350,7 @@ __decorate$1([
40468
41350
  this.main._updateShaderData(shaderData);
40469
41351
  this.velocityOverLifetime._updateShaderData(shaderData);
40470
41352
  this.forceOverLifetime._updateShaderData(shaderData);
41353
+ this.limitVelocityOverLifetime._updateShaderData(shaderData);
40471
41354
  this.textureSheetAnimation._updateShaderData(shaderData);
40472
41355
  this.sizeOverLifetime._updateShaderData(shaderData);
40473
41356
  this.rotationOverLifetime._updateShaderData(shaderData);
@@ -40482,11 +41365,41 @@ __decorate$1([
40482
41365
  this.textureSheetAnimation._resetRandomSeed(seed);
40483
41366
  this.velocityOverLifetime._resetRandomSeed(seed);
40484
41367
  this.forceOverLifetime._resetRandomSeed(seed);
41368
+ this.limitVelocityOverLifetime._resetRandomSeed(seed);
40485
41369
  this.rotationOverLifetime._resetRandomSeed(seed);
40486
41370
  this.colorOverLifetime._resetRandomSeed(seed);
40487
41371
  };
40488
41372
  /**
40489
41373
  * @internal
41374
+ */ _proto._setTransformFeedback = function _setTransformFeedback(enabled) {
41375
+ this._useTransformFeedback = enabled;
41376
+ // Switching TF mode invalidates all active particle state: feedback buffers and instance
41377
+ // buffer layout are incompatible between the two paths. Clear rather than show a one-frame
41378
+ // jump; new particles will fill in naturally from the next emit cycle.
41379
+ this._clearActiveParticles();
41380
+ if (enabled) {
41381
+ if (!this._feedbackSimulator) {
41382
+ this._feedbackSimulator = new ParticleTransformFeedbackSimulator(this._renderer.engine);
41383
+ }
41384
+ var simulator = this._feedbackSimulator;
41385
+ var readBinding = simulator.readBinding;
41386
+ if (!readBinding || readBinding.buffer.byteLength !== this._currentParticleCount * ParticleBufferUtils.feedbackVertexStride) {
41387
+ simulator.resize(this._currentParticleCount, this._instanceVertexBufferBinding);
41388
+ simulator.destroyOldBuffers();
41389
+ } else {
41390
+ simulator._instanceBinding = this._instanceVertexBufferBinding;
41391
+ }
41392
+ this._renderer.shaderData.enableMacro(ParticleGenerator._transformFeedbackMacro);
41393
+ // Feedback buffer swaps every frame; VAO caching would bake stale buffer handles.
41394
+ this._primitive.enableVAO = false;
41395
+ } else {
41396
+ this._renderer.shaderData.disableMacro(ParticleGenerator._transformFeedbackMacro);
41397
+ this._primitive.enableVAO = true;
41398
+ }
41399
+ this._reorganizeGeometryBuffers();
41400
+ };
41401
+ /**
41402
+ * @internal
40490
41403
  */ _proto._getAliveParticleCount = function _getAliveParticleCount() {
40491
41404
  if (this._firstActiveElement <= this._firstFreeElement) {
40492
41405
  return this._firstFreeElement - this._firstActiveElement;
@@ -40513,10 +41426,19 @@ __decorate$1([
40513
41426
  };
40514
41427
  /**
40515
41428
  * @internal
41429
+ */ _proto._cloneTo = function _cloneTo(target) {
41430
+ if (target.limitVelocityOverLifetime.enabled) {
41431
+ target._setTransformFeedback(true);
41432
+ }
41433
+ };
41434
+ /**
41435
+ * @internal
40516
41436
  */ _proto._destroy = function _destroy() {
41437
+ var _this__feedbackSimulator;
40517
41438
  this._instanceVertexBufferBinding.buffer.destroy();
40518
41439
  this._primitive.destroy();
40519
41440
  this.emission._destroy();
41441
+ (_this__feedbackSimulator = this._feedbackSimulator) == null ? void 0 : _this__feedbackSimulator.destroy();
40520
41442
  };
40521
41443
  /**
40522
41444
  * @internal
@@ -40748,8 +41670,34 @@ __decorate$1([
40748
41670
  instanceVertices[offset + 39] = rand1.random();
40749
41671
  instanceVertices[offset + 40] = rand1.random();
40750
41672
  }
41673
+ var limitVelocityOverLifetime = this.limitVelocityOverLifetime;
41674
+ if (limitVelocityOverLifetime.enabled && (limitVelocityOverLifetime._isSpeedRandomMode() || limitVelocityOverLifetime._isDragRandomMode())) {
41675
+ instanceVertices[offset + 41] = limitVelocityOverLifetime._speedRand.random();
41676
+ }
41677
+ // Initialize feedback buffer for this particle
41678
+ if (this._useTransformFeedback) {
41679
+ this._addFeedbackParticle(firstFreeElement, position, direction, startSpeed, transform);
41680
+ }
40751
41681
  this._firstFreeElement = nextFreeElement;
40752
41682
  };
41683
+ _proto._addFeedbackParticle = function _addFeedbackParticle(index, shapePosition, direction, startSpeed, transform) {
41684
+ var position;
41685
+ if (this.main.simulationSpace === ParticleSimulationSpace.Local) {
41686
+ position = shapePosition;
41687
+ } else {
41688
+ position = ParticleGenerator._tempVector32;
41689
+ Vector3.transformByQuat(shapePosition, transform.worldRotationQuaternion, position);
41690
+ position.add(transform.worldPosition);
41691
+ }
41692
+ this._feedbackSimulator.writeParticleData(index, position, direction.x * startSpeed, direction.y * startSpeed, direction.z * startSpeed);
41693
+ };
41694
+ _proto._clearActiveParticles = function _clearActiveParticles() {
41695
+ var firstFreeElement = this._firstFreeElement;
41696
+ this._firstRetiredElement = firstFreeElement;
41697
+ this._firstActiveElement = firstFreeElement;
41698
+ this._firstNewElement = firstFreeElement;
41699
+ this._firstActiveTransformedBoundingBox = this._firstFreeTransformedBoundingBox;
41700
+ };
40753
41701
  _proto._retireActiveParticles = function _retireActiveParticles() {
40754
41702
  var engine = this._renderer.engine;
40755
41703
  var frameCount = engine.time.frameCount;
@@ -40793,16 +41741,19 @@ __decorate$1([
40793
41741
  return;
40794
41742
  }
40795
41743
  var byteStride = ParticleBufferUtils.instanceVertexStride;
40796
- var start = firstActiveElement * byteStride;
40797
41744
  var instanceBuffer = this._instanceVertexBufferBinding.buffer;
40798
41745
  var dataBuffer = this._instanceVertices.buffer;
41746
+ // Feedback mode: upload in-place (indices match feedback buffer slots)
41747
+ // Non-feedback mode: compact to GPU offset 0
41748
+ var compact = !this._useTransformFeedback;
41749
+ var start = firstActiveElement * byteStride;
40799
41750
  if (firstActiveElement < firstFreeElement) {
40800
- instanceBuffer.setData(dataBuffer, 0, start, (firstFreeElement - firstActiveElement) * byteStride, SetDataOptions.Discard);
41751
+ instanceBuffer.setData(dataBuffer, compact ? 0 : start, start, (firstFreeElement - firstActiveElement) * byteStride, SetDataOptions.Discard);
40801
41752
  } else {
40802
- var firstSegmentCount = (this._currentParticleCount - firstActiveElement) * byteStride;
40803
- instanceBuffer.setData(dataBuffer, 0, start, firstSegmentCount, SetDataOptions.Discard);
41753
+ var firstSegmentSize = (this._currentParticleCount - firstActiveElement) * byteStride;
41754
+ instanceBuffer.setData(dataBuffer, compact ? 0 : start, start, firstSegmentSize, SetDataOptions.Discard);
40804
41755
  if (firstFreeElement > 0) {
40805
- instanceBuffer.setData(dataBuffer, firstSegmentCount, 0, firstFreeElement * byteStride);
41756
+ instanceBuffer.setData(dataBuffer, compact ? firstSegmentSize : 0, 0, firstFreeElement * byteStride);
40806
41757
  }
40807
41758
  }
40808
41759
  this._firstNewElement = firstFreeElement;
@@ -41020,11 +41971,13 @@ ParticleGenerator._tempVector21 = new Vector2();
41020
41971
  ParticleGenerator._tempVector22 = new Vector2();
41021
41972
  ParticleGenerator._tempVector30 = new Vector3();
41022
41973
  ParticleGenerator._tempVector31 = new Vector3();
41974
+ ParticleGenerator._tempVector32 = new Vector3();
41023
41975
  ParticleGenerator._tempMat = new Matrix();
41024
41976
  ParticleGenerator._tempColor0 = new Color();
41025
41977
  ParticleGenerator._tempParticleRenderers = new Array();
41026
41978
  ParticleGenerator._particleIncreaseCount = 128;
41027
41979
  ParticleGenerator._transformedBoundsIncreaseCount = 16;
41980
+ ParticleGenerator._transformFeedbackMacro = ShaderMacro.getByName("RENDERER_TRANSFORM_FEEDBACK");
41028
41981
  __decorate$1([
41029
41982
  deepClone
41030
41983
  ], ParticleGenerator.prototype, "main", void 0);
@@ -41037,6 +41990,9 @@ __decorate$1([
41037
41990
  __decorate$1([
41038
41991
  deepClone
41039
41992
  ], ParticleGenerator.prototype, "forceOverLifetime", void 0);
41993
+ __decorate$1([
41994
+ deepClone
41995
+ ], ParticleGenerator.prototype, "limitVelocityOverLifetime", void 0);
41040
41996
  __decorate$1([
41041
41997
  deepClone
41042
41998
  ], ParticleGenerator.prototype, "sizeOverLifetime", void 0);
@@ -41073,6 +42029,15 @@ __decorate$1([
41073
42029
  __decorate$1([
41074
42030
  ignoreClone
41075
42031
  ], ParticleGenerator.prototype, "_subPrimitive", void 0);
42032
+ __decorate$1([
42033
+ ignoreClone
42034
+ ], ParticleGenerator.prototype, "_feedbackSimulator", void 0);
42035
+ __decorate$1([
42036
+ ignoreClone
42037
+ ], ParticleGenerator.prototype, "_useTransformFeedback", void 0);
42038
+ __decorate$1([
42039
+ ignoreClone
42040
+ ], ParticleGenerator.prototype, "_feedbackBindingIndex", void 0);
41076
42041
  __decorate$1([
41077
42042
  ignoreClone
41078
42043
  ], ParticleGenerator.prototype, "_isPlaying", void 0);
@@ -43220,6 +44185,7 @@ var CoreObjects = /*#__PURE__*/Object.freeze({
43220
44185
  Layer: Layer,
43221
44186
  LayerPathMask: LayerPathMask,
43222
44187
  Light: Light,
44188
+ LimitVelocityOverLifetimeModule: LimitVelocityOverLifetimeModule,
43223
44189
  Loader: Loader,
43224
44190
  Logger: Logger,
43225
44191
  MSAASamples: MSAASamples,
@@ -43670,6 +44636,14 @@ var GLBuffer = /*#__PURE__*/ function() {
43670
44636
  throw "Buffer is write-only on WebGL1.0 platforms.";
43671
44637
  }
43672
44638
  };
44639
+ _proto.copyFromBuffer = function copyFromBuffer(srcBuffer, srcByteOffset, dstByteOffset, byteLength) {
44640
+ var gl = this._gl;
44641
+ gl.bindBuffer(gl.COPY_READ_BUFFER, srcBuffer._glBuffer);
44642
+ gl.bindBuffer(gl.COPY_WRITE_BUFFER, this._glBuffer);
44643
+ gl.copyBufferSubData(gl.COPY_READ_BUFFER, gl.COPY_WRITE_BUFFER, srcByteOffset, dstByteOffset, byteLength);
44644
+ gl.bindBuffer(gl.COPY_READ_BUFFER, null);
44645
+ gl.bindBuffer(gl.COPY_WRITE_BUFFER, null);
44646
+ };
43673
44647
  _proto.destroy = function destroy() {
43674
44648
  this._gl.deleteBuffer(this._glBuffer);
43675
44649
  this._gl = null;
@@ -45160,6 +46134,150 @@ var GLBuffer = /*#__PURE__*/ function() {
45160
46134
  };
45161
46135
  return GLTextureCube;
45162
46136
  }(GLTexture);
46137
+ /**
46138
+ * @internal
46139
+ * WebGL2 implementation of Transform Feedback.
46140
+ */ var GLTransformFeedback = /*#__PURE__*/ function() {
46141
+ function GLTransformFeedback(rhi) {
46142
+ var gl = rhi.gl;
46143
+ this._gl = gl;
46144
+ this._glTransformFeedback = gl.createTransformFeedback();
46145
+ }
46146
+ var _proto = GLTransformFeedback.prototype;
46147
+ _proto.bindBufferRange = function bindBufferRange(index, buffer, byteOffset, byteSize) {
46148
+ var gl = this._gl;
46149
+ gl.bindBufferRange(gl.TRANSFORM_FEEDBACK_BUFFER, index, buffer._glBuffer, byteOffset, byteSize);
46150
+ };
46151
+ _proto.unbindBuffer = function unbindBuffer(index) {
46152
+ var gl = this._gl;
46153
+ gl.bindBufferBase(gl.TRANSFORM_FEEDBACK_BUFFER, index, null);
46154
+ };
46155
+ _proto.begin = function begin(primitiveMode) {
46156
+ this._gl.beginTransformFeedback(primitiveMode);
46157
+ };
46158
+ _proto.end = function end() {
46159
+ this._gl.endTransformFeedback();
46160
+ };
46161
+ _proto.bind = function bind() {
46162
+ var gl = this._gl;
46163
+ gl.bindTransformFeedback(gl.TRANSFORM_FEEDBACK, this._glTransformFeedback);
46164
+ };
46165
+ _proto.unbind = function unbind() {
46166
+ var gl = this._gl;
46167
+ gl.bindTransformFeedback(gl.TRANSFORM_FEEDBACK, null);
46168
+ };
46169
+ _proto.destroy = function destroy() {
46170
+ if (this._glTransformFeedback) {
46171
+ this._gl.deleteTransformFeedback(this._glTransformFeedback);
46172
+ this._glTransformFeedback = null;
46173
+ }
46174
+ };
46175
+ return GLTransformFeedback;
46176
+ }();
46177
+ function _array_like_to_array$1(arr, len) {
46178
+ if (len == null || len > arr.length) len = arr.length;
46179
+ for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
46180
+ return arr2;
46181
+ }
46182
+ function _unsupported_iterable_to_array$1(o, minLen) {
46183
+ if (!o) return;
46184
+ if (typeof o === "string") return _array_like_to_array$1(o, minLen);
46185
+ var n = Object.prototype.toString.call(o).slice(8, -1);
46186
+ if (n === "Object" && o.constructor) n = o.constructor.name;
46187
+ if (n === "Map" || n === "Set") return Array.from(n);
46188
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array$1(o, minLen);
46189
+ }
46190
+ function _create_for_of_iterator_helper_loose$1(o, allowArrayLike) {
46191
+ var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
46192
+ if (it) return (it = it.call(o)).next.bind(it);
46193
+ // Fallback for engines without symbol support
46194
+ if (Array.isArray(o) || (it = _unsupported_iterable_to_array$1(o)) || allowArrayLike && o && typeof o.length === "number") {
46195
+ if (it) o = it;
46196
+ var i = 0;
46197
+ return function() {
46198
+ if (i >= o.length) return {
46199
+ done: true
46200
+ };
46201
+ return {
46202
+ done: false,
46203
+ value: o[i++]
46204
+ };
46205
+ };
46206
+ }
46207
+ throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
46208
+ }
46209
+ /**
46210
+ * @internal
46211
+ * WebGL2 implementation of Transform Feedback primitive.
46212
+ * Maintains two VAOs (one per read direction), auto-rebuilds when program changes.
46213
+ */ var GLTransformFeedbackPrimitive = /*#__PURE__*/ function() {
46214
+ function GLTransformFeedbackPrimitive(gl) {
46215
+ this._lastProgramId = -1;
46216
+ this._gl = gl;
46217
+ }
46218
+ var _proto = GLTransformFeedbackPrimitive.prototype;
46219
+ _proto.updateVertexLayout = function updateVertexLayout(program, readBinding, writeBinding, feedbackElements, inputBinding, inputElements) {
46220
+ if (program.id === this._lastProgramId) return;
46221
+ this._deleteVAOs();
46222
+ var attribs = program.attributeLocation;
46223
+ this._vaoA = this._createVAO(attribs, readBinding, feedbackElements, inputBinding, inputElements);
46224
+ this._vaoB = this._createVAO(attribs, writeBinding, feedbackElements, inputBinding, inputElements);
46225
+ this._lastProgramId = program.id;
46226
+ this._gl.bindVertexArray(null);
46227
+ };
46228
+ _proto.bind = function bind(readIsA) {
46229
+ this._gl.bindVertexArray(readIsA ? this._vaoA : this._vaoB);
46230
+ };
46231
+ _proto.unbind = function unbind() {
46232
+ this._gl.bindVertexArray(null);
46233
+ };
46234
+ _proto.draw = function draw(mode, first, count) {
46235
+ this._gl.drawArrays(mode, first, count);
46236
+ };
46237
+ _proto.invalidate = function invalidate() {
46238
+ this._deleteVAOs();
46239
+ };
46240
+ _proto.destroy = function destroy() {
46241
+ this._deleteVAOs();
46242
+ };
46243
+ _proto._deleteVAOs = function _deleteVAOs() {
46244
+ var gl = this._gl;
46245
+ if (this._vaoA) {
46246
+ gl.deleteVertexArray(this._vaoA);
46247
+ this._vaoA = null;
46248
+ }
46249
+ if (this._vaoB) {
46250
+ gl.deleteVertexArray(this._vaoB);
46251
+ this._vaoB = null;
46252
+ }
46253
+ this._lastProgramId = -1;
46254
+ };
46255
+ _proto._createVAO = function _createVAO(attribs, feedbackBinding, feedbackElements, inputBinding, inputElements) {
46256
+ var gl = this._gl;
46257
+ var vao = gl.createVertexArray();
46258
+ gl.bindVertexArray(vao);
46259
+ // @ts-ignore: Access internal _platformBuffer across packages
46260
+ gl.bindBuffer(gl.ARRAY_BUFFER, feedbackBinding.buffer._platformBuffer._glBuffer);
46261
+ this._bindElements(gl, attribs, feedbackElements, feedbackBinding.stride);
46262
+ // @ts-ignore: Access internal _platformBuffer across packages
46263
+ gl.bindBuffer(gl.ARRAY_BUFFER, inputBinding.buffer._platformBuffer._glBuffer);
46264
+ this._bindElements(gl, attribs, inputElements, inputBinding.stride);
46265
+ gl.bindBuffer(gl.ARRAY_BUFFER, null);
46266
+ return vao;
46267
+ };
46268
+ _proto._bindElements = function _bindElements(gl, attribs, elements, stride) {
46269
+ for(var _iterator = _create_for_of_iterator_helper_loose$1(elements), _step; !(_step = _iterator()).done;){
46270
+ var element = _step.value;
46271
+ var loc = attribs[element.attribute];
46272
+ if (loc !== undefined && loc !== -1) {
46273
+ var info = element._formatMetaInfo;
46274
+ gl.enableVertexAttribArray(loc);
46275
+ gl.vertexAttribPointer(loc, info.size, info.type, info.normalized, stride, element.offset);
46276
+ }
46277
+ }
46278
+ };
46279
+ return GLTransformFeedbackPrimitive;
46280
+ }();
45163
46281
  /**
45164
46282
  * WebGL mode.
45165
46283
  */ var WebGLMode = /*#__PURE__*/ function(WebGLMode) {
@@ -45281,6 +46399,37 @@ var GLBuffer = /*#__PURE__*/ function() {
45281
46399
  if (bufferUsage === void 0) bufferUsage = BufferUsage.Static;
45282
46400
  return new GLBuffer(this, type, byteLength, bufferUsage, data);
45283
46401
  };
46402
+ _proto.createPlatformTransformFeedback = function createPlatformTransformFeedback() {
46403
+ return new GLTransformFeedback(this);
46404
+ };
46405
+ _proto.createPlatformTransformFeedbackPrimitive = function createPlatformTransformFeedbackPrimitive() {
46406
+ return new GLTransformFeedbackPrimitive(this._gl);
46407
+ };
46408
+ /**
46409
+ * Enable GL_RASTERIZER_DISCARD (WebGL2 only).
46410
+ */ _proto.enableRasterizerDiscard = function enableRasterizerDiscard() {
46411
+ if (this._isWebGL2) {
46412
+ var gl = this._gl;
46413
+ gl.enable(gl.RASTERIZER_DISCARD);
46414
+ }
46415
+ };
46416
+ /**
46417
+ * Disable GL_RASTERIZER_DISCARD (WebGL2 only).
46418
+ */ _proto.disableRasterizerDiscard = function disableRasterizerDiscard() {
46419
+ if (this._isWebGL2) {
46420
+ var gl = this._gl;
46421
+ gl.disable(gl.RASTERIZER_DISCARD);
46422
+ }
46423
+ };
46424
+ /**
46425
+ * Invalidate the cached shader program state.
46426
+ * Call this after using a custom program (e.g., Transform Feedback) outside the engine's pipeline.
46427
+ */ _proto.invalidateShaderProgramState = function invalidateShaderProgramState() {
46428
+ if (this._currentBindShaderProgram) {
46429
+ this._gl.useProgram(null);
46430
+ this._currentBindShaderProgram = null;
46431
+ }
46432
+ };
45284
46433
  _proto.requireExtension = function requireExtension(ext) {
45285
46434
  return this._extensions.requireExtension(ext);
45286
46435
  };
@@ -52904,11 +54053,11 @@ EXT_texture_webp = __decorate([
52904
54053
  ], EXT_texture_webp);
52905
54054
 
52906
54055
  //@ts-ignore
52907
- var version = "2.0.0-alpha.16";
54056
+ var version = "2.0.0-alpha.18";
52908
54057
  console.log("Galacean Engine Version: " + version);
52909
54058
  for(var key in CoreObjects){
52910
54059
  Loader.registerClass(key, CoreObjects[key]);
52911
54060
  }
52912
54061
 
52913
- export { AccessorType, AmbientLight, AmbientOcclusion, AmbientOcclusionQuality, AnimationArrayCurve, AnimationBoolCurve, AnimationClip, AnimationClipCurveBinding, AnimationClipDecoder, AnimationColorCurve, AnimationCurve, AnimationEvent, AnimationFloatArrayCurve, AnimationFloatCurve, AnimationQuaternionCurve, AnimationRectCurve, AnimationRefCurve, AnimationStringCurve, AnimationVector2Curve, AnimationVector3Curve, AnimationVector4Curve, Animator, AnimatorCondition, AnimatorConditionMode, AnimatorController, AnimatorControllerLayer, AnimatorControllerParameter, AnimatorCullingMode, AnimatorLayerBlendingMode, AnimatorLayerMask, AnimatorState, AnimatorStateMachine, AnimatorStateTransition, AntiAliasing, AssetPromise, AssetType, AudioClip, AudioManager, AudioSource, Background, BackgroundMode, BackgroundTextureFillMode, BaseMaterial, BasicRenderPipeline, BatchUtils, BlendFactor, BlendMode, BlendOperation, BlendShape, BlendShapeFrame, BlendState, BlinnPhongMaterial, Blitter, BloomDownScaleMode, BloomEffect, BoolUpdateFlag, BoundingBox, BoundingFrustum, BoundingSphere, BoxColliderShape, BoxShape, Buffer, BufferAsset, BufferBindFlag, BufferInfo, BufferMesh, BufferReader, BufferUsage, BufferUtil, Burst, Camera, CameraClearFlags, CameraModifyFlags, CameraType$1 as CameraType, Canvas, CapsuleColliderShape, CharRenderInfo, CharacterController, CircleShape, ClearableObjectPool, CloneManager, CloneUtils, Collider, ColliderShape, ColliderShapeUpAxis, Collision, CollisionDetectionMode, CollisionUtil, Color, ColorOverLifetimeModule, ColorWriteMask, CompareFunction, Component, ConeEmitType, ConeShape, ContactPoint, ContainmentType, ContentRestorer, ControllerCollisionFlag, ControllerNonWalkableMode, CubeProbe, CullMode, CurveKey, DataType, DependentMode, DepthState, DepthTextureMode, DiffuseMode, DirectLight, DisorderedArray, Downsampling, DynamicCollider, DynamicColliderConstraints, EmissionModule, Engine, EngineObject, Entity, EntityModifyFlags, EventDispatcher, FileHeader, FinalPass, FixedJoint, FogMode, Font, FontStyle, FrustumFace, GLCapabilityType, GLCompressedTextureInternalFormat, GLTFAnimationParser, GLTFAnimatorControllerParser, GLTFBufferParser, GLTFBufferViewParser, GLTFEntityParser, GLTFExtensionMode, GLTFExtensionParser, GLTFLoader, GLTFMaterialParser, GLTFMeshParser, GLTFParser, GLTFParserContext, GLTFParserType, GLTFResource, GLTFSceneParser, GLTFSchemaParser, GLTFSkinParser, GLTFTextureParser, GLTFUtils, GLTFValidator, GradientAlphaKey, GradientColorKey, HDRDecoder, HemisphereShape, HierarchyParser, HingeJoint, HitResult, IndexBufferBinding, IndexFormat, InputManager, InterpolableValueType, InterpolationType, JSONAsset, Joint, JointLimits, JointMotor, KTX2Loader, KTX2TargetFormat, Keyframe, Keys, Layer, LayerPathMask, Light, Loader, Logger, MSAASamples, MainModule, Material, MaterialLoaderType, MathUtil, Matrix, Matrix3x3, Mesh, MeshColliderShape, MeshColliderShapeCookingFlag, MeshDecoder, MeshRenderer, MeshShape, MeshTopology, ModelMesh, OverflowMode, PBRMaterial, ParserContext, ParserType, ParticleCompositeCurve, ParticleCompositeGradient, ParticleCurve, ParticleCurveMode, ParticleGenerator, ParticleGradient, ParticleGradientMode, ParticleMaterial, ParticleRenderMode, ParticleRenderer, ParticleScaleMode, ParticleShapeArcMode, ParticleShapeType, ParticleSimulationSpace, ParticleStopMode, PhysicsMaterial, PhysicsMaterialCombineMode, PhysicsScene, PipelineStage, Plane, PlaneColliderShape, PlaneIntersectionType, Platform, PointLight, Pointer, PointerButton, PointerEventData, PointerEventEmitter, PointerPhase, PostProcess, PostProcessEffect, PostProcessEffectBoolParameter, PostProcessEffectColorParameter, PostProcessEffectEnumParameter, PostProcessEffectFloatParameter, PostProcessEffectParameter, PostProcessEffectTextureParameter, PostProcessEffectVector2Parameter, PostProcessEffectVector3Parameter, PostProcessEffectVector4Parameter, PostProcessManager, PostProcessPass, PostProcessPassEvent, PostProcessUberPass, PrefabResource, Primitive, PrimitiveMesh, Probe, Quaternion, Rand, RasterState, Ray, Rect, ReferResource, ReflectionParser, RefractionMode, RenderBufferDepthFormat, RenderFace, RenderQueue, RenderQueueFlags, RenderQueueType, RenderState, RenderStateElementKey, RenderTarget, RenderTargetBlendState, Renderer, RendererUpdateFlags, RenderingStatistics, ReplacementFailureStrategy, ResourceManager, ReturnableObjectPool, RotationOverLifetimeModule, SafeLoopArray, Scene, SceneManager, SceneParser, Script, SetDataOptions, Shader, ShaderData, ShaderDataGroup, ShaderFactory, ShaderLanguage, ShaderLib, ShaderMacro, ShaderMacroCollection, ShaderPass, ShaderProperty, ShaderPropertyType, ShaderTagKey, ShadowCascadesMode, ShadowResolution, ShadowType, Signal, SimpleSpriteAssembler, SizeOverLifetimeModule, Skin, SkinnedMeshRenderer, Sky, SkyBoxMaterial, SkyProceduralMaterial, SlicedSpriteAssembler, SpecularMode, SphereColliderShape, SphereShape, SphericalHarmonics3, SpotLight, SpringJoint, Sprite, SpriteAtlas, SpriteDrawMode, SpriteMask, SpriteMaskInteraction, SpriteMaskLayer, SpriteModifyFlags, SpriteRenderer, SpriteTileMode, StateMachineScript, StaticCollider, StencilOperation, StencilState, SubFont, SubMesh, SubPrimitive, SubShader, SunMode, SystemInfo, TextAsset, TextHorizontalAlignment, TextRenderer, TextUtils, TextVerticalAlignment, Texture, Texture2D, Texture2DArray, Texture2DDecoder, TextureCoordinate, TextureCube, TextureCubeFace, TextureDepthCompareFunction, TextureFilterMode, TextureFormat, TextureSheetAnimationModule, TextureUsage, TextureUtils, TextureWrapMode$1 as TextureWrapMode, TiledSpriteAssembler, Time, TonemappingEffect, TonemappingMode, TrailMaterial, TrailRenderer, TrailTextureMode, Transform, TransformModifyFlags, UnlitMaterial, Utils, Vector2, Vector3, Vector4, VelocityOverLifetimeModule, VertexAttribute, VertexBufferBinding, VertexElement, VertexElementFormat, WebCanvas, WebGLEngine, WebGLGraphicDevice, WebGLMode, WrapMode, XRManager, assignmentClone, decode, decoder, decoderMap, deepClone, dependentComponents, ignoreClone, parseSingleKTX, registerGLTFExtension, registerGLTFParser, registerPointerEventEmitter, request, resourceLoader, shallowClone, version };
54062
+ export { AccessorType, AmbientLight, AmbientOcclusion, AmbientOcclusionQuality, AnimationArrayCurve, AnimationBoolCurve, AnimationClip, AnimationClipCurveBinding, AnimationClipDecoder, AnimationColorCurve, AnimationCurve, AnimationEvent, AnimationFloatArrayCurve, AnimationFloatCurve, AnimationQuaternionCurve, AnimationRectCurve, AnimationRefCurve, AnimationStringCurve, AnimationVector2Curve, AnimationVector3Curve, AnimationVector4Curve, Animator, AnimatorCondition, AnimatorConditionMode, AnimatorController, AnimatorControllerLayer, AnimatorControllerParameter, AnimatorCullingMode, AnimatorLayerBlendingMode, AnimatorLayerMask, AnimatorState, AnimatorStateMachine, AnimatorStateTransition, AntiAliasing, AssetPromise, AssetType, AudioClip, AudioManager, AudioSource, Background, BackgroundMode, BackgroundTextureFillMode, BaseMaterial, BasicRenderPipeline, BatchUtils, BlendFactor, BlendMode, BlendOperation, BlendShape, BlendShapeFrame, BlendState, BlinnPhongMaterial, Blitter, BloomDownScaleMode, BloomEffect, BoolUpdateFlag, BoundingBox, BoundingFrustum, BoundingSphere, BoxColliderShape, BoxShape, Buffer, BufferAsset, BufferBindFlag, BufferInfo, BufferMesh, BufferReader, BufferUsage, BufferUtil, Burst, Camera, CameraClearFlags, CameraModifyFlags, CameraType$1 as CameraType, Canvas, CapsuleColliderShape, CharRenderInfo, CharacterController, CircleShape, ClearableObjectPool, CloneManager, CloneUtils, Collider, ColliderShape, ColliderShapeUpAxis, Collision, CollisionDetectionMode, CollisionUtil, Color, ColorOverLifetimeModule, ColorWriteMask, CompareFunction, Component, ConeEmitType, ConeShape, ContactPoint, ContainmentType, ContentRestorer, ControllerCollisionFlag, ControllerNonWalkableMode, CubeProbe, CullMode, CurveKey, DataType, DependentMode, DepthState, DepthTextureMode, DiffuseMode, DirectLight, DisorderedArray, Downsampling, DynamicCollider, DynamicColliderConstraints, EmissionModule, Engine, EngineObject, Entity, EntityModifyFlags, EventDispatcher, FileHeader, FinalPass, FixedJoint, FogMode, Font, FontStyle, FrustumFace, GLCapabilityType, GLCompressedTextureInternalFormat, GLTFAnimationParser, GLTFAnimatorControllerParser, GLTFBufferParser, GLTFBufferViewParser, GLTFEntityParser, GLTFExtensionMode, GLTFExtensionParser, GLTFLoader, GLTFMaterialParser, GLTFMeshParser, GLTFParser, GLTFParserContext, GLTFParserType, GLTFResource, GLTFSceneParser, GLTFSchemaParser, GLTFSkinParser, GLTFTextureParser, GLTFUtils, GLTFValidator, GradientAlphaKey, GradientColorKey, HDRDecoder, HemisphereShape, HierarchyParser, HingeJoint, HitResult, IndexBufferBinding, IndexFormat, InputManager, InterpolableValueType, InterpolationType, JSONAsset, Joint, JointLimits, JointMotor, KTX2Loader, KTX2TargetFormat, Keyframe, Keys, Layer, LayerPathMask, Light, LimitVelocityOverLifetimeModule, Loader, Logger, MSAASamples, MainModule, Material, MaterialLoaderType, MathUtil, Matrix, Matrix3x3, Mesh, MeshColliderShape, MeshColliderShapeCookingFlag, MeshDecoder, MeshRenderer, MeshShape, MeshTopology, ModelMesh, OverflowMode, PBRMaterial, ParserContext, ParserType, ParticleCompositeCurve, ParticleCompositeGradient, ParticleCurve, ParticleCurveMode, ParticleGenerator, ParticleGradient, ParticleGradientMode, ParticleMaterial, ParticleRenderMode, ParticleRenderer, ParticleScaleMode, ParticleShapeArcMode, ParticleShapeType, ParticleSimulationSpace, ParticleStopMode, PhysicsMaterial, PhysicsMaterialCombineMode, PhysicsScene, PipelineStage, Plane, PlaneColliderShape, PlaneIntersectionType, Platform, PointLight, Pointer, PointerButton, PointerEventData, PointerEventEmitter, PointerPhase, PostProcess, PostProcessEffect, PostProcessEffectBoolParameter, PostProcessEffectColorParameter, PostProcessEffectEnumParameter, PostProcessEffectFloatParameter, PostProcessEffectParameter, PostProcessEffectTextureParameter, PostProcessEffectVector2Parameter, PostProcessEffectVector3Parameter, PostProcessEffectVector4Parameter, PostProcessManager, PostProcessPass, PostProcessPassEvent, PostProcessUberPass, PrefabResource, Primitive, PrimitiveMesh, Probe, Quaternion, Rand, RasterState, Ray, Rect, ReferResource, ReflectionParser, RefractionMode, RenderBufferDepthFormat, RenderFace, RenderQueue, RenderQueueFlags, RenderQueueType, RenderState, RenderStateElementKey, RenderTarget, RenderTargetBlendState, Renderer, RendererUpdateFlags, RenderingStatistics, ReplacementFailureStrategy, ResourceManager, ReturnableObjectPool, RotationOverLifetimeModule, SafeLoopArray, Scene, SceneManager, SceneParser, Script, SetDataOptions, Shader, ShaderData, ShaderDataGroup, ShaderFactory, ShaderLanguage, ShaderLib, ShaderMacro, ShaderMacroCollection, ShaderPass, ShaderProperty, ShaderPropertyType, ShaderTagKey, ShadowCascadesMode, ShadowResolution, ShadowType, Signal, SimpleSpriteAssembler, SizeOverLifetimeModule, Skin, SkinnedMeshRenderer, Sky, SkyBoxMaterial, SkyProceduralMaterial, SlicedSpriteAssembler, SpecularMode, SphereColliderShape, SphereShape, SphericalHarmonics3, SpotLight, SpringJoint, Sprite, SpriteAtlas, SpriteDrawMode, SpriteMask, SpriteMaskInteraction, SpriteMaskLayer, SpriteModifyFlags, SpriteRenderer, SpriteTileMode, StateMachineScript, StaticCollider, StencilOperation, StencilState, SubFont, SubMesh, SubPrimitive, SubShader, SunMode, SystemInfo, TextAsset, TextHorizontalAlignment, TextRenderer, TextUtils, TextVerticalAlignment, Texture, Texture2D, Texture2DArray, Texture2DDecoder, TextureCoordinate, TextureCube, TextureCubeFace, TextureDepthCompareFunction, TextureFilterMode, TextureFormat, TextureSheetAnimationModule, TextureUsage, TextureUtils, TextureWrapMode$1 as TextureWrapMode, TiledSpriteAssembler, Time, TonemappingEffect, TonemappingMode, TrailMaterial, TrailRenderer, TrailTextureMode, Transform, TransformModifyFlags, UnlitMaterial, Utils, Vector2, Vector3, Vector4, VelocityOverLifetimeModule, VertexAttribute, VertexBufferBinding, VertexElement, VertexElementFormat, WebCanvas, WebGLEngine, WebGLGraphicDevice, WebGLMode, WrapMode, XRManager, assignmentClone, decode, decoder, decoderMap, deepClone, dependentComponents, ignoreClone, parseSingleKTX, registerGLTFExtension, registerGLTFParser, registerPointerEventEmitter, request, resourceLoader, shallowClone, version };
52914
54063
  //# sourceMappingURL=bundled.module.js.map