<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: kvickan</title>
    <description>The latest articles on DEV Community by kvickan (@kvickan).</description>
    <link>https://dev.to/kvickan</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4125871%2F529a93df-0330-46d5-a503-ba5c46c92524.png</url>
      <title>DEV Community: kvickan</title>
      <link>https://dev.to/kvickan</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/kvickan"/>
    <language>en</language>
    <item>
      <title>Sharing scene transforms across multiple Three.js render passes</title>
      <dc:creator>kvickan</dc:creator>
      <pubDate>Tue, 15 Sep 2026 09:07:25 +0000</pubDate>
      <link>https://dev.to/kvickan/sharing-scene-transforms-across-multiple-threejs-render-passes-5dhd</link>
      <guid>https://dev.to/kvickan/sharing-scene-transforms-across-multiple-threejs-render-passes-5dhd</guid>
      <description>&lt;p&gt;A scene can be rendered several times for one displayed frame: the main view, a reflection, and an ambient-occlusion pass may all need the same object poses. In my browser game Vesper, I keep animation and transform preparation ahead of those render passes.&lt;/p&gt;

&lt;p&gt;This article was prepared with generative AI and is labeled Fully Autonomous. I used GPT-6 Astra in Codex during the game's development too; that is separate from the authorship of this article.&lt;/p&gt;

&lt;h2&gt;
  
  
  One set of poses, several cameras
&lt;/h2&gt;

&lt;p&gt;A child mesh inherits its parent's transform. An animated skeleton adds another dependency: bones must reach their world-space poses before a pass reads them. If different passes update that hierarchy independently, the code does repeated work and makes the ordering harder to reason about.&lt;/p&gt;

&lt;p&gt;The current implementation uses this small wrapper, from &lt;code&gt;src/scene-frame.ts&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="kd"&gt;type&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;Scene&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;three&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="cm"&gt;/** Animation is finished before submission. Main, reflection and AO cameras
 * share those transforms; their render callbacks change visibility, not poses.
 * Keep camera updates automatic, and restore the scene policy even on failure. */&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;renderSceneFrame&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;scene&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="nx"&gt;Scene&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nx"&gt;render&lt;/span&gt;&lt;span class="p"&gt;:()&lt;/span&gt;&lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;&lt;span class="k"&gt;void&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
 &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;automatic&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nx"&gt;scene&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;matrixWorldAutoUpdate&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
 &lt;span class="nx"&gt;scene&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;updateMatrixWorld&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
 &lt;span class="nx"&gt;scene&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;matrixWorldAutoUpdate&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
 &lt;span class="k"&gt;try&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nf"&gt;render&lt;/span&gt;&lt;span class="p"&gt;();}&lt;/span&gt;&lt;span class="k"&gt;finally&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;scene&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;matrixWorldAutoUpdate&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nx"&gt;automatic&lt;/span&gt;&lt;span class="p"&gt;;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The ordering is the contract:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Finish animation and object movement.&lt;/li&gt;
&lt;li&gt;Update the scene's world matrices once.&lt;/li&gt;
&lt;li&gt;Submit all the views that share those poses.&lt;/li&gt;
&lt;li&gt;Restore the original automatic-update policy.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The wrapper changes the scene's policy, leaving camera updates automatic. The &lt;code&gt;finally&lt;/code&gt; matters: a failed render should not leave the scene stuck in a different update mode on the next frame. It also restores an originally false setting correctly.&lt;/p&gt;

&lt;h2&gt;
  
  
  The constraint that makes this useful
&lt;/h2&gt;

&lt;p&gt;Render callbacks may change visibility, but they must not move objects or change bone poses after the shared matrix update. A reflection that temporarily moves geometry would violate this contract. Such a pass needs a different update boundary or an explicit additional transform update.&lt;/p&gt;

&lt;p&gt;This is a scheduling choice for this renderer. It is not a general instruction to disable automatic updates in every Three.js project. The code here targets the project's installed Three.js 0.180 setup.&lt;/p&gt;

&lt;h2&gt;
  
  
  What the checks establish
&lt;/h2&gt;

&lt;p&gt;The existing focused tests exercise a parent/child hierarchy and animated bone poses across four simulated render passes. They assert that the transforms are current and that scene preparation happens once. A second test throws inside the render callback and checks restoration for both original policy values.&lt;/p&gt;

&lt;p&gt;On September 15, 2026, &lt;code&gt;npm run test:focus -- tests/scene-frame.test.ts&lt;/code&gt; completed with &lt;strong&gt;2 passing tests and no failures&lt;/strong&gt;. These checks cover the transform contract and error cleanup. They do not measure a frame-rate gain, GPU cost, or performance on a phone.&lt;/p&gt;

&lt;p&gt;The live implementation is part of &lt;a href="https://vesper.mansgullberg.chatgpt.site/" rel="noopener noreferrer"&gt;Vesper - The Last Light&lt;/a&gt;, a Three.js browser adventure with reflective flooded areas. The takeaway is small: define when poses become stable, share that state only across compatible passes, and restore temporary rendering policy even when a pass fails.&lt;/p&gt;

</description>
      <category>threejs</category>
    </item>
  </channel>
</rss>
