www.jpct.net

jPCT-AE - a 3d engine for Android => Support => Topic started by: Thomas. on July 20, 2012, 11:11:34 am

Title: modelViewProjectionMatrix
Post by: Thomas. on July 20, 2012, 11:11:34 am
How can I get modelViewProjectionMatrix in code? Is there some getter for this?
Title: Re: modelViewProjectionMatrix
Post by: EgonOlsen on July 20, 2012, 12:32:34 pm
No, it's a combination of model view (i.e. object's transformation and camera matrix) and projection matrix (i.e. frustum matrix). It's computed on the fly and feed into the shader. Why would you want to access it from outside the shader?
Title: Re: modelViewProjectionMatrix
Post by: Thomas. on July 20, 2012, 01:23:05 pm
I need previous MVPM for motion blur...
Title: Re: modelViewProjectionMatrix
Post by: EgonOlsen on July 20, 2012, 02:53:20 pm
That's a bit difficult...every solution that i can think of so far either feels wrong or will be much too complicated. The best option might be to add a special getter for this to GLSLShader. While this still feels wrong somehow, it's the only place where it actually fits...

Much hassle for a feature that i would turn off in the blink of an eye...
Title: Re: modelViewProjectionMatrix
Post by: Thomas. on July 20, 2012, 03:19:46 pm
From my side is every solution very complicated. I have one suggestion. I can not think of any other use of old MVPM, just motion blur. So, what about new boolean attribute in Object3D for send previous MVPM to shader? When matrix is calculated, it can be saved to attribute and send in next render. This is the simplest solution for us, IMHO :)

edit: In theory is motion blur as demanding as depth of field, so should not be any problems with performance.

And some method like renderScene(FrameBuffer, GLSLShader), which will set input shader for all objects while rendering and after return original, would be very useful. It is possible also from my side through IRenderHook, but...
Title: Re: modelViewProjectionMatrix
Post by: EgonOlsen on July 20, 2012, 05:44:06 pm
I could add something like that, but it feels a bit strange to me, because the matrix actually isn't an attribute of an object. Anyway, this leaves some questions: What if the object wasn't visible before? And what if it was but 2-x frames in the past? Does that matter?

Wouldn't it be better to simply inject the projection matrix (which doesn't change between frames unless you change the fov) into the shader and let the application control the injection of an additional model view matrix (which is simple the world transformation from the last frame in that case). That requires slightly more code on your side, but it seems to be the more logical and flexible solution to me.

About that render-method: You can simply extend FrameBuffer and add it yourself. Just iterate over all objects in the world, set your shader and call the super-method. I don't see the need for such a special purpose method to be part of the general API.
Title: Re: modelViewProjectionMatrix
Post by: Thomas. on July 20, 2012, 06:11:00 pm
If the object wasn't visible before? I didn't thinking about this, it is problem, object will has some "random" speed. But I don't show objects in middle of screen, so it will be fine. And if the object was never visible, be ideal send current MVPM, it has zero speed.

OK, it would be fine, but I don't know how to create model view matrix from transformation...?

Fine, I'll try it.
Title: Re: modelViewProjectionMatrix
Post by: EgonOlsen on July 20, 2012, 08:25:28 pm
I've added support for a new uniform called "projectionMatrix" to the beta jar. The model view matrix can be calculated like this (unoptimized):

Code: [Select]
Matrix mc=new Matrix();
Matrix mv=obj.getWorldTransformation();
mc.setTo(world.getCamera().getBack());
SimpleVector v=world.getCamera().getPosition();
v.scalarMul(-1);
mc.translate(v);
mv.matMul(mc);
Title: Re: modelViewProjectionMatrix
Post by: Thomas. on July 23, 2012, 04:54:07 pm
About that render-method: You can simply extend FrameBuffer and add it yourself. Just iterate over all objects in the world, set your shader and call the super-method. I don't see the need for such a special purpose method to be part of the general API.

Did you mean extends World? There is no method for get GLSLShader from Object3D. I have to copy all to array, draw and return original shader. It is not well solution, but probably there is nothing else...

And how can I set uniform for specific object, if many objects use one shader? Or uniforms are per shader?
Title: Re: modelViewProjectionMatrix
Post by: EgonOlsen on July 23, 2012, 08:47:27 pm
Yes, i meant to extend World. I've also added the getter for shaders to the beta-jar.

