export default /* glsl */ ` #include #include #include #include #include #include attribute vec3 offset; attribute float rotation; attribute vec3 size; attribute vec4 velocity; uniform float speedFactor; void main() { float lengthFactor = velocity.w; float avgSize = (size.x + size.y) * 0.5; #ifdef USE_SKEW vec4 mvPosition = modelViewMatrix * vec4( offset, 1.0 ); vec3 viewVelocity = normalMatrix * velocity.xyz; vec3 scaledPos = vec3(position.xy * size.xy, position.z); float vlength = length(viewVelocity); vec3 projVelocity = dot(scaledPos, viewVelocity) * viewVelocity / vlength; mvPosition.xyz += scaledPos + projVelocity * (speedFactor / avgSize + lengthFactor / vlength); #else vec4 mvPosition = modelViewMatrix * vec4( offset, 1.0 ); vec3 viewVelocity = normalMatrix * velocity.xyz; float vlength = length(viewVelocity); mvPosition.xyz += position.y * normalize(cross(mvPosition.xyz, viewVelocity)) * avgSize; // switch the cross to match unity implementation mvPosition.xyz -= (position.x + 0.5) * viewVelocity * (1.0 + lengthFactor / vlength) * avgSize; // minus position.x to match unity implementation #endif vColor = color; gl_Position = projectionMatrix * mvPosition; #include #include #include #include } `; /* vec3 instancePos = vec3(position.xy * size, position.z); instancePos += dot(instancePos, viewVelocity) * viewVelocity * speedFactor; mvPosition.xyz += instancePos; vColor = color; //vec4(1, 1, 1, 1); //color; //length(viewVelocity) * 0.1 #ifndef USE_SIZEATTENUATION bool isPerspective = ( projectionMatrix[ 2 ][ 3 ] == - 1.0 ); if ( isPerspective ) computedSize *= - mvPosition.z; #endif */