Happy Friday!
I’m making a particle system driven by a computer shader. I got most of the technique from Bruno Imbrizi’s Curl Noise video. In Bruno’s tutorial, he has the boxes rotate to face the direction they are moving by setting “Rotate to Vector” in the Geometry instancing. My problem is that I want to have other things affecting the rotation of the instances, so I would rather create the same effect only using the Rotate OP input of the Geometry instancing.
I’ve attached the simplest possible recreation of my actual particle system. It might be hard to see in this video, but it’s 16 cones moving around, but they’re always facing the camera. I want them to face the direction they are moving. And I need to do this only using the Rotate OP, not the Rotate To Vector OP.
https://vimeo.com/620085989
SimpleParticles.toe (6.7 KB)
The simplified shader that is controlling the instancing is:
layout (local_size_x = 8, local_size_y = 8) in;
#define M_PI 3.1415926535897932384626433832795
#define HALF_PI (M_PI/2.0)
#define TWO_PI (M_PI*2.0)
vec3 lookAt(vec3 v1, vec3 v2) {
// What goes here to make the instances look "forward"?
return vec3(0,0,0);
}
void main()
{
vec3 pos = texelFetch(sTD2DInputs[0], ivec2(gl_GlobalInvocationID.xy), 0).xyz;
vec3 vel = texelFetch(sTD2DInputs[1], ivec2(gl_GlobalInvocationID.xy), 0).xyz;
vec3 acc = texelFetch(sTD2DInputs[2], ivec2(gl_GlobalInvocationID.xy), 0).xyz;
acc *= 0.001; // We just need a tiny bit of the acceleration
acc += -pos * 0.001; // attract them back towards the center just a bit.
vel += acc;
pos += vel;
vel *= 0.96; // friction - slow 'em down a bit.
vec3 rot = lookAt(pos, pos+vel);
imageStore(mTDComputeOutputs[0], ivec2(gl_GlobalInvocationID.xy), TDOutputSwizzle(vec4(pos,1)));
imageStore(mTDComputeOutputs[1], ivec2(gl_GlobalInvocationID.xy), TDOutputSwizzle(vec4(vel,1)));
imageStore(mTDComputeOutputs[2], ivec2(gl_GlobalInvocationID.xy), TDOutputSwizzle(vec4(rot,1)));
}
So my question is: how do I calculate the rotation? My research so far has led me to believe that it is either very simple or somewhat complex. I know I should probably be using quaternions instead of euler angles, which would mean I would need to store both the quaternion in an output buffer in order to do that calculations, and then another buffer with the quat translated to euler angles so that I can feed that to the Rotate OP in the Instancing tab…
As you can see, I’m a bit confused. Any help would be greatly appreciated. Thanks in advance.