About the uniforms: They are per shader but you can set them per object, if you implement the IRenderHook interface and use setCurrentObject3D() and/or beforeRendering() for this.
Title: Re: modelViewProjectionMatrix
Post by: Thomas. on July 23, 2012, 09:50:06 pm
Ok, thanks :) ... Uniforms are for distortions. Motion blur will be by camera, only. For small mobile screens is useless doing anything extra complicated...
Title: Re: modelViewProjectionMatrix
Post by: Thomas. on July 24, 2012, 09:31:59 pm
I have confusion with matrix. I want model view projection matrix that is composed of model view matrix, camera rotation, translation and projection matrix, but is it possible? If yes, how can I do it?? Probably I have to somehow compensate model view matrix from previous camera settings, but I don't know how.

simply: I want new model view projection matrix from old model view matrix with new camera settings
Title: Re: modelViewProjectionMatrix
Post by: EgonOlsen on July 24, 2012, 09:35:10 pm
My idea was to store the model view matrix from the last frame, inject that into the shader and multiply it with the projection matrix (which doesn't change between frames).
Title: Re: modelViewProjectionMatrix
Post by: Thomas. on July 24, 2012, 09:46:44 pm
I wanted to avoid its :) You wrote "In some cases, it could be necessary to reset the ID", ID of Object3D can be reset at run time?
Title: Re: modelViewProjectionMatrix
Post by: EgonOlsen on July 24, 2012, 10:03:24 pm
Where did i wrote that and what did i mean with that... ???
Title: Re: modelViewProjectionMatrix
Post by: Thomas. on July 24, 2012, 10:06:37 pm
Object3D.getID() ... Object3D has still same ID or it can be reset?
Title: Re: modelViewProjectionMatrix
Post by: EgonOlsen on July 24, 2012, 10:10:07 pm
The ids will be assigned by the engine, but you can set/reset the counter. However...why would you want to?
Title: Re: modelViewProjectionMatrix
Post by: Thomas. on July 24, 2012, 10:17:19 pm
I want to store MVM and IRenderHook in HashMap, render and return all original IRenderHook...

edit: and original shader...
Title: Re: modelViewProjectionMatrix
Post by: EgonOlsen on July 24, 2012, 10:19:42 pm
Ok, but why do you want to reset the id for that?
Title: Re: modelViewProjectionMatrix
Post by: Thomas. on July 24, 2012, 10:32:57 pm
I don't want to reset IDs, I thought, that jPCT can reset them in some cases...
Title: Re: modelViewProjectionMatrix
Post by: EgonOlsen on July 24, 2012, 10:36:36 pm
I misunderstood you there...no, jPCT doesn't reset the id by itself.
Title: Re: modelViewProjectionMatrix
Post by: Thomas. on July 24, 2012, 10:45:10 pm
Ok and IDs are also unique between worlds or not?
Title: Re: modelViewProjectionMatrix
Post by: EgonOlsen on July 24, 2012, 10:48:15 pm
Yes
Title: Re: modelViewProjectionMatrix
Post by: Thomas. on July 24, 2012, 10:51:01 pm
Thanks ;)
Title: Re: modelViewProjectionMatrix
Post by: Thomas. on July 25, 2012, 08:41:44 pm
Could you add method for get RenderHook from Object3D?
Title: Re: modelViewProjectionMatrix
Post by: EgonOlsen on July 27, 2012, 07:45:55 pm
I've added that method. Please download the latest beta jar.
Title: Re: modelViewProjectionMatrix
Post by: Thomas. on July 29, 2012, 08:42:02 pm
I've added that method. Please download the latest beta jar.

Thanks ;) I can set uniforms per object, now.

I've added support for a new uniform called "projectionMatrix" to the beta jar. The model view matrix can be calculated like this (unoptimized):

Code: [Select]
Matrix mc=new Matrix();
Matrix mv=obj.getWorldTransformation();
mc.setTo(world.getCamera().getBack());
SimpleVector v=world.getCamera().getPosition();
v.scalarMul(-1);
mc.translate(v);
mv.matMul(mc);

In these calculations is small bug. If someone will need it, here is fixed code.

Code: [Select]
private Matrix calcModelViewMatrix(World world, Object3D object) {
Camera cam = world.getCamera();
Matrix mc = new Matrix();
Matrix modelView = object.getWorldTransformation();
Matrix backMatrix = cam.getBack();
mc.setTo(backMatrix);
SimpleVector v = cam.getPosition();
v.scalarMul(-1);
modelView.translate(v);
modelView.matMul(mc);
return modelView;
}