- "precision mediump float;\n"
-
- "attribute vec2 aPosition;\n"
-
- "uniform mat4 uMvpMatrix;\n"
- "uniform mat4 uModelView;\n"
- "uniform mat4 uViewMatrix;\n"
- "uniform mat4 uProjection;\n"
- "uniform vec3 uSize;\n"
-
- "uniform mat4 uModelLastFrame;\n"
- "float timeDelta = 0.0167;\n"
-
- "uniform float uGeometryStretchFactor;\n"
- "uniform float uSpeedScalingFactor;\n"
-
- // outputs
- "varying vec2 vModelSpaceCenterToPos;\n"
- "varying vec2 vScreenSpaceVelocityVector;\n"
- "varying float vSpeed;\n"
- "varying vec2 vTexCoord;\n"
-
- "void main()\n"
- "{\n"
- // get view space position of vertex this frame and last frame
- " vec4 vertexPosition = vec4(aPosition, 0.0, 1.0);\n"
- " vertexPosition.xyz *= uSize;\n"
-
- " vec4 viewSpaceVertex = uModelView * vertexPosition;\n"
- " vec4 viewSpaceVertexLastFrame = (uViewMatrix * uModelLastFrame) * vertexPosition;\n"
- " float reciprocalTimeDelta = 1.0 / timeDelta;\n"
-
- // work out vertex's last movement in view space
- " vec3 viewSpacePosDelta = viewSpaceVertex.xyz - viewSpaceVertexLastFrame.xyz;\n"
-
- // get clip space position of vertex this frame and last frame
- " vec4 clipSpaceVertex = uMvpMatrix * vertexPosition;\n"
- " vec4 clipSpaceVertexLastFrame = uProjection * viewSpaceVertexLastFrame;\n"
-
- // decide how much this vertex is 'trailing', i.e. at the back of the object relative to its direction of motion. We do this
- // by assuming the objects model space origin is at its center and taking the dot product of the vector from center to vertex with the motion direction
- " float t = 0.0;\n"
- " float posDeltaLength = length(viewSpacePosDelta);\n"
- " if(posDeltaLength > 0.001)\n" // avoid div by 0 if object has barely moved
- " {\n"
- " vec4 viewSpaceCenterToPos = uModelView * vec4(vertexPosition.xy, 0.0, 0.0);\n"
- " float centerToVertexDist = length(viewSpaceCenterToPos);\n"
- " if(centerToVertexDist > 0.001)\n" // avoid div by 0 if object has vertex at model space origin
- " {\n"
- " vec3 viewSpacePosDeltaNormalised = viewSpacePosDelta / posDeltaLength;\n"
- " vec3 viewSpaceCenterToPosNormalised = viewSpaceCenterToPos.xyz / centerToVertexDist;\n"
- " t = (dot(viewSpacePosDeltaNormalised, viewSpaceCenterToPosNormalised) * 0.5 ) + 0.5;\n" // scale and bias from [-1..1] to [0..1]
- " }\n"
- " }\n"
- // output vertex position lerped with its last position, based on how much it is trailing,
- // this stretches the geom back along where it has just been, giving a warping effect
- // Note: we must take account of time delta to convert position delta into a velocity, so changes are smooth (take into account frame time correctly)
- " gl_Position = mix(clipSpaceVertexLastFrame, clipSpaceVertex, t * uGeometryStretchFactor * reciprocalTimeDelta);\n"
-
- // work out vertex's last movement in normalised device coordinates [-1..1] space, i.e. perspective divide
- " vec2 ndcVertex = clipSpaceVertex.xy / clipSpaceVertex.w;\n"
- " vec2 ndcVertexLastFrame = clipSpaceVertexLastFrame.xy / clipSpaceVertexLastFrame.w;\n"
- // scale and bias so that a value of 1.0 corresponds to screen size (NDC is [-1..1] = 2)
- " vScreenSpaceVelocityVector = ((ndcVertex - ndcVertexLastFrame) * 0.5 * reciprocalTimeDelta);\n"
- " vScreenSpaceVelocityVector.y = -vScreenSpaceVelocityVector.y;\n" // TODO negated due to y being inverted in our coordinate system?
- // calculate a scaling factor proportional to velocity, which we can use to tweak how things look
- " vSpeed = length(vScreenSpaceVelocityVector) * uSpeedScalingFactor;\n"
- " vSpeed = clamp(vSpeed, 0.0, 1.0);\n"
-
- // provide fragment shader with vector from center of object to pixel (assumes the objects model space origin is at its center and verts have same z)
- " vModelSpaceCenterToPos = viewSpaceVertex.xy;\n"
-
- " vec2 texCoord = aPosition + vec2(0.5);"
- " vTexCoord = texCoord;\n"
- "}\n";
-
+ "precision mediump float;\n"
+
+ "attribute vec2 aPosition;\n"
+
+ "uniform mat4 uMvpMatrix;\n"
+ "uniform mat4 uModelView;\n"
+ "uniform mat4 uViewMatrix;\n"
+ "uniform mat4 uProjection;\n"
+ "uniform vec3 uSize;\n"
+
+ "uniform mat4 uModelLastFrame;\n"
+ "float timeDelta = 0.0167;\n"
+
+ "uniform float uGeometryStretchFactor;\n"
+ "uniform float uSpeedScalingFactor;\n"
+
+ // outputs
+ "varying vec2 vModelSpaceCenterToPos;\n"
+ "varying vec2 vScreenSpaceVelocityVector;\n"
+ "varying float vSpeed;\n"
+ "varying vec2 vTexCoord;\n"
+
+ "void main()\n"
+ "{\n"
+ // get view space position of vertex this frame and last frame
+ " vec4 vertexPosition = vec4(aPosition, 0.0, 1.0);\n"
+ " vertexPosition.xyz *= uSize;\n"
+
+ " vec4 viewSpaceVertex = uModelView * vertexPosition;\n"
+ " vec4 viewSpaceVertexLastFrame = (uViewMatrix * uModelLastFrame) * vertexPosition;\n"
+ " float reciprocalTimeDelta = 1.0 / timeDelta;\n"
+
+ // work out vertex's last movement in view space
+ " vec3 viewSpacePosDelta = viewSpaceVertex.xyz - viewSpaceVertexLastFrame.xyz;\n"
+
+ // get clip space position of vertex this frame and last frame
+ " vec4 clipSpaceVertex = uMvpMatrix * vertexPosition;\n"
+ " vec4 clipSpaceVertexLastFrame = uProjection * viewSpaceVertexLastFrame;\n"
+
+ // decide how much this vertex is 'trailing', i.e. at the back of the object relative to its direction of motion. We do this
+ // by assuming the objects model space origin is at its center and taking the dot product of the vector from center to vertex with the motion direction
+ " float t = 0.0;\n"
+ " float posDeltaLength = length(viewSpacePosDelta);\n"
+ " if(posDeltaLength > 0.001)\n" // avoid div by 0 if object has barely moved
+ " {\n"
+ " vec4 viewSpaceCenterToPos = uModelView * vec4(vertexPosition.xy, 0.0, 0.0);\n"
+ " float centerToVertexDist = length(viewSpaceCenterToPos);\n"
+ " if(centerToVertexDist > 0.001)\n" // avoid div by 0 if object has vertex at model space origin
+ " {\n"
+ " vec3 viewSpacePosDeltaNormalised = viewSpacePosDelta / posDeltaLength;\n"
+ " vec3 viewSpaceCenterToPosNormalised = viewSpaceCenterToPos.xyz / centerToVertexDist;\n"
+ " t = (dot(viewSpacePosDeltaNormalised, viewSpaceCenterToPosNormalised) * 0.5 ) + 0.5;\n" // scale and bias from [-1..1] to [0..1]
+ " }\n"
+ " }\n"
+ // output vertex position lerped with its last position, based on how much it is trailing,
+ // this stretches the geom back along where it has just been, giving a warping effect
+ // Note: we must take account of time delta to convert position delta into a velocity, so changes are smooth (take into account frame time correctly)
+ " gl_Position = mix(clipSpaceVertexLastFrame, clipSpaceVertex, t * uGeometryStretchFactor * reciprocalTimeDelta);\n"
+
+ // work out vertex's last movement in normalised device coordinates [-1..1] space, i.e. perspective divide
+ " vec2 ndcVertex = clipSpaceVertex.xy / clipSpaceVertex.w;\n"
+ " vec2 ndcVertexLastFrame = clipSpaceVertexLastFrame.xy / clipSpaceVertexLastFrame.w;\n"
+ // scale and bias so that a value of 1.0 corresponds to screen size (NDC is [-1..1] = 2)
+ " vScreenSpaceVelocityVector = ((ndcVertex - ndcVertexLastFrame) * 0.5 * reciprocalTimeDelta);\n"
+ " vScreenSpaceVelocityVector.y = -vScreenSpaceVelocityVector.y;\n" // TODO negated due to y being inverted in our coordinate system?
+ // calculate a scaling factor proportional to velocity, which we can use to tweak how things look
+ " vSpeed = length(vScreenSpaceVelocityVector) * uSpeedScalingFactor;\n"
+ " vSpeed = clamp(vSpeed, 0.0, 1.0);\n"
+
+ // provide fragment shader with vector from center of object to pixel (assumes the objects model space origin is at its center and verts have same z)
+ " vModelSpaceCenterToPos = viewSpaceVertex.xy;\n"
+
+ " vec2 texCoord = aPosition + vec2(0.5);"
+ " vTexCoord = texCoord;\n"
+ "}\n";