[SOLVED] Particles self rotation while facing the camera (ie: sphericalbillboard)

Hi !
I wanted to add some animation to my instanced particles engine, but it seems I cannot have both: particles facing camera, and particle rotating around its center.
The particles don’t have a world matrix, I only use posVP to draw them.

Do they need a world matrix to make them rotate around the vector facing the cam ?
I have tried so many things I’m a little lost. The only thing almost normal I achieved is the particles rotating around the emitter position, that’s when I started wondering about a worldmatrix.

I found this: https://en.wikipedia.org/wiki/Rodrigues'_rotation_formula but before I start with this…
Is there a (simple) solution to rotate the quad after the posVP (screenspace) around its own center ? (which is known: the current corner processed, and the 3D center position of the particle)

The particles in the xna gpu particle sample do that, take a look (on mobile, can’t link)

Had a look at it, and I took the rotation part into my code, but the rotation (a 2x2 matrix) is done around the emitter, if I move the rotation multiplication somewhere else, I loose the alignement to the camera :confused: and the rotation is still weird…

I’ll post some code later

Did you try it out? I’m almost 100% sure it’s not centered on the emitter.

If it were though you have to change the order of multiplication

They rotate around their center, but in my shader they rotate around the emitter, I must have set the rotation to the wrong place.
I have placed it at the “same” moment, after the V*P multiplication :confused:

In the sample, corners are done this way:

for (int i = 0; i < settings.MaxParticles; i++)
{
    particles[i * 4 + 0].Corner = new Short2(-1, -1);
    particles[i * 4 + 1].Corner = new Short2(1, -1);
    particles[i * 4 + 2].Corner = new Short2(1, 1);
    particles[i * 4 + 3].Corner = new Short2(-1, 1);
}

Whereas mine, as I’m using instancing, are done one time at the definition vertexbuffer:

vertices[0].Position = new Vector3(-halfWidth, -halfHeight, 0);
vertices[1].Position = new Vector3(halfWidth, -halfHeight, 0);
vertices[2].Position = new Vector3(-halfWidth, halfHeight, 0);
vertices[3].Position = new Vector3(halfWidth, halfHeight, 0);

But I dont think scaling changes the center of the rotation.

I then align to the camera (which in the sampler is done … where) ?

temp_pos3D = pos3D.xyz;
temp_pos3D += (offset.x * Size.x * Side + offset.y * Size.y * Up); //side is the camera’s Right Vector3, Up is the camera’s Up Vector3

and then the V*P comes… and the rotation

Maybe it is here my problem lies…

ex:

Nyaha you already helped me out about this problem and now you’re experiencing it, I solved mine because its easy and not using a shader… CreateBillboard is enough on my case ^ _^ Y good luck Sir…

I know :slight_smile:
I’m sure I did the multiplication the right order, but they still rotate around something instead of their center :frowning:
Can draw millions of them, but cannot have them rotate… pfffff

I solved again the problem myself… almost
After explaining my problem, I had an idea: rotate the texture coordinates. And voilà:

New problem: the texture coordinates sometimes jumps/stutter when moving the camera…

EDIT: I think this is not the right solution. So this is not solved.
I think I’ll have to compute the rotation around the eye vector…
Because the difference between xna’s sample and my code is the instancing:
I set the position of the particles (in fact the emitter just serves me as a center of the “volume”),
while in XNA they moved from the emitter (where their coordinates start at) in the vertex shader. There is something I must be missing/messing with.