jerome Posted January 10, 2016 Share Posted January 10, 2016 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 ... Quote Link to comment Share on other sites More sharing options...
chg Posted January 10, 2016 Share Posted January 10, 2016 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 (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 Quote Link to comment Share on other sites More sharing options...
jerome Posted January 10, 2016 Author Share Posted January 10, 2016 Okhttp://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 ... Quote Link to comment Share on other sites More sharing options...
Stvsynrj Posted January 10, 2016 Share Posted January 10, 2016 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 Quote Link to comment Share on other sites More sharing options...
chg Posted January 10, 2016 Share Posted January 10, 2016 Okhttp://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 requirementie. 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 Quote Link to comment Share on other sites More sharing options...
jerome Posted January 10, 2016 Author Share Posted January 10, 2016 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. Quote Link to comment Share on other sites More sharing options...
chg Posted January 10, 2016 Share Posted January 10, 2016 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.tspublic 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 Quote Link to comment Share on other sites More sharing options...
jerome Posted January 10, 2016 Author Share Posted January 10, 2016 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 ... Quote Link to comment Share on other sites More sharing options...
chg Posted January 10, 2016 Share Posted January 10, 2016 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) Quote Link to comment Share on other sites More sharing options...
jerome Posted January 10, 2016 Author Share Posted January 10, 2016 It looks like you found the answer I was looking for thanks Quote Link to comment Share on other sites More sharing options...
Vousk-prod. Posted January 10, 2016 Share Posted January 10, 2016 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. Quote Link to comment Share on other sites More sharing options...
Temechon Posted January 11, 2016 Share Posted January 11, 2016 Wow I'm late to the party...Vousk-prod is right : with no viewport defined, all cameras are rendered in the same view.And Stvsynrj is right too : bGUI does not scale when going full screen. I tried to work on it, but it was more complicated than planed Quote Link to comment Share on other sites More sharing options...
jerome Posted January 11, 2016 Author Share Posted January 11, 2016 Thank you all of you for the great explanations Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.