Transform_world & Motion Blur
- May 3, 2022
- 1 reply
- 1027 views
Hi gang;
I am having a really tough time trying to get motion blur to work ***correctly***. I'm working on a rather simple particle system so I am attempting to create a new world for every particle, and transform it with motion blur. I have scoured this forum inside out and pieced together a working piece but since there is no documentation anywhere that explains what part of the transform matrix relates to what, I am not getting anywhere.
Here is the meat of the code:
PF_CompositeMode mode;
mode.opacity = alpha * 255 + 0.5;
mode.opacitySu = alpha * 32768 + 0.5;
mode.rgb_only = false;
mode.xfer = PF_Xfer_IN_FRONT;
PF_FloatMatrix mat1;
PF_FloatMatrix mat2;
double ratio = (double)in_data->downsample_x.num / (double)in_data->downsample_x.den;
double scale = 1.0 * ratio * psize;
// Before matrix
// i is the current particle in the loop
mat1.mat[0][0] = mat1.mat[1][1] = mat1.mat[2][2] = i; // identity
mat1.mat[2][0] = px2 - checkoutLayer.u.ld.width * scale / 2; // This is the x translation
mat1.mat[2][1] = py2 - checkoutLayer.u.ld.height * scale / 2; // This is the y translation
mat1.mat[0][0] = scale; // This is the scale
mat1.mat[1][1] = scale; // This is the scale
// After Matrix
mat2.mat[0][0] = mat2.mat[1][1] = mat2.mat[2][2] = i; // identity
// lastpx & lastpy are arrays holding the previous frame (time) particle position
mat2.mat[2][0] = lastpx[i][time+1] - checkoutLayer.u.ld.width * scale / 2; // This is the x translation
mat2.mat[2][1] = lastpy[i][time+1] - checkoutLayer.u.ld.height * scale / 2; // This is the y translation
mat2.mat[0][0] = scale; // This is the scale
mat2.mat[1][1] = scale; // This is the scale
PF_FloatMatrix my_matrices[2];
my_matrices[0] = mat1;
my_matrices[1] = mat2;
PF_Rect dest;
dest.bottom = in_data->height;
dest.left = 0;
dest.right = in_data->width;
dest.top = 0;
int quality = PF_Quality_HI;
err = suites.WorldTransformSuite1()->transform_world(NULL, quality, F_MF_Alpha_STRAIGHT, PF_Field_FRAME, &particle_world, &mode, NULL, my_matrices, 2L, true, &dest, output);
ERR(suites.WorldSuite1()->dispose_world(in_data->effect_ref, &particle_world));Although this code works to some degree, it basically motion blurs every particle together, one after another, resulting in what looks like one long stream. I have attached a screengrab of what that looks like. It almost seems as if it's not separating the particle motion blur for each frame, but rather motion blurring them across frames as well. You can also see a streak going to the top-left hand corner which I have to figure out what that is.
I think this has something to do with the 'identity' but of course, there is no documentation anywhere that explains how to do this! I should add that all of this code is occuring inside the for-every-particle loop. So for each particle, I am creating a new world, copying the selected layer from it, transforming it, and destroying it. I didn't add the initial part that shows the creation and copying of the selected layer as that is rather self-explanatory and not likely the issue here.
I feel like I am close. The motion blur is there, it's just not separated by frames. But I won't be able to get anywhere if I can't find documentation that explains how to use it correctly.
Any helpful advice would be MUCH appreciated!
Thanks,
-Richard
