Amerio.Stephane Posted June 19 Posted June 19 Hello, Here is a test setup: in 2.21, create a new IG project in the default world, create a default sphere and place it at position (0,50,0) run with -extern_plugin UnigineIG,UnigineCIGIConnector -main_window_size 640 480 database_load 1 => the sphere appears in the center of screen with your CIGI emitter of choice, send ViewDefinition with FOV angles (20,-20,-20,20) (top, bottom, left, right). This makes a square FOV. Because the FOV is square but the window is not, the ball appears elongated along its width (this is expected and normal) render_virtual_resolution 480 480 => the view is simply cropped with black bars. Expected result was a screen resize with black bars, in order to have a correct aspect ratio. In 2.20 (and previously), there was visibly a bug in the FOV handling that always lead to a correct FOV ratio. This was correctly fixed in 2.21 (good!) but now the render_virtual_resolution behavior is no longer correct (it never was, but it was not a problem before because of the other bug) Please note that in this example I used a decorated window, but in real life we use Exclusive Fullscreen and we need to match the available display resolution, while still maintaining the correct aspect ratio for the simulated sensor. If render_virtual_resolution is not the correct way to proceed, please advise 🙂 1
bmyagkov Posted June 19 Posted June 19 Hi Stéphane, Thank you for the detailed report and for the clear reproduction steps, this is very helpful. We have already passed the case over to our QA team and are now waiting for their feedback. As soon as we have any information to share, we will come back with an update on the issue, first thing next week. Thanks again for the signal!
bmyagkov Posted June 23 Posted June 23 Hi Stéphane, Thank you for your patience and once again for the very detailed write-up and reproduction steps, they made it really easy for us to track the issue down on our side. After a closer look, this indeed turns out to be a sneaky little bug on our end. The good news is that the actual fix looks pretty straightforward and hopefully it will be included with one of the following 2.21 patches provided through our support ticket form. Thanks again for the signal and sorry for the inconvenience this has caused in the meantime.
Amerio.Stephane Posted June 29 Author Posted June 29 Hello, your latest patch is working for a single window, but it doesn't work with multiple viewports (spidervision). With the attached sensor.sv:sensor.sv render_virtual_resolution -1 -1, square FOV: (left is incorrect - wrong HFOV, right is half-correct - right HFOV but no resize black bars) render_virtual_resolution 600 600, same square FOV: Expected result for all viewports: Of course, in the real world, all viewports may not have a square FOV (each viewport is assigned its own CIGI view ID in code) but this is our most frequent use case. It would be ideal to be able to specify for each viewport its own render_virtual_resolution (maybe render_virtual_resolution_viewport W H id)
bmyagkov Posted June 30 Posted June 30 Hi Stéphane, Thanks for the additional testing and the detailed setup. What you are seeing with the SpiderVision configuration is actually expected behavior and the reason it does not react to render_virtual_resolution the same way a single window does is rooted in how the plugin builds its image. Each SpiderVision viewport is self-contained: the plugin substitutes its own projection matrix and modelview before every frame, computed from the per-viewport parameters stored in the .sv configuration (vertical FOV and aspect for projector-type viewports, or display geometry for display-type ones). The active player camera FOV from the world, and the render_virtual_resolution request applied at the engine level, are intentionally overridden inside the plugin so that the calibrated multi-projector setup stays consistent regardless of what the source camera is doing. That is why the patch you have works for the standalone window (where the engine-level projection is what actually reaches the screen) but does not change anything inside the SV viewports. The second part of what you observe, the image filling the whole window without black bars, comes from the warp stage. By default, when an SV viewport has no warp grid enabled, the plugin renders the result onto a full-window quad (create_square() in the plugin), so the rendered texture is stretched across the entire client area of the window. To get letterbox/pillarbox bars on an SV viewport, the warp grid has to be reshaped accordingly: enable the warp grid for that viewport and move its four corners inward so the warped output occupies a square (or whatever aspect you need) area inside the window, leaving the surrounding pixels black. From the plugin's point of view there is no other place where the aspect of the source FOV would be enforced, the warp is the final layout step. So in short, per-viewport FOV is governed by the .sv configurator and per-viewport "fit" inside the physical output goes through the warp grid. The two are independent, by design. Thanks!
Amerio.Stephane Posted June 30 Author Posted June 30 (edited) Yeah it makes sense, indeed. I'll give it a try this way. Bonus question: is there a way to easily set in code the warp grid? Or must I bake the warp grid in the sv file? EDIT: Shouldn't the HFOV be the same in the left viewport with and without the render_virtual_resolution? This feels like another bug. Edited June 30 by Amerio.Stephane 1
bmyagkov Posted June 30 Posted June 30 Hi Stéphane, Glad to hear the explanation made sense, looking forward to your test results. 59 minutes ago, Amerio.Stephane said: EDIT: Shouldn't the HFOV be the same in the left viewport with and without the render_virtual_resolution? This feels like another bug. That does look a bit suspicious at first glance. We will double-check on our side, but one important thing to keep in mind: since each SpiderVision viewport drives its own projection through the .sv configurator and shapes the final output through the warp stage, you actually do not need render_virtual_resolution at all in the SV scenario. Aspect/letterboxing for a SpiderVision viewport is better expressed by adjusting that viewport's warp, and the main-window render_virtual_resolution can simply be left untouched in this setup, right? 59 minutes ago, Amerio.Stephane said: Bonus question: is there a way to easily set in code the warp grid? Or must I bake the warp grid in the sv file? This can be done from code, see the attached AppWorldLogic.cpp for an example. If the viewport happens to have no warp grid at all, you can initialize one beforehand: viewport->getWarpGrid()->setGridSize(2, 2); viewport->getWarpGrid()->setPointHandleSmoothType(0, SpiderVision::ViewportData::POINT_SMOOTH_TYPE_LINEAR); viewport->getWarpGrid()->setPointHandleSmoothType(1, SpiderVision::ViewportData::POINT_SMOOTH_TYPE_LINEAR); viewport->getWarpGrid()->setPointHandleSmoothType(2, SpiderVision::ViewportData::POINT_SMOOTH_TYPE_LINEAR); viewport->getWarpGrid()->setPointHandleSmoothType(3, SpiderVision::ViewportData::POINT_SMOOTH_TYPE_LINEAR); Thanks! AppWorldLogic.cpp 1
Amerio.Stephane Posted June 30 Author Posted June 30 3 hours ago, bmyagkov said: That does look a bit suspicious at first glance. It definitively looks like a bug. Easy to workaround with a render_virtual_resolution, but as you noted, we shouldn't need that anymore (apart from specific visual fx or fillrate performance). Anyway, it should produce the same aspect ratio with or without if we can use the warp grid instead. Your sample code works great btw, thanks! I just need a way to dynamically set the physical size with the FOV ratio, or diretcly use the FOV (as that is what the customer controls in the end). I use setViewportCustomPlayer to assign a CIGI view to a viewport, but there is no getViewportCustomPLayer, or equivalent to retrieve the player or at least its v/hfov
Amerio.Stephane Posted July 3 Author Posted July 3 @bmyagkov could you help us to retrieve the correct FOV from the viewports? (if not directly possible, I'll find a way around, just trying first to go the easy path if possible)
bmyagkov Posted July 3 Posted July 3 Hi Stéphane, Just to make sure we are on the same page, we are not 100% sure what exactly you would like to end up with on your side, so let me describe how we understood it and please correct us if we are off. Our reading is: you already know the vertical FOV (and either the horizontal FOV or the aspect) on the CIGI side, and what you actually need is a way to push those values into the SV viewport so its physical size and letterboxing follow automatically, rather than a getter for setViewportCustomPlayer. If that is the case, there is no getter counterpart to setViewportCustomPlayer, but you also do not really need to read the FOV back from the viewport since you already have it. A small helper like this should do the job: void setup_viewport(SpiderVision::ViewportData *viewport, float vfov, float aspect, bool resize_window) { float sy = 2.0f * Math::tan(vfov * Consts::DEG2RAD * 0.5f); float sx = aspect * sy; viewport->setSize(vec2(sx, sy)); viewport->setPosition(vec3(0.0f, 1.0f, 0.0f)); viewport->setRotation(vec3(90.0f, 0.0f, 0.0f)); auto window_size = viewport->getWindowSize(); float window_aspect = toFloat(window_size.x) / toFloat(window_size.y); float scale_x = min(1.0f, aspect / window_aspect); float scale_y = min(1.0f, window_aspect / aspect); viewport->getWarpGrid()->setGridSize(2, 2); viewport->getWarpGrid()->setPointHandleSmoothType(0, SpiderVision::ViewportData::POINT_SMOOTH_TYPE_LINEAR); viewport->getWarpGrid()->setPointHandleSmoothType(1, SpiderVision::ViewportData::POINT_SMOOTH_TYPE_LINEAR); viewport->getWarpGrid()->setPointHandleSmoothType(2, SpiderVision::ViewportData::POINT_SMOOTH_TYPE_LINEAR); viewport->getWarpGrid()->setPointHandleSmoothType(3, SpiderVision::ViewportData::POINT_SMOOTH_TYPE_LINEAR); viewport->getWarpGrid()->setPoint(0, vec2(-1.0f, -1.0f)); viewport->getWarpGrid()->setPoint(1, vec2(-1.0f, 1.0f)); viewport->getWarpGrid()->setPoint(2, vec2(1.0f, -1.0f)); viewport->getWarpGrid()->setPoint(3, vec2(1.0f, 1.0f)); if (resize_window) { viewport->setWindowSize(ivec2(window_size.x * scale_x, window_size.y * scale_y)); } else { viewport->getWarpGrid()->setPoint(0, vec2(-scale_x, -scale_y)); viewport->getWarpGrid()->setPoint(1, vec2(-scale_x, scale_y)); viewport->getWarpGrid()->setPoint(2, vec2(scale_x, -scale_y)); viewport->getWarpGrid()->setPoint(3, vec2(scale_x, scale_y)); } } If it is more convenient for you to work with vfov and hfov directly instead: float sy = 2.0f * Math::tan(vfov * Consts::DEG2RAD * 0.5f); float sx = 2.0f * Math::tan(hfov * Consts::DEG2RAD * 0.5f); float aspect = sx / sy; Does this match what you were after, or did you have a different flow in mind? Thanks!
Amerio.Stephane Posted July 3 Author Posted July 3 Hi, thanks for the code sample. But my "issue" here is that the code that receive the FOV (on_process_view_def) and our spidervision modules are managed by two different plugins at the moment, so they don't clearly communicate with one another. Just a software-archtitecture choice, really. The easy way would have been to get the player back from the viewport management code (an hypothetic getViewportPlayer, non-existent at this time). No worries, though, I'll work around it. Again, thanks for the code sample!
bmyagkov Posted July 3 Posted July 3 You're right that there's no getViewportPlayer in the shape you were hoping for. But you can reach the camera of a given viewport through the public SpiderVision API: SpiderVision::Manager::get()->getEngineWindow(viewport_id)->getCamera(); And if you ever need to go the other direction and recover the FOV from a viewport's geometry, here are the two derivations. Vertical FOV: mat4 rot = composeRotationXYZ(viewport->getRotation()) * scale(viewport->getSize().x, viewport->getSize().y, 1); vec3 tangent = rot.getColumn3(0); vec3 binormal = rot.getColumn3(1); vec3 position = viewport->getPosition(); // view basis vec3 normal = normalize(cross(tangent, binormal)); vec3 right = normalize(tangent); vec3 up = normalize(binormal); // projection matrix float scale = -1.0f / dot(normal, position); float l = dot(right, position - tangent * 0.5f) * scale; float r = dot(right, position + tangent * 0.5f) * scale; float b = dot(up, position - binormal * 0.5f) * scale; float t = dot(up, position + binormal * 0.5f) * scale; float vfov = Math::atan(t) - atan(b); Horizontal FOV: mat4 rot = composeRotationXYZ(viewport->getRotation()) * scale(viewport->getSize().x, viewport->getSize().y, 1); vec3 tangent = rot.getColumn3(0); vec3 binormal = rot.getColumn3(1); vec3 position = viewport->getPosition(); // view basis vec3 normal = normalize(cross(tangent, binormal)); vec3 right = normalize(tangent); vec3 up = normalize(binormal); // projection matrix float scale = -1.0f / dot(normal, position); float l = dot(right, position - tangent * 0.5f) * scale; float r = dot(right, position + tangent * 0.5f) * scale; float b = dot(up, position - binormal * 0.5f) * scale; float t = dot(up, position + binormal * 0.5f) * scale; float hfov = Math::atan(r) - atan(l); This may not be exactly what you're after, but hopefully it helps you move forward on the architecture side. Thanks! 1
Amerio.Stephane Posted July 8 Author Posted July 8 On 6/30/2026 at 11:14 AM, bmyagkov said: On 6/30/2026 at 10:12 AM, Amerio.Stephane said: EDIT: Shouldn't the HFOV be the same in the left viewport with and without the render_virtual_resolution? This feels like another bug. That does look a bit suspicious at first glance. We will double-check on our side Just a quick follow up on this specific issue. I found out that the main window has setAspectCorrection(false) while the others have setAspectCorrection(true) by default (NOT something we used to set up in code). And more importantly, render_virtual_resolution does have an impact on this, as it will simply disregard the window aspect correction flag. => in the end, it's easy to fix on our side (setAspectCorrection(false) on every window); but you may want to check on your side that the current behavior is what you really want and document (different settings on main and other viewports and render_virtual_resolution) 1
Recommended Posts