<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-2">
</head>
<body>
<div class="elementToProof" style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Thanks for these thoughts!</div>
<div class="elementToProof" style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div class="elementToProof" style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);" dir="auto">
I see great benefits in reducing draw calls. Many big scenes would not be accessible without this technique....</div>
<div class="elementToProof" style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);" dir="auto">
<br>
</div>
<div class="elementToProof" style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);" dir="auto">
<br>
</div>
<div class="elementToProof" style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);" dir="auto">
I agree we should think about this at the scenegraph level and the requirements...</div>
<div class="elementToProof" style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);" dir="auto">
<br>
</div>
<div class="elementToProof" style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);" dir="auto">
For example , are switches and lods</div>
<div class="elementToProof" style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);" dir="auto">
Allowed under staticgroup?</div>
<div class="elementToProof" style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);" dir="auto">
Can shapes inside them they be animated or used with sensors?</div>
<div class="elementToProof" style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);" dir="auto">
<br>
</div>
<div class="elementToProof" style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);" dir="auto">
The cases and rules could multiply quicky...so what are the rules?</div>
<div class="elementToProof" style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);" dir="auto">
<br>
</div>
<div class="elementToProof" style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);" dir="auto">
Is it just that the geometry and appearance are not changed during run time</div>
<div class="elementToProof" style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);" dir="auto">
?</div>
<div class="elementToProof" style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);" dir="auto">
<br>
</div>
<div class="elementToProof" style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);" dir="auto">
My understanding is that it is the appearance properties that drive such batch drawing.</div>
<div class="elementToProof" style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);" dir="auto">
<br>
</div>
<div class="elementToProof" style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);" dir="auto">
<br>
</div>
<div class="elementToProof" style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);" dir="auto">
And that batching draw calls is distinct from gpu instancing </div>
<div class="elementToProof" style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);" dir="auto">
<br>
</div>
<div class="elementToProof" style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);" dir="auto">
Br,</div>
<div class="elementToProof" style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);" dir="auto">
N</div>
<div class="elementToProof" style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);" dir="auto">
</div>
<ol start="1" data-editing-info="{"applyListStyleFromLevel":true}" data-listchain="__List_Chain_1" style="list-style-type:decimal">
<li style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; display: block; color: rgb(0, 0, 0);">
<div class="elementToProof"><br>
</div>
</li></ol>
<div id="appendonsend"></div>
<hr tabindex="-1" style="display:inline-block; width:98%">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" style="font-size: 11pt; color: rgb(0, 0, 0);"><b>From:</b> x3d-public <x3d-public-bounces@web3d.org> on behalf of Michalis Kamburelis via x3d-public <x3d-public@web3d.org><br>
<b>Sent:</b> Thursday, August 15, 2024 10:05 AM<br>
<b>To:</b> Extensible 3D (X3D) Graphics public discussion <x3d-public@web3d.org><br>
<b>Cc:</b> Michalis Kamburelis <michalis.kambi@gmail.com>; Andreas Plesch <andreasplesch@gmail.com><br>
<b>Subject:</b> Re: [x3d-public] Render optimizations</font>
<div> </div>
</div>
<div class="BodyFragment"><font size="2"><span style="font-size:11pt">
<div class="PlainText">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>
<a href="https://castle-engine.io/apidoc/html/CastleViewport.TCastleViewport.html#DynamicBatching">https://nam04.safelinks.protection.outlook.com/?url=https%3A%2F%2Fcastle-engine.io%2Fapidoc%2Fhtml%2FCastleViewport.TCastleViewport.html%23DynamicBatching&data=05%7C02%7Cnpolys%40vt.edu%7Cf4153cf113214ee288f408dcbd33862e%7C6095688410ad40fa863d4f32c1e3a37a%7C0%7C0%7C638593276240790010%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C0%7C%7C%7C&sdata=dWDyUxgXJXDWOE6NGEBhxVU7xo95wb4yqDR6KGlExR0%3D&reserved=0</a><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 <a href="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/">
https://nam04.safelinks.protection.outlook.com/?url=https%3A%2F%2Fcastle-engine.io%2Fwp%2F2023%2F06%2F30%2Fbig-renderer-improvements-correct-and-automatic-blending-sorting-more-powerful-batching-now-cross-scene-easier-and-more-reliable-occlusion-culling-and-occlusion-sorting%2F&data=05%7C02%7Cnpolys%40vt.edu%7Cf4153cf113214ee288f408dcbd33862e%7C6095688410ad40fa863d4f32c1e3a37a%7C0%7C0%7C638593276240799006%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C0%7C%7C%7C&sdata=3zj75lO%2BGNt2oEgQYOsKRfYfE7VLl015ffpT6cFA2AQ%3D&reserved=0</a><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 ( <a href="https://castle-engine.io/viewport_and_scenes">https://nam04.safelinks.protection.outlook.com/?url=https%3A%2F%2Fcastle-engine.io%2Fviewport_and_scenes&data=05%7C02%7Cnpolys%40vt.edu%7Cf4153cf113214ee288f408dcbd33862e%7C6095688410ad40fa863d4f32c1e3a37a%7C0%7C0%7C638593276240804124%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C0%7C%7C%7C&sdata=rr4YEEwKzJyWOmNpyyR%2FbciQb2t0KBn7LQi2oy9fFoQ%3D&reserved=0</a>
).<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>
<a href="https://github.com/castle-engine/castle-engine/blob/master/src/scene/castleinternalbatchshapes.pas">https://nam04.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fcastle-engine%2Fcastle-engine%2Fblob%2Fmaster%2Fsrc%2Fscene%2Fcastleinternalbatchshapes.pas&data=05%7C02%7Cnpolys%40vt.edu%7Cf4153cf113214ee288f408dcbd33862e%7C6095688410ad40fa863d4f32c1e3a37a%7C0%7C0%7C638593276240808932%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C0%7C%7C%7C&sdata=Z5%2FGgY95qBFcIVUjX0GhlEVu9IybCpZ3IZ5hdU7GUO0%3D&reserved=0</a><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>
><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>
> <a href="http://web3d.org/mailman/listinfo/x3d-public_web3d.org">https://nam04.safelinks.protection.outlook.com/?url=http%3A%2F%2Fweb3d.org%2Fmailman%2Flistinfo%2Fx3d-public_web3d.org&data=05%7C02%7Cnpolys%40vt.edu%7Cf4153cf113214ee288f408dcbd33862e%7C6095688410ad40fa863d4f32c1e3a37a%7C0%7C0%7C638593276240813793%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C0%7C%7C%7C&sdata=Ydzv2CO7GpAFAP5NM0%2FsYwvGu5slcacu6Vj%2B4DO4QnE%3D&reserved=0</a><br>
<br>
_______________________________________________<br>
x3d-public mailing list<br>
x3d-public@web3d.org<br>
<a href="http://web3d.org/mailman/listinfo/x3d-public_web3d.org">https://nam04.safelinks.protection.outlook.com/?url=http%3A%2F%2Fweb3d.org%2Fmailman%2Flistinfo%2Fx3d-public_web3d.org&data=05%7C02%7Cnpolys%40vt.edu%7Cf4153cf113214ee288f408dcbd33862e%7C6095688410ad40fa863d4f32c1e3a37a%7C0%7C0%7C638593276240818630%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C0%7C%7C%7C&sdata=LIqWNX%2FojJzXreHbbJdIz%2FcQNfyBG2zt9RjFC%2B6sQFE%3D&reserved=0</a><br>
</div>
</span></font></div>
</body>
</html>