It looks like I’m getting my coordinates wrong.
I’m using an arc rotate camera, and for the portal material I’m using a render target texture, with a shader material to adjust the clipping. The portal seems back-to-front, and no amount of flipping/rotating in the world/camera coordinates, render texture or shader code being able to fix it.
Is this an issue with using an Arc rotate camera? I have tried free cameras, as well as matrix multiplications and quaternions to no avail, as they’re above my maths skill.
Could anyone please help with this? Can provide more information if needed.
J.W
p.s Love Babylonjs! A giant THANK YOU to the team!
I’m trying to re-create a simple portal master/slave camera set-up. The slave camera is rendering its output onto a “portal” texture, which is adjusted by a vert and frag shader.
I cannot get the two cameras to align with the portals properly, and problems rending from backfaces. I think it is my maths, rather than a problem with babylon.
In this pg, I have two “rooms”, one red, and the green one which is showing the inverse rotation needed for the camera. It starts off correct but slowly go out of alignment. I’m using 6 transformNode.roate() (one for each axis x 2) which doesn’t seem right. I’ve tried transformNode.rotation() but cannot get the second “green” room to align properly.
Position and rotation are the correct properties on Babylon. The third column of the world matrix is indeed the translation. For getting the rotation from a matrix you can use getRotationMatrix or decomposeToTransformNode Matrix | Babylon.js Documentation (babylonjs.com)
Not sure if I should add to this thread, or start a new one, but essentially I’m trying to do the same thing with portals and I don’t have much of an understanding of matrix.
Here is what I’ve tried to do to replicate the function from above.
const redMatrix = red._worldMatrix;
const blueMatrix = blue._localMatrix;
const playerCamMatrix = playerCam._worldMatrix;
const matrix = redMatrix
.multiply(blueMatrix)
.multiply(playerCamMatrix);
var position = new Vector3();
var quaternion = new Quaternion();
matrix.decompose(undefined, quaternion, position);
portalCam.position = position;
portalCam.rotationQuaternion = quaternion;
I’ve tried a combination of getWorldMatrix() and getWorldMatrix().invert(), but I’m pretty much shooting in the dark and can’t really find anybody else trying to do the same thing in Babylon.
I think where I’m going wrong is trying to use worldMatrix and localMatrix, but in Unity localToWorldMatrix and worldToLocaMatrix is something different to both, but I’m really not sure!
Is there anyone who understands the Unity functions and knows how to replicate the functionality in Babylon?
localToWorldMatrix should be the result of computeWorldMatrix ( TransformNode | Babylon.js Documentation (babylonjs.com)) and the worldToLocalMatrix is the inverse of this. I agree that it can be confusing with the differences in naming between programs, but this worldMatrix is basically what takes the object’s vertices from its local space to the scene’s space (which is named model matrix here):
In the playground, there are 2 cameras. If you enable the gizmos you can see that one is pointing at the blue portal, what I’m trying to do is make the the red camera look at the red portal in the same way, relatively. But I’ve definitely done something wrong. It sort of tries, but if you rotate/translate the “Blue Camera”, you can see it’s pretty wrong! Any idea what I’m doing wrong?
Sorry to pull up this thread but i have a question.
I’ve added this portal code to my game but in my case the portals are much further away in the level. What is happening is I can get between the portals so that one portal is to the back of the master camera. When this happens, the meshes behind the camera (outside of the view frustrum) seem to be set to invisible and aren’t rendered in the portal cameras.
I understand this is for performance but is there a way to disable the “out of frustrum culling”? I can’t find any documentation on it