Motion Blur Implementation

A forum for exporter development discussion.
Post Reply
10 posts • Page 1 of 1
User avatar
Whaat
Developer
Posts: 1827
Joined: Fri Dec 22, 2006 6:15 am
Location: Canada
Contact:

Motion Blur Implementation

Post by Whaat » Tue May 05, 2009 4:57 pm

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?

User avatar
OnoSendai
Developer
Posts: 6227
Joined: Sat May 20, 2006 6:16 pm
Location: Wellington, NZ
Contact:

Re: Motion Blur Implementation

Post by OnoSendai » Tue May 05, 2009 5:09 pm

Check out motion_blur_test.igs and camera_motion_blur_test.igs from the testscenes dir in Indigo 2.0.4.

User avatar
Whaat
Developer
Posts: 1827
Joined: Fri Dec 22, 2006 6:15 am
Location: Canada
Contact:

Re: Motion Blur Implementation

Post by Whaat » Tue Jun 02, 2009 4:03 pm

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...

User avatar
OnoSendai
Developer
Posts: 6227
Joined: Sat May 20, 2006 6:16 pm
Location: Wellington, NZ
Contact:

Re: Motion Blur Implementation

Post by OnoSendai » Tue Jun 02, 2009 4:13 pm

It describes a rotation transformation, applied after any <rotation> element transformation if present.
So it's not relative to the last keyframe.

User avatar
Whaat
Developer
Posts: 1827
Joined: Fri Dec 22, 2006 6:15 am
Location: Canada
Contact:

Re: Motion Blur Implementation

Post by Whaat » Sun Jun 07, 2009 4:47 pm

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?

User avatar
Whaat
Developer
Posts: 1827
Joined: Fri Dec 22, 2006 6:15 am
Location: Canada
Contact:

Re: Motion Blur Implementation

Post by Whaat » Sun Jun 07, 2009 5:06 pm

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.

User avatar
benn
Posts: 1046
Joined: Mon Dec 08, 2008 12:47 pm
Location: Wellington, New Zealand
Contact:

Re: Motion Blur Implementation

Post by benn » Sun Jun 07, 2009 6:37 pm

I'll ask Nick tomorrow and get back to you.

User avatar
fused
Developer
Posts: 3648
Joined: Fri Sep 22, 2006 7:19 am
Location: Berlin, Germany
3D Software: Cinema 4D

Re: Motion Blur Implementation

Post by fused » Sun Jun 07, 2009 11:21 pm

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 :)

User avatar
Whaat
Developer
Posts: 1827
Joined: Fri Dec 22, 2006 6:15 am
Location: Canada
Contact:

Re: Motion Blur Implementation

Post by Whaat » Mon Jun 08, 2009 10:21 am

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?

User avatar
fused
Developer
Posts: 3648
Joined: Fri Sep 22, 2006 7:19 am
Location: Berlin, Germany
3D Software: Cinema 4D

Re: Motion Blur Implementation

Post by fused » Mon Jun 08, 2009 10:47 am

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...

Post Reply
10 posts • Page 1 of 1

Who is online

Users browsing this forum: No registered users and 1 guest