Jump to content

Camera Up Vector


Gaume
 Share

Recommended Posts

I'm trying, using my own shader, to make a billboard  using a predefined XZ plane mesh. 

to do so, i first build the necessary vector (into my own material) to pass to the shader,

                var cam = scene.activeCamera;
                var look = cam.position.subtract(mesh.position).normalize();
                var view = scene.getViewMatrix();
                var up = new BABYLON.Vector3(view.m[1], view.m[5], view.m[9]);
                var right = BABYLON.Vector3.Cross(up, look);

                this._effect.setMatrix(__world_str, world);
                this._effect.setMatrix(__worldViewProjection_str, world.multiply(scene.getTransformMatrix()));
                this._effect.setVector3(__upVector_str, up);
                this._effect.setVector3(__rightVector_str, right);
                this._effect.setVector3(__center_str, mesh.position);

then use the values into the shader as :

	vec3 newp = center + (upVector * position.x) + (rightVector * position.z);
	vec4 outPosition = worldViewProjection * vec4(newp, 1.);
	gl_Position = outPosition;

where center is the center of the billboard.

I use an ArcRotateCamera.

However, this is NOT render properly. The plane is ALWAYS facing the camera, which is good, BUT it strectch vertically when spining arround.. What i have missed ??? 

Capture10.JPG

Capture11.JPG

Link to comment
Share on other sites

Hi Guy, found the solution..

the code is correct, was a scalling not set correctly on Y into the mesh and while the scalling is apply after the tranformation (part of the world matrix), it's strech the mesh on X and Z but NOT on Y. I let the code for thus interested by the billboard shader subject.

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