Jump to content

How Does BJS Handle Cameras


jerome
 Share

Recommended Posts

Hi,

 

I'm having a look at the excellent bGUI extension code.

I'm wondering how Temechon did to display a vertical orthographic panel in front of the main scene.

 

I'm just discoverying that a BJS scene has an array of active cameras : https://github.com/Temechon/bGUI/blob/master/src/GUISystem.js#L70

 

and meanwhile a single active camera.

 

So I don't really get how two different cameras can be used in the same time ...

I just don't get the global mechanism to tell the engine to render this, this and this with a camera and that, that and that with another one in the same scene, as I can't find in the bGUI code that there would different scenes to be rendered.

 

Seems mysterious to me ...

 

Link to comment
Share on other sites

I found http://doc.babylonjs.com/tutorials/Layermasks_and_Multi-cam_Textures it looks to just apply different view transforms or something based upon the layermask. Sorry, I maybe slightly confused too :huh: (I answered thinking I knew and then realised I was likely wrong)

 

Further edit: This tutorial seems to be better: http://www.pixelcodr.com/tutos/shooter/shooter.html

Link to comment
Share on other sites

Ok

http://doc.babylonjs.com/tutorials/How_to_use_Multi-Views

 

So unless several viewports are declared, the property activeCamera of the Scene object is the camera to be used.

If there are some viewports, a viewport is to be given to each camera added to the scene activeCameras array.

In this case, is the scene property activeCamera  no longer taken in account  ?

 

I can't see bGui uses any viewport in its code : https://github.com/Temechon/bGUI/tree/master/src

 

Still mysterious ...

Link to comment
Share on other sites

Hi !

 

   Yes you are right @jerome, but first they have to be pushed in the activeCameras array.

 

   And just for a test, http://www.babylonjs-playground.com/#1DI7V7#0

 

   But i think bGUI uses 1. Blended scene like i did, 2. Billborded quads (sounds better).

 

  (btw, we used bGUI for Babylonyzer and we found that images are not resized correctly (ratio in our case) when the browser is resized.)

 

   let's ask Julian :D

Link to comment
Share on other sites

Ok

http://doc.babylonjs.com/tutorials/How_to_use_Multi-Views

 

So unless several viewports are declared, the property activeCamera of the Scene object is the camera to be used.

I didn't get that from your linked documentation... I'm not sure that Babylon.js's idea of a viewport is the same as the OpenGL one but from what I see there I'm inclined to think it might be and thus conceive the advice on "needing" viewports might be more the doc writer's assumption about use cases than an actual requirement

ie. suggesting that if one wants to use multiple cameras than the writer thinks it likely that the coder will want to restrict some to small window-like regions of the screen eg. to draw a minimap. For a GUI overlay you want to render over the whole screen buffer but with a different view transform (orthographic, maybe pixel units) so you want a different "camera" (ie. view matrix) but you don't want to change the viewport (from the default)... I'd actually think that would be the more common use case though...

Stvsynrj's post came up while I was writing this, I notice his scene works (and does what I think is expected in such case) if the viewport line is commented

Link to comment
Share on other sites

I remember Stvsysnj just did 2 scenes with 2 different layers... so 2 different calls to render().

 

oops, wrong assumption, sorry !

 

ok, I understand well the Steve's PG.

But not how bGUI does with no viewport at all AND several cameras.

Link to comment
Share on other sites

Ok so I checked the source on Github, all camera have a viewport property and if you don't change it it's still set in the constructor to default to the full screen as per https://github.com/BabylonJS/Babylon.js/blob/e34bc65217cc45935c6b49124a36d26f25e2824d/src/Cameras/babylon.camera.ts

public viewport = new Viewport(0, 0, 1.0, 1.0);
It is just used to set the GL viewport property (ie. it more or less just applies a rectangular clipping region to what's drawn), so I'm certain you don't have to set it to a subregion for additional cameras, just if you don't they will also render the scene fullscene and over the top of the scene as it was rendered for the preceding active camera
Link to comment
Share on other sites

Ok

 

This means each camera has its own viewport by default.

So ? 

If there are several cameras in the scene activeCameras array, they'are all used ? else it's the one refered by the scene.activeCamera property ?

 

not sure ...

Link to comment
Share on other sites

Ok

 

This means each camera has its own viewport by default.

Yeah, but the point was it's not like a class that has lots of state or does lots of stuff, each camera moreorless has a rectangle defined by 2 2d coords, which the engine asks WebGL to clip drawing to (the renderer caches the current rect so when it changes cameras it can avoid call into WebGL if the same numbers are used)

 

If there are several cameras in the scene activeCameras array, they'are all used ? else it's the one refered by the scene.activeCamera property ?

 

not sure ...

That is what the code in babylon.scene.ts looks to do:

 

        public render(): void {
...

            // Multi-cameras?            if (this.activeCameras.length > 0) {                var currentRenderId = this._renderId;                for (var cameraIndex = 0; cameraIndex < this.activeCameras.length; cameraIndex++) {                    this._renderId = currentRenderId;                    this._processSubCameras(this.activeCameras[cameraIndex]);                }            } else {                if (!this.activeCamera) {                    throw new Error("No camera defined");                }                this._processSubCameras(this.activeCamera);            }
processSubCamers() calls _renderForCamera() which I think does the drawing... (reasonably sure but don't hold me to it, complex engine code is complex)
Link to comment
Share on other sites

By default every active camera has the whole screen as viewport. Rendering on top of each other.

processSubCamera is mainly for camera rigs (set of many cameras "acting as one", as for instance stereoscopic cameras).

renderForCamera calls the engine renderer in the camera's point of view (and fov, etc), using also layers and layermask to determine which scene elements to render for the currently rendered camera.

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