<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body style="overflow-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;">Thank you Andreas for this idea. It is an interesting possibility for optimizing geometries. There is nothing like this built into X_ITE yet, but there are already optimizations for StaticGroup and if I were to build something like this (geometry merge), it would be in StaticGroup, as it seems very easy to implement there at first glance. <div><br></div><div>Best regards,</div><div>Holger</div><div><br id="lineBreakAtBeginningOfMessage"><div>
<div dir="auto" style="caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0); letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; overflow-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;"><div dir="auto" style="caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0); letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; overflow-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;"><div dir="auto" style="caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0); letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; overflow-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;"><div dir="auto" style="caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0); letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; overflow-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;"><div dir="auto" style="caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0); letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; overflow-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;"><div dir="auto" style="text-align: start; text-indent: 0px; overflow-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;"><div style="caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0); letter-spacing: normal; text-transform: none; white-space: normal; word-spacing: 0px; text-decoration: none; -webkit-text-stroke-width: 0px;">--</div><div style="caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0); letter-spacing: normal; text-transform: none; white-space: normal; word-spacing: 0px; text-decoration: none; -webkit-text-stroke-width: 0px;">Holger Seelig</div><div style="caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0); letter-spacing: normal; text-transform: none; white-space: normal; word-spacing: 0px; text-decoration: none; -webkit-text-stroke-width: 0px;">Leipzig, Germany</div><div style="caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0); letter-spacing: normal; text-transform: none; white-space: normal; word-spacing: 0px; text-decoration: none; -webkit-text-stroke-width: 0px;"><br></div><div style="caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0); letter-spacing: normal; text-transform: none; white-space: normal; word-spacing: 0px; text-decoration: none; -webkit-text-stroke-width: 0px;">holger.seelig@yahoo.de</div><div>https://create3000.github.io/x_ite/</div></div></div></div></div></div></div>
</div>
<div><br><blockquote type="cite"><div>Am 15.08.2024 um 16:05 schrieb Michalis Kamburelis via x3d-public <x3d-public@web3d.org>:</div><br class="Apple-interchange-newline"><div><div>Castle Game Engine can be told to do this at run-time, it's called<br>DynamicBatching.<br><br>It's just a checkbox really, see<br>https://castle-engine.io/apidoc/html/CastleViewport.TCastleViewport.html#DynamicBatching<br>. In Castle Model Viewer you can activate it with "View -> Dynamic<br>Batching".<br><br>Doing it at run-time has naturally benefits and drawbacks:<br><br>- The benefit of doing it at run-time is that we can "glue" any<br>shapes, not necessarily within StaticGroup.<br><br> We even work "cross-scene", that is in Castle Game Engine you<br>typically display multiple models (X3D, glTF, etc.) in your viewport<br>and we can "glue" into one shapes from various scenes. See e.g. news<br>on https://castle-engine.io/wp/2023/06/30/big-renderer-improvements-correct-and-automatic-blending-sorting-more-powerful-batching-now-cross-scene-easier-and-more-reliable-occlusion-culling-and-occlusion-sorting/<br>when we introduced "cross-scene" batching.<br><br> Doing it at run-time also means we can do it after frustum culling<br>has eliminated shapes outside of frustum. So by "gluing many shapes<br>into one" we don't negate the benefits of frustum culling.<br><br>- The drawback is that effectively DynamicBatching does some<br>additional comparisons and processing at run-time. This consumes time,<br>and can (in theory) defeat the gains of batching. But it practice it<br>(almost) never happens -- the comparisons are rather fast.<br><br>Sometimes it's a huge huge gain. As you say, in some models there's a<br>big opportunity to effectively have 1 draw call instead of thousands<br>-- which translates to big performance gains. And sometimes it's zero<br>gain. I haven't found a case when it's "negative gain", that is when<br>the extra work at run-time done comparing / merging actually<br>outweights the benefits, but I'm sure it exists (I can construct an<br>artificial example of this in my head, but does it happen in real-life<br>usage?).<br><br>All in all, this is a significant feature with some maintenance costs,<br>but it is worth it (on *some* cases).<br><br>We plan to introduce also StaticBatching to do it at load time. For<br>this we plan to invent a way to tell "this model in completely static"<br>-- we don't want to rely on X3D StaticGroup nodes, because<br><br>- Many X3D models don't use them (even when it would make sense). It<br>requires authoring tools support also (e.g. Blender -> X3D exporter to<br>honor some "static" setting from Blender).<br><br>- And other 3D formats (like glTF) don't have a StaticGroup equivalent.<br><br>So we plan to instead have a "Static" checkbox at TCastleScene<br>component ( https://castle-engine.io/viewport_and_scenes ).<br><br>The implementation contains hardcoded a number of rules / comparisons<br>(to compare and merge things that are important visually, and ignore<br>everything else). See<br>https://github.com/castle-engine/castle-engine/blob/master/src/scene/castleinternalbatchshapes.pas<br>. It's of course not perfect, right now it doesn't merge *everything*<br>possible. It is coded carefully, i.e. we're not sure can 2 shapes be<br>merged -> we don't merge (possibly losing performance, but not risking<br>rendering bugs).<br><br>To compare, Unity also has both static and dynamic batching. They<br>probably don't use X3D underneath :), but still the concept underneath<br>is likely similar to what CGE is doing and to what you describe. They<br>also have a checkbox "Static" at GameObjects, to help with this.<br><br>Regards,<br>Michalis<br><br>wt., 13 sie 2024 o 23:12 Andreas Plesch via x3d-public<br><x3d-public@web3d.org> napisaĆ(a):<br><br><blockquote type="cite"><br>I think there may be an opportunity for some relatively simple tools<br>to achieve meaningful rendering improvements using the declarative<br>nature of X3D.<br><br>The idea is that it is much more efficient for (at least for GL based)<br>rendering to send a single draw call with a large object compared to<br>many draw calls with smaller objects. In effect, if it is possible to<br>combine multiple Shapes into a single larger Shape, it can have huge<br>effects on rendering speeds. For example, it is possible to easily<br>render hundreds of thousands of points in a single cloud while it may<br>be nearly impossible to render hundreds of thousands of Shapes with a<br>few points each.<br><br>StaticGroup is designed to help a browser with such optimizations and<br>I was wondering if there are existing tools which already do this,<br>perhaps in a preprocessing step.<br><br>The simplest, while useful tool I can think of is this:<br><br>Inside a StaticGroup, it should be possible to identify Shapes which<br>use the same Appearance (by DEF/USE). We group these Shapes by the<br>drawing primitive they would use (points, lines, triangles). Combining<br>the geometries into a single geometry would be most involved but only<br>considering IndexedFace and TriangleSets should be already useful.<br>Transforms and TextureTransforms would need to be flattened but this<br>can be neatly separated. Finally, a single Shape with the shared<br>Appearance and the combined geometry can replace multiple Shapes.<br><br>The underlying reason for such a tool is that (machine and human)<br>generators and editors tend to produce many Shapes because it is a bit<br>harder to keep track of them and organize them into single, larger<br>objects.<br><br>So any thoughts or pointers to existing X3D optimization tools will be<br>very welcome,<br><br>Andreas<br><br>--<br>Andreas Plesch<br>Waltham, MA 02453<br><br>_______________________________________________<br>x3d-public mailing list<br>x3d-public@web3d.org<br>http://web3d.org/mailman/listinfo/x3d-public_web3d.org<br></blockquote><br>_______________________________________________<br>x3d-public mailing list<br>x3d-public@web3d.org<br>http://web3d.org/mailman/listinfo/x3d-public_web3d.org<br></div></div></blockquote></div><br></div></body></html>