modelViewProjectionMatrix

Started by Thomas., July 20, 2012, 11:11:34 AM

Previous topic - Next topic

Thomas.

How can I get modelViewProjectionMatrix in code? Is there some getter for this?

EgonOlsen

#1
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?

Thomas.

I need previous MVPM for motion blur...

EgonOlsen

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

Thomas.

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

EgonOlsen

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.

Thomas.

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.

EgonOlsen

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


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

Thomas.

#8
Quote from: EgonOlsen on July 20, 2012, 05:44:06 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?

EgonOlsen

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.

Thomas.

#10
Ok, thanks :) ... Uniforms are for distortions. Motion blur will be by camera, only. For small mobile screens is useless doing anything extra complicated...

Thomas.

#11
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

EgonOlsen

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

Thomas.

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?

EgonOlsen

Where did i wrote that and what did i mean with that... ???