import './chunks.glsl'; export declare const vertexShader = "\n #include \n #include \n #include \n #include \n\n #include \n #include \n #include \n #include \n\n #include \n #include \n #include \n #include \n #include \n #include \n #include \n\t#include \n\n\tvarying vec2 vUv;\n\n void main() {\n\t\tvUv = uv;\n\n\t\t// Setup...\n\t\thighp float age = getAge();\n\t\thighp float alive = getAlive();\n\t\thighp float maxAge = getMaxAge();\n\t\thighp float positionInTime = (age / maxAge);\n\t\thighp float isAlive = when_gt( alive, 0.0 );\n\n\t\t#ifdef SHOULD_WIGGLE_PARTICLES\n\t\t float wiggleAmount = positionInTime * getWiggle();\n\t\t float wiggleSin = isAlive * sin( wiggleAmount );\n\t\t float wiggleCos = isAlive * cos( wiggleAmount );\n\t\t#endif\n\n\t\t// Forces\n // Get forces & position\n vec3 vel = getVelocity( age );\n\t\tvec3 accel = getAcceleration( age );\n\t\tvec3 force = vec3( 0.0 );\n\t\tvec3 pos = vec3( center );\n\n\t\tvec3 prev_vel = getVelocity( age - deltaTime);\n\t\tvec3 prev_accel = getAcceleration( age - deltaTime);\n\t\tvec3 prev_force = vec3( 0.0 );\n\t\tvec3 prev_pos = vec3( center );\n\n\t\thighp float prev_positionInTime = ((age - deltaTime) / maxAge);\n\n // Calculate the required drag to apply to the forces.\n\t\tfloat drag = 1.0 - (positionInTime * 0.5) * acceleration.w;\n\t\tfloat prev_drag = 1.0 - (prev_positionInTime * 0.5) * acceleration.w;\n\n // Integrate forces...\n force += vel;\n force *= drag;\n force += accel * age;\n pos += force;\n\n // Wiggly wiggly wiggle!\n\t\t#ifdef SHOULD_WIGGLE_PARTICLES\n\t\t pos.x += wiggleSin;\n\t\t pos.y += wiggleCos;\n\t\t pos.z += wiggleSin;\n\t\t#endif\n\n\t\t// Rotate the emitter around it's central point\n\t\t#ifdef SHOULD_ORBIT_PARTICLES\n\t\t\tpos = getOrbitPosition( pos, positionInTime );\n\t\t#endif\n\n\t\t// Appearance\n\t\t// Determine color and opacity for this particle\n\t\t#ifdef COLORIZE\n\t\t vec3 c = isAlive * getColorOverLifetime(\n\t\t positionInTime,\n\t\t unpackColor( color.x ),\n\t\t unpackColor( color.y ),\n\t\t unpackColor( color.z ),\n\t\t unpackColor( color.w )\n\t\t );\n\t\t#else\n\t\t vec3 c = vec3(1.0);\n\t\t#endif\n\n\t\tfloat o = isAlive * getFloatOverLifetime( positionInTime, opacity );\n\n\t\t// Assign color to vColor varying.\n\t\tvColor = vec4( c, o );\n\n\t\t// Determine angle\n\t\t// #ifdef SHOULD_ROTATE_TEXTURE\n\t\t// vAngle = isAlive * getFloatOverLifetime( positionInTime, angle );\n\t\t// #endif\n\n\t\t// If this particle is using a sprite-sheet as a texture, we'll have to figure out\n\t\t// what frame of the texture the particle is using at it's current position in time.\n\t\t// #ifdef SHOULD_CALCULATE_SPRITE\n\t\t// float framesX = textureAnimation.x;\n\t\t// float framesY = textureAnimation.y;\n\t\t// float loopCount = textureAnimation.w;\n\t\t// float totalFrames = textureAnimation.z;\n\t\t// float frameNumber = mod( (positionInTime * loopCount) * totalFrames, totalFrames );\n\t\t// float column = floor(mod( frameNumber, framesX ));\n\t\t// float row = floor( (frameNumber - column) / framesX );\n\t\t// float columnNorm = column / framesX;\n\t\t// float rowNorm = row / framesY;\n\t\t// vSpriteSheet.x = 1.0 / framesX;\n\t\t// vSpriteSheet.y = 1.0 / framesY;\n\t\t// vSpriteSheet.z = columnNorm;\n\t\t// vSpriteSheet.w = rowNorm;\n\t\t// #endif\n\n\t\thighp float particleSize = getFloatOverLifetime( positionInTime, size ) * isAlive;\n\t\tfloat particleRotationRadians = rotation[2] == 0.0 ? rotation[1] * positionInTime : rotation[1];\n\n\t\t#ifdef DIRECTIONAL_BILLBOARD\n\t\t\t//https://gamedev.stackexchange.com/questions/153326/how-to-rotate-directional-billboard-particle-sprites-toward-the-direction-the-pa\n\t\t\tvec3 quad_center_in_time = center;\n\t\t\tquad_center_in_time += force;\n\n\t\t\t// Get previous positions to calculate movement direction\n\t\t\tprev_force += prev_vel;\n\t\t\tprev_force *= prev_drag;\n\t\t\tprev_force += prev_accel * age;\n\t\t\tprev_pos += prev_force;\n\n\t\t\t//https://gamedev.stackexchange.com/questions/117528/calculate-matrix-transformation-components-separately/117539#117539\n\t\t\tfloat scaleX = length(vec3(modelMatrix[0][0], modelMatrix[0][1], modelMatrix[0][2]));\n\t\t\t// float scaleY = length(vec3(modelMatrix[1][0], modelMatrix[1][1], modelMatrix[1][2]));\n\t\t\t// float scaleZ = length(vec3(modelMatrix[2][0], modelMatrix[2][1], modelMatrix[2][2]));\n\n\t\t\tfloat maxScale = scaleX; // max(max(scaleX, scaleY), scaleZ);\n\n\t\t\tvec4 wPos;\n\t\t\t#ifdef WORLD_SPACE_ENABLED\n\t\t\t\twPos = vec4(worldSpawnPosition + pos, 1.0);\n\t\t\t#else\n\t\t\t\twPos = modelMatrix * vec4(pos, 1.0);\n\t\t\t#endif\n\t\t\tvec3 wCameraPos = cameraPosition;\n\t\t\tvec3 wCameraPlaneNormal = normalize(wCameraPos - quad_center_in_time);\n\t\t\tvec4 _forceDirInTime = vec4(force - prev_force, 1.0) * inverse(modelMatrix);\n\t\t\tvec3 forceDirInTime = normalize(_forceDirInTime.xyz);\n\t\t\tmat4 projectionViewMatrix = projectionMatrix * viewMatrix;\n\n\t\t\tvec3 wUp = vec3(0.0, 1.0, 0.0);\n\t\t\tfloat dot = dot(forceDirInTime, wCameraPlaneNormal);\n\t\t\tif (abs(dot) < 1.0)\n\t\t\t{\n\t\t\t\twUp = cross(wCameraPlaneNormal, forceDirInTime);\n\t\t\t}\n\n\t\t\twUp = wUp * particleSize * maxScale * 0.5;\n\t\t\tforceDirInTime *= particleSize * maxScale * 0.5;\n\n\t\t\tif (position.x < 0.0) {\n\t\t\t\tif (position.y < 0.0) {\n\t\t\t\t\t// top left quad vertex\n\t\t\t\t\tgl_Position = projectionViewMatrix * vec4(wPos.xyz - wUp + forceDirInTime, 1.0);\n\t\t\t\t} else {\n\t\t\t\t\t// bottom left quad vertex\n\t\t\t\t\tgl_Position = projectionViewMatrix * vec4(wPos.xyz - wUp - forceDirInTime, 1.0);\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tif (position.y < 0.0) {\n\t\t\t\t\t// top right quad vertex\n\t\t\t\t\tgl_Position = projectionViewMatrix * vec4(wPos.xyz + wUp + forceDirInTime, 1.0);\n\t\t\t\t} else {\n\t\t\t\t\t// bottom right quad vertex\n\t\t\t\t\tgl_Position = projectionViewMatrix * vec4(wPos.xyz + wUp - forceDirInTime, 1.0);\n\t\t\t\t}\n\t\t\t}\n\t\t#endif\n\n\t\t#ifdef CYLINDRICAL_BILLBOARD\n\t\t\t//Quad Billboard : Works only on quads that have its center at origin.\n\t\t\t// https://www.youtube.com/watch?v=AY73ZAEKqBM\n\t\t\t// https://github.com/sketchpunk/FunWithWebGL2/blob/5d4148de1714376b0b4a47e8b59826362c256f68/progress/fungi/shaders/TransformFB_P2.txt\n\t\t\t// http://www.songho.ca/opengl/files/gl_anglestoaxes01.png\n\n\t\t\tmat4 mvMat;\n\t\t\tvec4 worldPos;\n\t\t\t#ifdef WORLD_SPACE_ENABLED\n\t\t\t\tworldPos = vec4(worldSpawnPosition + pos, 1.0);\n\t\t\t\tmvMat = viewMatrix;\n\t\t\t#else\n\t\t\t\tworldPos = modelMatrix * vec4(pos, 1.0);\n\t\t\t\tmvMat = modelViewMatrix;\n\t\t\t#endif\n\t\t\t// https://gamedev.stackexchange.com/questions/119702/fastest-way-to-neutralize-scale-in-the-transform-matrix\n\t\t\tmat4 mvMatWithoutScale = mat4(normalize(mvMat[0]), normalize(mvMat[1]), normalize(mvMat[2]), mvMat[3]);\n\n\t\t\tvec3 right = vec3(mvMatWithoutScale[0][0], mvMatWithoutScale[1][0], mvMatWithoutScale[2][0]);\n\t\t\tvec4 up = vec4(0.0, 1.0, 0.0, 1.0); // Cylindrical\n\n // GLSL automatically takes the top-left 3\u00D73\n mat3 rotationMatrix = mat3(getRotationMatrix4(vec3(0, 0, 1), particleRotationRadians)); \n\n // Apply particle rotation and size to vertex in the XY plane\n vec3 p = rotationMatrix * position * particleSize;\n\n\t\t\t//vec3 p = position * particleSize;\n\t\t\tvec3 vert_billboard_pos = pos + (right.xyz * p.x) + (up.xyz * p.y); //Rotate vertex toward camera\n\n\t\t\t#ifdef WORLD_SPACE_ENABLED\n\t\t\t\tvec4 worldVertPos = vec4(worldSpawnPosition + vert_billboard_pos, 1.0);\n\t\t\t\tgl_Position = projectionMatrix * viewMatrix * worldVertPos;\n\t\t\t#else\n\t\t\t\tgl_Position = projectionMatrix * modelViewMatrix * vec4(vert_billboard_pos, 1.0);\n\t\t\t#endif\n\t\t#endif\n\n\n\t\t#ifdef SPHERICAL_BILLBOARD\n\t\t //Convert pos to a world-space value\n\t\t\tvec4 mvPosition;\n\t\t\tfloat scaleX;\n\t\t\t#ifdef WORLD_SPACE_ENABLED\n\t\t\t\t// For world space, use unit scale and world spawn position\n\t\t\t\tscaleX = 1.0;\n\t\t\t\tmvPosition = viewMatrix * vec4(worldSpawnPosition + pos, 1.0);\n\t\t\t#else\n\t\t\t\tscaleX = length(vec3(modelMatrix[0][0], modelMatrix[0][1], modelMatrix[0][2]));\n\t\t\t\tmvPosition = modelViewMatrix * vec4( pos, 1.0 );\n\t\t\t#endif\n\n mat3 rotationMatrix = mat3(getRotationMatrix4(vec3(0, 0, 1), particleRotationRadians));\n\n\t\t\tmvPosition.xy += (rotationMatrix * position).xy * particleSize * scaleX;\n\n\t\t\tgl_Position = projectionMatrix * mvPosition;\n\t\t#endif\n\n\t\t#ifdef NO_BILLBOARD\n\t\t\t#ifdef RANDOM_PARTICLE_ROTATION\n\t\t\t\tvec3 randomSeed = normalize(center + velocity);\n\t\t\t\tvec3 randomAxis = vec3(rand(randomSeed[0]), rand(randomSeed[1]), rand(randomSeed[2]));\n\t\t\t\tvec3 normAxis = normalize(randomAxis);\n\n\t\t\t\tfloat angle = 0.0;\n\t\t\t\tfloat random = normAxis[0] / size.x;\n\t\t\t\tfloat rotationRandomness = clamp(random, 0.6, 1.2);\n\t\t\t\tfloat endAngle = randomParticleRotationAngle * rotationRandomness;\n\n\t\t\t\tif (normAxis[0] > 0.5) {\n\t\t\t\t\tangle += mix(0.0, endAngle, positionInTime);\n\t\t\t\t} else {\n\t\t\t\t\tangle -= mix(0.0, endAngle, positionInTime);\n\t\t\t\t}\n\n\t\t\t\tmat4 rotationMatrix = getRotationMatrix4(randomAxis, angle);\n\t\t\t\tvec4 rotatedPos = vec4(position, 1.0) * rotationMatrix;\n\t\t\t\tvec4 vertexPosition = vec4(pos + (rotatedPos.xyz * particleSize), 1.0);\n\t\t\t#else\n\t\t\t\tvec3 unpackedRotationAxis = unpackRotationAxis(rotation[0]);\n\t\t\t\tmat3 rotationMatrix3 = mat3(getRotationMatrix4(unpackedRotationAxis, particleRotationRadians)); \n\n\t\t\t\tvec4 vertexPosition = vec4(pos + (rotationMatrix3 * position) * particleSize, 1.0);\n\t\t\t#endif\n\t\t\t#ifdef WORLD_SPACE_ENABLED\n\t\t\t\tvec4 worldVertexPosition = vec4(worldSpawnPosition + vertexPosition.xyz, 1.0);\n\t\t\t\tgl_Position = projectionMatrix * viewMatrix * worldVertexPosition;\n\t\t\t#else\n\t\t\t\tgl_Position = projectionMatrix * modelViewMatrix * vertexPosition;\n\t\t\t#endif\n\t\t#endif\n\n\n #include \n #include \n\n }\n\n";