Author Topic: modelViewProjectionMatrix  (Read 8078 times)

Offline Thomas.

  • double
  • *****
  • Posts: 833
    • View Profile
modelViewProjectionMatrix
« on: July 20, 2012, 11:11:34 am »
How can I get modelViewProjectionMatrix in code? Is there some getter for this?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: modelViewProjectionMatrix
« Reply #1 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?
« Last Edit: July 20, 2012, 12:38:32 pm by EgonOlsen »

Offline Thomas.

  • double
  • *****
  • Posts: 833
    • View Profile
Re: modelViewProjectionMatrix
« Reply #2 on: July 20, 2012, 01:23:05 pm »
I need previous MVPM for motion blur...

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: modelViewProjectionMatrix
« Reply #3 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...

Offline Thomas.

  • double
  • *****
  • Posts: 833
    • View Profile
Re: modelViewProjectionMatrix
« Reply #4 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...
« Last Edit: July 20, 2012, 03:40:26 pm by Thomas. »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: modelViewProjectionMatrix
« Reply #5 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.

Offline Thomas.

  • double
  • *****
  • Posts: 833
    • View Profile
Re: modelViewProjectionMatrix
« Reply #6 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.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: modelViewProjectionMatrix
« Reply #7 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);

Offline Thomas.

  • double
  • *****
  • Posts: 833
    • View Profile
Re: modelViewProjectionMatrix
« Reply #8 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?
« Last Edit: July 23, 2012, 07:26:42 pm by Thomas. »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: modelViewProjectionMatrix
« Reply #9 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.

Offline Thomas.

  • double
  • *****
  • Posts: 833
    • View Profile
Re: modelViewProjectionMatrix
« Reply #10 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...
« Last Edit: July 24, 2012, 09:25:20 pm by Thomas. »

Offline Thomas.

  • double
  • *****
  • Posts: 833
    • View Profile
Re: modelViewProjectionMatrix
« Reply #11 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
« Last Edit: July 24, 2012, 09:35:33 pm by Thomas. »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: modelViewProjectionMatrix
« Reply #12 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).

Offline Thomas.

  • double
  • *****
  • Posts: 833
    • View Profile
Re: modelViewProjectionMatrix
« Reply #13 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?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: modelViewProjectionMatrix
« Reply #14 on: July 24, 2012, 10:03:24 pm »
Where did i wrote that and what did i mean with that... ???