Reputation: 789
I got a conceptual question I cant wrap my head around. I made a picture from particles, so I have 50000 particles that make a nice picture. Now Id like to make a wave go through the picture / particles. all particles have x and y coord with z = 0.0 so z value this is what I want to animate over time
I have a basic vertex shader code
precision mediump float;
attribute float uColor;
attribute float uRnd;
uniform float uTime;
uniform float uMouseX;
uniform float uMouseY;
uniform bool uAnimate;
varying float uCol;
varying vec2 vUv;
varying vec2 vMousePos;
void main(){
uCol = uColor;
vUv = uv;
vMousePos = vec2(uMouseX, uMouseY);
vec3 pos = position;
vec4 modelPosition = modelMatrix * vec4(pos, 1.0);
vec4 viewPosition = viewMatrix * modelPosition;
vec4 projectedPosition = projectionMatrix * viewPosition;
gl_PointSize = 3.0;
gl_Position = projectedPosition;
}
Problem is I dont understand how can I influence only certain particles independet of others at any given time. for instance writing
vec4 modelPosition = modelMatrix * vec4(pos, 1.0);
modelposition.z += 100.0 * sin(uTime);
vec4 viewPosition = viewMatrix * modelPosition;
vec4 projectedPosition = projectionMatrix * viewPosition;
will influence every particle z position at any given time so entire picture moves. Iets say id want the wave to flow from left to right, so Id have to first start with particles on left side and then gradually move over to right side. what do I have to do to be able to select out certain vertexes from the rest ?
Upvotes: 1
Views: 102
Reputation: 9622
2 options:
calculate the per particle offset on the CPU and pass that information as an additional attribute buffer (i.e. do the same thing you do when passing normals and uv buffers) and then add the offset on the gpu.
Dfine your math transformation as a function f(x, y, t) where (x,y) are the original positions of a particle and t is teh current time, your function (written on the shader) now applies the transformation to the particles.
For example:
vec3 f(vec2 pos, float t)
{
return vec3(pos, sin(pos.x + t) + cos(pos.y + t));
}
Will make your particles wiggle over time, this might not be the pattern you need so you must play around with the math until you are satisfied.
Upvotes: 1