Page 1 of 1

Motion Blur Implementation

Posted: Tue May 05, 2009 4:57 pm
by Whaat
How about some info on implementing motion blur? I thought I read that Ono emailed some stuff to fused. Can someone please explain the XML tags related to motion blur?

Re: Motion Blur Implementation

Posted: Tue May 05, 2009 5:09 pm
by OnoSendai
Check out motion_blur_test.igs and camera_motion_blur_test.igs from the testscenes dir in Indigo 2.0.4.

Re: Motion Blur Implementation

Posted: Tue Jun 02, 2009 4:03 pm
by Whaat
Ono,

is the intent of the rotation quaternion element to represent the current orientation or the change in orientation from the previous keyframe? It seems to represent a change...

Re: Motion Blur Implementation

Posted: Tue Jun 02, 2009 4:13 pm
by OnoSendai
It describes a rotation transformation, applied after any <rotation> element transformation if present.
So it's not relative to the last keyframe.

Re: Motion Blur Implementation

Posted: Sun Jun 07, 2009 4:47 pm
by Whaat
OnoSendai wrote:It describes a rotation transformation, applied after any <rotation> element transformation if present.
So it's not relative to the last keyframe.
so what if you don't have a <rotation> element present?

Re: Motion Blur Implementation

Posted: Sun Jun 07, 2009 5:06 pm
by Whaat
OK. Could someone just spell it out for me? :) I would like to see actual code that does the following:
Given vectors for the x,y,z axes of a model, convert to the type of quaternion that is accepted by Indigo. I know I am on the right track but I need a bit of help here.

Re: Motion Blur Implementation

Posted: Sun Jun 07, 2009 6:37 pm
by benn
I'll ask Nick tomorrow and get back to you.

Re: Motion Blur Implementation

Posted: Sun Jun 07, 2009 11:21 pm
by fused
Whaat wrote:OK. Could someone just spell it out for me? :) I would like to see actual code that does the following:
Given vectors for the x,y,z axes of a model, convert to the type of quaternion that is accepted by Indigo. I know I am on the right track but I need a bit of help here.
Dont be confused by the word "quaternion", it just expects simple axis rotation that is internally converted to a quaternion. i implemented 3 different ways to convert it and never got correct results, then asked nick and he told me that.

i think the easiest is that the <rotation> just carries an identity matrix (maybe with scale) when using motion blur.

heres some of my (experimental) motion blur code:

Code: Select all

	[...bleh...]

	//SCALE
	SceneExportRealValue("scale", 1.0, model);

	//MESH_NAME
	SceneExportStringValue("mesh_name", meshname.GetFileString(), model);

	//Motion blur
	Real strength = 1.0;
	LONG num_keyframes_inbetween = 0;

	if (ObjectHasMotionBlurTag(obj, strength, num_keyframes_inbetween)) {
		//experimental mb stuff
		SceneExportMoBlurMatrix(model, m); //exports the identity matrix with applied scale

		LONG fps = mDoc->GetFps();

		BaseTime time = BaseTime(m_frame, fps);

		//get topmost object with animation, neccecary so all childs will be correctly animated
		//if found, animate
		BaseObject *topmost = GetTopmostAnimated(obj);
		if (topmost) mDoc->AnimateObject(topmost, time, ANIMATE_QUICK);

		Real rotation;
		Vector axis;
		Vector position;

		position = obj->GetMg().off;
		MatrixToRotAxis(obj->GetMg(), &axis, &rotation);
		SceneExportKeyframe(0.0, model, rotation, axis, position); //exports the first keyframe

		//some stuff to get along with c4d animation stuff. only whole keyframes can be
		//exported for now - getting values inbetween is a bit tricky
		Real m_exposure = 0.3333333;
		Real newFrame = (Real)m_frame + (fps * m_exposure);

		Real step = 1 / Floor((fps * m_exposure) + 0.5);

		//export all other keyframes
		for (int i = m_frame+1; i < newFrame-0.5; i++)
		{
			time = BaseTime(i, mDoc->GetFps());

			topmost = GetTopmostAnimated(obj);
			if (topmost) mDoc->AnimateObject(topmost, time, ANIMATE_QUICK);

			position = obj->GetMg().off;
			MatrixToRotAxis(obj->GetMg(), &axis, &rotation);
			SceneExportKeyframe(step*i, model, rotation, axis, position);
		}

		time = BaseTime(newFrame, mDoc->GetFps());
		
		topmost = GetTopmostAnimated(obj);
		if (topmost) mDoc->AnimateObject(topmost, time, ANIMATE_QUICK);

		position = obj->GetMg().off;
		MatrixToRotAxis(obj->GetMg(), &axis, &rotation);
		SceneExportKeyframe(1.0, model, rotation, axis, position);
	} else { //if no motion blur, normal rotation
		//POS/ROTATION/SCALE
		SceneExportPosAndMatrix(model, m);
	}
i admit, its a bit messy :)

Re: Motion Blur Implementation

Posted: Mon Jun 08, 2009 10:21 am
by Whaat
I think the part I am interested in the most is this:

Code: Select all

MatrixToRotAxis(obj->GetMg(), &axis, &rotation);
Do you mind exposing this method? :) Or is part of the API?

Re: Motion Blur Implementation

Posted: Mon Jun 08, 2009 10:47 am
by fused
Its part of the API, but no problem :)

Code: Select all

void MatrixToRotAxis(const Matrix &mm, Vector *v, Real *w)
{
	Matrix m = mm;
	// MatrixVectoren MUESSEN normiert sein!!! ---vec's must be normalized
	m.v1=!m.v1;
	m.v2=!m.v2;
	m.v3=!m.v3;

	// Winkel berechnen ---calculate angles
	*w = ACos((m.v1.x+m.v2.y+m.v3.z-1.0)/2.0);

	// Achse berechnen ---calc axis
	v->x= m.v2.z-m.v3.y;
	v->y= m.v3.x-m.v1.z;
	v->z= m.v1.y-m.v2.x;
	*v = !(*v);

	if (*v==0.0)
	{
		*v = Vector(0.0,1.0,0.0);
		*w = 0.0;
	}
}
you can clearly see that maxons coders dont give a damn about writing english comments ;)
probably copyrighted by maxon or so, so make sure you dont copy that 1:1. be inspired :P

added some translation for you...