Jump to content

Camera view matrix computed for each frame


JulienGobin
 Share

Recommended Posts

Hi everyone,

 

First of all, happy new year and thanks for this amazing webgl engine.

 

I noticed the view matrix of the camera is computed for each frame when BABYLON.Camera.prototype.getViewMatrix is called by BABYLON.Scene.prototype._renderForCamera (called by BABYLON.Scene.prototype.render).

 

BABYLON.Camera.prototype.getViewMatrix is in two parts:

this._computedViewMatrix = this._getViewMatrix();// BABYLON.Camera.prototype._getViewMatrix is overrided in sub-classes (ArcRotateCamera and FreeCamera compute for each frame a matrix and return it)

and

if (this.parent && this.parent.getWorldMatrix) {            if (!this._worldMatrix) {                this._worldMatrix = BABYLON.Matrix.Identity();            }            this._computedViewMatrix.invertToRef(this._worldMatrix);            this._worldMatrix.multiplyToRef(this.parent.getWorldMatrix(), this._computedViewMatrix);            this._computedViewMatrix.invert();            return this._computedViewMatrix;        }

which computes the view matrix if the camera has a parent.

 

Is it on purpose that the view matrix is computed for each frame? Is it better for the memory? (instead of caching values like it's done for the meshes; BABYLON.Mesh.prototype.computeWorldMatrix)

Link to comment
Share on other sites

Ok, thank for your fast reply :) .

I'm already working on a system that makes the job. (Because i really need it), maybe i can send you a pull request when i have finished (tomorrow) ?

 

(I'm also working on a system, based on this first one, that forces the wireframe display when the fps is shutting down when a camera is moving; of course it's optional and parametrable. Will you be interested by it ?).

 

 

Here what i have done so far :

 

http://jsfiddle.net/JulienGobin/7DT4R/

http://jsfiddle.net/JulienGobin/4QhX4/

Link to comment
Share on other sites

Really? I didn't check how you do the wireframe rendering but my first thought would be that's it's faster to render in wireframe mode. Weird. Anyway, I guess what JulienGobin uses here http://jsfiddle.net/JulienGobin/4QhX4/ could be modified to use a fastest material when the camera is moving (instead of wireframe). That's kind of cool.

 

this._scene.activeCamera.forceWireframe would be replaced by this._scene.activeCamera.forceFastestMaterial and the material would be set for the mesh in BABYLON.Mesh.prototype.render

Link to comment
Share on other sites

Thank for your reply, the new pull request (without the wireframe stuff) is here : https://github.com/BabylonJS/Babylon.js/pull/126

 

For the wireframe stuff i'm really surprised that this display mode is worst than the normal one. I will force myself on more test next time ^^'.

(Edit : wrong link, my bad)

Edited by JulienGobin
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...