<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Demo &#8211; Jacco&#039;s Blog</title>
	<atom:link href="https://jacco.ompf2.com/category/demo/feed/" rel="self" type="application/rss+xml" />
	<link>https://jacco.ompf2.com</link>
	<description>Links, Code &#38; Articles</description>
	<lastBuildDate>Mon, 20 May 2024 12:56:06 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.8.5</generator>

<image>
	<url>https://jacco.ompf2.com/wp-content/uploads/2019/03/cropped-robotlab-32x32.jpg</url>
	<title>Demo &#8211; Jacco&#039;s Blog</title>
	<link>https://jacco.ompf2.com</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>How to build a BVH &#8211; part 9b: Massive</title>
		<link>https://jacco.ompf2.com/2022/06/15/how-to-build-a-bvh-part-9b-massive/</link>
					<comments>https://jacco.ompf2.com/2022/06/15/how-to-build-a-bvh-part-9b-massive/#comments</comments>
		
		<dc:creator><![CDATA[jbikker]]></dc:creator>
		<pubDate>Wed, 15 Jun 2022 09:30:36 +0000</pubDate>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Demo]]></category>
		<category><![CDATA[Source Code]]></category>
		<category><![CDATA[Tutorial]]></category>
		<guid isPermaLink="false">https://jacco.ompf2.com/?p=1445</guid>

					<description><![CDATA[In this series we explore the wonderful world of the bounding volume hierarchy: the mysterious data structure...]]></description>
										<content:encoded><![CDATA[
<p>In this series we explore the wonderful world of the <em>bounding volume hierarchy:</em> the mysterious data structure that enables real-time ray tracing on recent GPUs, in complex, animated scenes. Despite the broad adoption of ray tracing in games, in-depth understanding of the underlying technology seems to be reserved to a select few. In this article we show how a proper BVH is implemented without support from DXR / RTX / OptiX / Vulkan, in easy-to-read &#8216;sane C++&#8217;. Whether this is actually useful for you, or just interesting as background information, depends on your needs, obviously.</p>



<p>This series consist of ten articles. For each article, full source code is <a href="https://github.com/jbikker/bvh_article">available on Github</a>, in easy-to-read &#8216;Sane C++&#8217;. Contents:</p>



<ol class="wp-block-list">
<li><a href="https://jacco.ompf2.com/2022/04/13/how-to-build-a-bvh-part-1-basics/">Basics: data structure, simple construction and ray traversal</a>.</li>



<li><a href="https://jacco.ompf2.com/2022/04/18/how-to-build-a-bvh-part-2-faster-rays/">Faster rays: the Surface Area Heuristic and ordered traversal</a>.</li>



<li><a href="https://jacco.ompf2.com/2022/04/21/how-to-build-a-bvh-part-3-quick-builds/">Faster construction: binned BVH building</a>.</li>



<li><a href="https://jacco.ompf2.com/2022/04/26/how-to-build-a-bvh-part-4-animation/">BVHs for animated models: refitting and rebuilding</a>.</li>



<li><a href="https://jacco.ompf2.com/2022/05/07/how-to-build-a-bvh-part-5-tlas-blas/">BVHs for animated scenes: the top-level BVH</a>.</li>



<li><a href="https://jacco.ompf2.com/2022/05/13/how-to-build-a-bvh-part-6-all-together-now/">TLAS &amp; BLAS part 2 – all together now</a>.</li>



<li><a href="https://jacco.ompf2.com/2022/05/20/how-to-build-a-bvh-part-7-consolidate/">Consolidating, part 1: ray tracing textured and shaded meshes</a>.</li>



<li><a href="https://jacco.ompf2.com/2022/05/27/how-to-build-a-bvh-part-8-whitted-style/">Consolidating, part 2: Whitted-style ray tracing</a>.</li>



<li><a href="https://jacco.ompf2.com/2022/06/03/how-to-build-a-bvh-part-9a-to-the-gpu/">OpenCL: GPU ray tracing, part 1</a>.</li>



<li><strong>OpenCL: GPU ray tracing, part 2 (SERIES FINAL, this article).</strong></li>



<li>P.S.: Concurrency <em>(under construction)</em></li>
</ol>



<p id="block-0335045c-892a-4222-aee1-ff87a91ce61a">This is the end. Last time we ported the ray tracing code to the GPU, or at least: BLAS traversal and basic visualization. All that is left to do is some cleaning up, and TLAS traversal. With that in place, we will have the same power on CPU and GPU, in terms of animation: we will be able to specify a transform (rotate, translate, scale) for each instance, on top of the capability to rebuild or refit meshes on-the-fly.</p>



<p>In this final article we implement TLAS traversal and the recursive Whitted-style ray tracer on the GPU. For that a few details need to be sorted out. The final product deserves a fitting final demo, for which I will take some inspiration from the <a href="https://www.youtube.com/watch?v=J513nnZyh5o">work of two of my students</a> at Utrecht University.</p>


<div class="wp-block-image">
<figure class="aligncenter size-large is-resized"><img decoding="async" src="https://raw.githubusercontent.com/jbikker/ompf2/main/logsof-1024x374.jpg" alt="" style="width:512px"/><figcaption class="wp-element-caption">Dragons. Lots of dragons.</figcaption></figure></div>


<h2 class="wp-block-heading">Preparations</h2>



<p>To keep the <a href="https://jacco.ompf2.com/2022/06/03/how-to-build-a-bvh-part-9a-to-the-gpu/">article 9a</a> code intact we start with a new file, titled <code>raytracer.cl</code>, which is initially a copy of <code>kernels.cl</code>. The new file will be loaded from <code>::Init()</code> on the CPU side:</p>



<div class="wp-block-urvanov-syntax-highlighter-code-block"><pre class="urvanov-syntax-highlighter-plain-tag">tracer = new Kernel( "cl/raytracer.cl", "render" );</pre></div>



<p>The OpenCL source file currently includes <code>template/common.h</code>. We add <code>cl/tools.h</code>, which currently just contains some functions for generating random numbers.</p>



<div class="wp-block-urvanov-syntax-highlighter-code-block"><pre class="urvanov-syntax-highlighter-plain-tag">#include "cl/tools.h"</pre></div>



<p>We can now move most of the code from raytracer.cl to tools.h. I propose to move the various structs (<code>Intersection</code>, <code>Ray</code>, <code>Tri</code>, <code>TriEx</code>, <code>BVHNode</code>, <code>TLASNode</code> and <code>BVHInstance</code>), as well as the color format conversion function <code>RGB32FtoRGB8</code> and the intersection functions <code>IntersectTri</code> and <code>IntersectAABB</code>. And finally, also <code>BVHIntersect</code>, for BLAS traversal. All that remains in <code>raytracer.cl</code> is then:</p>



<ul class="wp-block-list">
<li><code>float3 Trace(...)</code>, which will replicate the functionality of the Trace function we used on the CPU, and</li>



<li><code>__kernel void render(...)</code>, the OpenCL kernel, which we call from the C++ code.</li>
</ul>



<p>The reorganized code lets us deal with high-level things in <code>raytracer.cl</code>, while the low-level details are hidden away in <code>tools.h</code>.</p>



<p>To match the theme of the article, a new mesh has been added to the assets folder: <code>dragon.obj</code>. </p>


<div class="wp-block-image is-resized">
<figure class="aligncenter size-large"><img decoding="async" src="https://raw.githubusercontent.com/jbikker/ompf2/main/dragonmesh.jpg" alt="" style="width:512px"/></figure></div>


<p>This version of the <a href="https://graphics.stanford.edu/data/3Dscanrep/">Stanford Dragon</a> consists of 19332 triangles, and it replaces the 1024 triangle <a href="https://www.computerhistory.org/revolution/computer-graphics-music-and-art/15/206">Utah teapot</a>. Some changes to the <code>Mesh</code> class are needed to accommodate the larger number of polygons:</p>



<div class="wp-block-urvanov-syntax-highlighter-code-block"><pre class="urvanov-syntax-highlighter-plain-tag">class Mesh
{
public:
    Mesh() = default;
    Mesh( const char* objFile, const char* texFile );
    Tri tri[19500];		// triangle data for intersection
    TriEx triEx[19500];		// triangle data for shading
    ...
};</pre></div>



<p>Similar changes are needed in the implementation of the <code>Mesh</code> constructor.</p>



<div class="wp-block-urvanov-syntax-highlighter-code-block"><pre class="urvanov-syntax-highlighter-plain-tag">Mesh::Mesh( const char* objFile, const char* texFile )
{
    // bare-bones obj file loader; only supports very basic meshes
    texture = new Surface( texFile );
    float2* UV = new float2[11050]; // enough for dragon.obj
    float3* N = new float3[11050], *P = new float3[19500];</pre></div>



<p>Here, 11050 is approximately the number of vertices in the dragon mesh.</p>



<p>With these changes, the code still works, but there is a small issue:</p>


<div class="wp-block-image is-resized">
<figure class="aligncenter size-large"><img decoding="async" src="https://raw.githubusercontent.com/jbikker/ompf2/main/small-1-1024x572.jpg" alt="" style="width:512px"/><figcaption class="wp-element-caption">&#8220;Small&#8221; may be a poorly chosen word.</figcaption></figure></div>


<p>The white shape that obscures the sky is a massive dragon. In the CPU code we would resolve this by assigning a scaling matrix to the instance of the dragon mesh. Or rather: we would apply the inverse of this matrix to the rays that intersects the dragon.</p>



<p>Time to add TLAS traversal.</p>



<h2 class="wp-block-heading">GPU TLAS</h2>



<p>The concept of the TLAS (a.k.a. <em>top level BVH</em>) was introduced in <a href="https://jacco.ompf2.com/2022/05/07/how-to-build-a-bvh-part-5-tlas-blas/">article 5</a> and <a href="https://jacco.ompf2.com/2022/05/13/how-to-build-a-bvh-part-6-all-together-now/">article 6</a>. The idea is to build and traverse a BVH over BVHs, where each of those BVHs can have a 4&#215;4 matrix transform, for translation, rotation, and scaling. Using the same BVH multiple times but with a different matrix enables instancing.</p>



<p>We already have the necessary data on the GPU. There is the <code>TLASNode</code> struct:</p>



<div class="wp-block-urvanov-syntax-highlighter-code-block"><pre class="urvanov-syntax-highlighter-plain-tag">struct TLASNode
{
    float minx, miny, minz;
    uint leftRight; // 2x16 bits
    float maxx, maxy, maxz;
    uint BLAS;
};</pre></div>



<p>And an array of <code>BVHInstance</code> objects, indexed by the <code>BLAS</code> field of the <code>TLASNode</code>:</p>



<div class="wp-block-urvanov-syntax-highlighter-code-block"><pre class="urvanov-syntax-highlighter-plain-tag">struct BVHInstance
{
    uint dummy1, dummy2;
    uint idx;
    float16 transform;
    float16 invTransform; // inverse transform
    uint dummy[6];
};</pre></div>



<p>The strange <code>dummy</code> array at the end is there to ensure that the size and layout of the OpenCL struct matches the CPU struct, at least to the extend that fields <code>transform</code> and <code>invTransform</code> are in the correct location. More on that in a second, because I made some serious mistakes here that need fixing&#8230;</p>



<p>We can now port the <code>TLAS::Intersect(...)</code> method. The process is similar to porting the <code>BVH::Intersect</code> method, so I paste the result here without going over every step in detail.</p>



<div class="wp-block-urvanov-syntax-highlighter-code-block"><pre class="urvanov-syntax-highlighter-plain-tag">void TLASIntersect( struct Ray* ray, struct Tri* tri, 
    struct BVHInstance* bvhInstance, struct TLASNode* tlasNode, 
    struct BVHNode* bvhNode, uint* triIdx )
{
    // initialize reciprocals for TLAS traversal
    ray-&gt;rD = (float3)(1.0f / ray-&gt;D.x, 1.0f / ray-&gt;D.y, 1.0f / ray-&gt;D.z);
    // use a local stack instead of a recursive function
    struct TLASNode* node = &amp;tlasNode[0], *stack[32];
    uint stackPtr = 0;
    // traversl loop; terminates when the stack is empty
    while (1)
    {
        if (node-&gt;leftRight == 0) // isLeaf()
        {
            // current node is a leaf: intersect instance
            InstanceIntersect( ray, &amp;bvhInstance[node-&gt;BLAS], node-&gt;BLAS, tri, bvhNode, triIdx );
            // pop a node from the stack; terminate if none left
            if (stackPtr == 0) break; else node = stack[--stackPtr];
            continue;
        }
        // current node is an interior node: visit child nodes, ordered
        struct TLASNode* child1 = &amp;tlasNode[node-&gt;leftRight &amp; 0xffff];
        struct TLASNode* child2 = &amp;tlasNode[node-&gt;leftRight &gt;&gt; 16];
        float dist1 = IntersectAABB( ray, child1 );
        float dist2 = IntersectAABB( ray, child2 );
        if (dist1 &gt; dist2) 
        { 
            float d = dist1; dist1 = dist2; dist2 = d;
            struct TLASNode* c = child1; child1 = child2; child2 = c;
        }
        if (dist1 == 1e30f)
        {
            // missed both child nodes; pop a node from the stack
            if (stackPtr == 0) break; else node = stack[--stackPtr];
        }
        else
        {
            // visit near node; push the far node if the ray intersects it
            node = child1;
            if (dist2 != 1e30f) stack[stackPtr++] = child2;
        }
    }
}</pre></div>



<p>We call two functions from <code>TLASIntersect</code> that we have not defined yet.</p>



<p>The first one is particularly interesting: We call <code>IntersectAABB</code>, with a <code>TLASNode*</code> rather than a <code>BVHNode*</code>. To my surprise, this <em>just works</em>. The <code>TLASNode</code> struct has, for the purpose of AABB intersection, the same layout as a <code>BVHNode</code>. And OpenCL doesn&#8217;t complain about the pointer type mismatch&#8230; Great, for now, but definitely something to keep in mind: Next time this &#8216;flexibility&#8217; may not be what we expect.</p>



<p>The second function requires more work. Here is the code for <code>InstanceIntersect</code>, based on <code>BVHInstance::Intersect</code> from the CPU code:</p>



<div class="wp-block-urvanov-syntax-highlighter-code-block"><pre class="urvanov-syntax-highlighter-plain-tag">void InstanceIntersect( struct Ray* ray, struct BVHInstance* bvhInstance,
    int blasIdx, struct Tri* tri, struct BVHNode* bvhNode, uint* triIdx )
{
    // backup and transform ray using instance transform
    struct Ray backup = *ray;
    TransformRay( ray, &amp;bvhInstance-&gt;invTransform );
    // traverse the BLAS
    BVHIntersect( ray, blasIdx, tri, bvhNode, triIdx );
    // restore ray without overwriting intersection record
    backup.hit = ray-&gt;hit;
    *ray = backup;
}</pre></div>



<p>This function in turn calls <code>TransformRay</code>, which is defined as follows:</p>



<div class="wp-block-urvanov-syntax-highlighter-code-block"><pre class="urvanov-syntax-highlighter-plain-tag">void TransformRay( struct Ray* ray, float16* invTransform )
{
    // do the transform
    ray-&gt;D = (float3)(
        dot( invTransform-&gt;s012, ray-&gt;D ),
        dot( invTransform-&gt;s456, ray-&gt;D ),
        dot( invTransform-&gt;s89A, ray-&gt;D )
    ); // see TransformVector in template.cpp
    ray-&gt;O = (float3)(
        dot( invTransform-&gt;s012, ray-&gt;O ) + invTransform-&gt;s3,
        dot( invTransform-&gt;s456, ray-&gt;O ) + invTransform-&gt;s7,
        dot( invTransform-&gt;s89A, ray-&gt;O ) + invTransform-&gt;sB
    ); // see TransformPosition in template.cpp
    // update ray direction reciprocals
    ray-&gt;rD = (float3)(1.0f / ray-&gt;D.x, 1.0f / ray-&gt;D.y, 1.0f / ray-&gt;D.z);
}</pre></div>



<p>This implements the <code>TransformVector</code> and <code>TransformPosition</code> matrix functions we used in the CPU code: In OpenCL, we have to implement these ourselves. </p>



<p>Note how the <code>float16</code> data is addressed here: To make a <code>float3</code> out of cells 0, 1 and 2, we write <code>invTransform-&gt;s012</code>. A same technique is available for all OpenCL vector types. For instance, to access <code>x</code> of <code>ray-&gt;D</code> we can simply write <code>ray-&gt;D.x</code>, but we can also get a <code>float2</code> based on the fields: e.g., <code>ray-&gt;D.xy</code>, but also: <code>ray-&gt;D.xx</code>, which would duplicate the first field, or <code>ray-&gt;D.zyx</code>, which would flip the three available fields and yields a <code>float3</code>. Any combination of x, y and z works. The technique is called <em>swizzling</em>. For a float16, x, y and z are obviously insufficient. In this case the fields are labeled 0..9 and A..F (or a..f, if you prefer that): this is the hexadecimal index of the 16 matrix cells.</p>



<h2 class="wp-block-heading">Debugging</h2>



<p>There is a problem with all this new code: <em>it doesn&#8217;t work.</em> When that happens, we debug, of course. But in OpenCL that is easier said than done: Breakpoints do not exist, and would be somewhat pointless anyway, considering that the code runs on (potentially) thousands of GPU threads. We do have some tools however. We can for example use <code>printf</code> from a kernel:</p>



<div class="wp-block-urvanov-syntax-highlighter-code-block"><pre class="urvanov-syntax-highlighter-plain-tag">void TLASIntersect( struct Ray* ray, struct Tri* tri, 
    struct BVHInstance* bvhInstance, struct TLASNode* tlasNode, 
    struct BVHNode* bvhNode, uint* triIdx )
{
    printf( "hello\n" );
    ...</pre></div>



<p>Besides that, we can visualize assumptions. For example:</p>



<div class="wp-block-urvanov-syntax-highlighter-code-block"><pre class="urvanov-syntax-highlighter-plain-tag">float3 Trace( struct Ray* ray, float* skyPixels, struct Tri* triData, struct BVHNode* bvhNodeData, uint* idxData )
{
    // check incoming data
    if (skyPixels == 0 || triData == 0) return (float3)(1, 0, 0);
    ...</pre></div>



<p>In the latter case, <code>Trace</code> will return a red pixel if we passed it an non-existent <code>skyPixels</code> or <code>triData</code> buffer. Other colors can be used to return information on different problems. Since the visualization is per-pixel, this can yield more detailed information than the <code>printf</code>.</p>



<p>With these limited tools I found several issues. The first is in struct <code>TLASNode</code>, which is very similar to <code>BVHNode</code>, and should thus be &#8216;just fine&#8217;:</p>



<div class="wp-block-urvanov-syntax-highlighter-code-block"><pre class="urvanov-syntax-highlighter-plain-tag">struct TLASNode
{
    float minx, miny, minz;
    uint leftRight; // 2x16 bits
    float maxx, maxy, maxz;
    uint BLAS;
};</pre></div>



<p>If this has you scratching your head: look no further, because the problem is not here, it is in the CPU version of this struct.</p>



<div class="wp-block-urvanov-syntax-highlighter-code-block"><pre class="urvanov-syntax-highlighter-plain-tag">// top-level BVH node
struct TLASNode
{
    float3 aabbMin;
    uint leftRight;
    float3 aabbMax;
    uint BLAS;
    bool isLeaf() { return leftRight == 0; }
};</pre></div>



<p>Now, one would assume that the two structs have the same size. Sadly, they don&#8217;t. The <code>float3</code> type takes 16 bytes in OpenCL, and therefore, the CPU-side version mimics this, to ensure data compatibility. We thus have a CPU TLASNode that is substantially larger than 32 bytes.</p>



<p>The problem is quickly resolved by changing the CPU-side struct:</p>



<div class="wp-block-urvanov-syntax-highlighter-code-block"><pre class="urvanov-syntax-highlighter-plain-tag">// top-level BVH node
struct TLASNode
{
    union { struct { float dummy1[3]; uint leftRight; }; float3 aabbMin; };
    union { struct { float dummy2[3]; uint BLAS; }; float3 aabbMax; };
    bool isLeaf() { return leftRight == 0; }
};</pre></div>



<p>That is very ugly, but: Now the two 16-byte structs overlap the <code>float3</code> fields in memory, which causes fields <code>leftRight</code> and <code>BLAS</code> to be exactly in the right location.</p>



<p>After this fix, we still get no useful results out of <code>TLASIntersect</code>. It turns out that there is <em>another </em>problematic struct; this time it is <code>BVHInstance</code>. The struct contains two float16 <code>fields</code>, which have the same size as a <code>mat4</code> in the CPU code. The problem is: OpenCL dictates that any field must be positioned in a struct such that its offset is a multiple of its size. In this case, the size of a <code>float16</code> is 64 bytes; we have only 12 bytes before the first <code>float16</code> and therefore OpenCL will inject 52 unused bytes between field <code>idx</code> and the first transform&#8230;</p>



<p>Fixing this is again easier on the CPU side. We modify the <code>BVHInstance</code> struct to:</p>



<div class="wp-block-urvanov-syntax-highlighter-code-block"><pre class="urvanov-syntax-highlighter-plain-tag">class BVHInstance
{
    ...
    mat4 transform;
    mat4 invTransform; // inverse transform
    aabb bounds; // in world space
    BVH* bvh = 0;
    uint idx;
    int dummy[7];
};</pre></div>



<p>In the new layout, <code>transform</code> and <code>invTransform</code> are properly aligned: <code>transform</code> now has an offset of 0, and <code>invTransform</code> is at offset 64. The array of dummy integers at the end ensures that the size of the whole struct is now a multiple of 64 bytes: This way, in an array of <code>BVHInstances</code> object other than the first also have proper offsets for the <code>float16</code> fields.</p>



<p>With these fixes, we finally have the full TLAS &amp; BLAS functionality on the GPU, albeit without any fancy shading:</p>


<div class="wp-block-image is-resized">
<figure class="aligncenter size-large"><img decoding="async" src="https://raw.githubusercontent.com/jbikker/ompf2/main/gputlas-1024x516.jpg" alt="" style="width:512px"/></figure></div>


<h2 class="wp-block-heading">Restoring Light</h2>



<p>The hard part is now done. Adding some shading is a matter of porting the body of the <code>Trace</code> function. This should not have too many surprises:</p>



<div class="wp-block-urvanov-syntax-highlighter-code-block"><pre class="urvanov-syntax-highlighter-plain-tag">float3 Trace( struct Ray* ray, float* skyPixels, 
    struct BVHInstance* instData, struct TLASNode* tlasData,
    uint* texData, struct Tri* triData, struct TriEx* triExData,
    struct BVHNode* bvhNodeData, uint* idxData )
{
    TLASIntersect( ray, triData, instData, tlasData, bvhNodeData, idxData );
    struct Intersection i = ray-&gt;hit;
    if (i.t == 1e30f)
    {
        // sample sky
        ...
    }
    // calculate texture uv based on barycentrics
    uint triIdx = i.instPrim &amp; 0xfffff;
    uint instIdx = i.instPrim &gt;&gt; 20;
    struct TriEx* tri = triExData + triIdx;
    float2 uv = i.u * tri-&gt;uv1 + i.v * tri-&gt;uv2 + (1 - (i.u + i.v)) * tri-&gt;uv0;
    int iu = (int)(uv.x * 1024) &amp; 1023;
    int iv = (int)(uv.y * 1024) &amp; 1023;
    uint texel = texData[iu + (iv &lt;&lt; 10)];
    float3 albedo = RGB8toRGB32F( texel );
    // calculate the normal for the intersection
    float3 N0 = (float3)( tri-&gt;N0x, tri-&gt;N0y, tri-&gt;N0z );
    float3 N1 = (float3)( tri-&gt;N1x, tri-&gt;N1y, tri-&gt;N1z );
    float3 N2 = (float3)( tri-&gt;N2x, tri-&gt;N2y, tri-&gt;N2z );
    float3 N = i.u * N1 + i.v * N2 + (1 - (i.u + i.v)) * N0;
    N = normalize( TransformVector( &amp;N, &amp;instData[instIdx].transform ) );
    float3 I = ray-&gt;O + i.t * ray-&gt;D;
    // calculate the diffuse reflection in the intersection point
    float3 L = lightPos - I;
    float dist = length( L );
    L *= 1.0f / dist;
    return albedo * (ambient + max( 0.0f, dot( N, L ) ) * lightColor * (1.0f / (dist * dist)));
}</pre></div>



<p>Note that the size of the brick texture is now hardcoded. We&#8217;ll want to change that at a later stage, to make the renderer more versatile. The light source is also still very much hardcoded, as it was in the CPU version. The three constants for the light source can be defined at global scope, somewhere above the <code>Trace</code> function:</p>



<div class="wp-block-urvanov-syntax-highlighter-code-block"><pre class="urvanov-syntax-highlighter-plain-tag">__constant float3 lightPos = (float3)(3, 10, 2);
__constant float3 lightColor = (float3)(150, 150, 120);
__constant float3 ambient = (float3)(0.2f, 0.2f, 0.4f);</pre></div>



<p>To convert pixels read from the texture to float3 we also need a port of the <code>RGB8toRGB32F</code> function. It&#8217;s straightforward, and should go to <code>tools.cl</code>:</p>



<div class="wp-block-urvanov-syntax-highlighter-code-block"><pre class="urvanov-syntax-highlighter-plain-tag">float3 RGB8toRGB32F( uint c )
{
    float s = 1 / 256.0f;
    int r = (c &gt;&gt; 16) &amp; 255;
    int g = (c &gt;&gt; 8) &amp; 255;
    int b = c &amp; 255;
    return (float3)(r * s, g * s, b * s);
}</pre></div>



<p>And finally, transforming the normal vector using the matrix for the intersected instance now uses a new function <code>TransformVector</code>, which in hindsight would come in handy in the <code>TransformRay</code> function as well. It is defined as:</p>



<div class="wp-block-urvanov-syntax-highlighter-code-block"><pre class="urvanov-syntax-highlighter-plain-tag">float3 TransformVector( float3* V, float16* T )
{
    return (float3)( dot( T-&gt;s012, *V ), dot( T-&gt;s456, *V ), dot( T-&gt;s89A, *V ) );
}</pre></div>



<p>And with that we have properly textured and illuminated dragons.</p>


<div class="wp-block-image is-resized">
<figure class="aligncenter size-large"><img decoding="async" src="https://raw.githubusercontent.com/jbikker/ompf2/main/dragonslit-1024x540.jpg" alt="" style="width:512px"/></figure></div>


<h2 class="wp-block-heading">Mirror Mirror</h2>



<p>The next challenge for the OpenCL port of the recursive ray tracer is: Recursion, which we need for mirrors, as well as glass and water (<em>dielectrics</em>). There is however a problem with recursion in OpenCL: <em>It is forbidden</em>. Yet, in the original <code>::Trace</code> function on the CPU, it was rather instrumental to our needs:</p>



<div class="wp-block-urvanov-syntax-highlighter-code-block"><pre class="urvanov-syntax-highlighter-plain-tag">float3 WhittedApp::Trace( Ray&amp; ray, int rayDepth )
{
    ...
    if (mirror)
    {	
        // calculate the specular reflection in the intersection point
        Ray secondary;
        secondary.D = ray.D - 2 * N * dot( N, ray.D );
        secondary.O = I + secondary.D * 0.001f;
        secondary.hit.t = 1e30f;
        if (rayDepth &gt;= 10) return float3( 0 );
        return Trace( secondary, rayDepth + 1 );
    }
    else
    {
        // calculate the diffuse reflection in the intersection point
        ...
    }
}</pre></div>



<p>The highlighted line (line 12) calls the <code>Trace</code> function itself with a just constructed <em>secondary ray</em>, which starts at the intersection point, and extends into the direction calculated using the specular reflection formula on line 8.</p>



<p>Luckily, we have ways to bypass recursion. We already did this to traverse the BVH: Instead of calling <code>BVHIntersect</code> for the left and right child nodes, we switch processing to the nearest child node, while we push the far node on a stack. And, whenever we would normally return, we now pop work from the stack, until the stack is empty.</p>



<p>We can deploy the same scheme here. Except, it will be simpler: Until we add glass or water, the path of a ray does not split up. It ends whenever we hit the skydome, but also when we hit a diffuse object. Only when we hit a reflective dragon we bounce, but in that case we can just restart the Trace function after replacing the original ray by a reflected ray. Like this:</p>



<div class="wp-block-urvanov-syntax-highlighter-code-block"><pre class="urvanov-syntax-highlighter-plain-tag">float3 Trace( ... )
{
    int rayDepth = 0;
    // bounce until we hit the sky or a diffuse surface
    while (rayDepth &lt; 10)
    {
        TLASIntersect( ray, ... );
        struct Intersection i = ray-&gt;hit;
        if (i.t == 1e30f)
        {
            // sample sky
            ...
            return ... ;
        }
        ...           
        if (mirror)
        {
            // calculate the specular reflection in the intersection point
            ray-&gt;D = ray-&gt;D - 2 * N * dot( N, ray-&gt;D );
            ray-&gt;O = I + ray-&gt;D * 0.001f;
            ray-&gt;hit.t = 1e30f;
            rayDepth++;
        }
        else
        {
            // calculate the diffuse reflection in the intersection point
            return ... ;
        }
    }
    return (float3)( 1, 1, 1 );
}</pre></div>



<p>Basically, this loop makes a ray bounce around, until it does <em>not </em>hit a mirror. Of course we need to be careful with infinite &#8216;recursion&#8217; (in this case: an infinite loop). So, we keep track of the &#8216;bounce depth&#8217; and once it exceeds a certain value, we terminate the loop. In that case the last surface we hit must have been a mirror; we thus return white, i.e. <code>(float3)(1, 1, 1)</code>, which is probably better than any other color.</p>



<p>The scheme is quite effective, and brings back the shiny dragons:</p>


<div class="wp-block-image is-resized">
<figure class="aligncenter size-large"><img decoding="async" src="https://raw.githubusercontent.com/jbikker/ompf2/main/shiny-1024x486.jpg" alt="" style="width:512px"/></figure></div>


<h2 class="wp-block-heading">MASSIVE</h2>



<p>One advantage of ray tracing is how it handles massive scenes. For simple scenes, traditional rasterization is typically a lot faster, but at some point, the tables turn. This has everything to do with the BVH: once build (that&#8217;s a rather important condition!), a BVH over <span class="wp-katex-eq" data-display="false">N</span> triangles requires on average <span class="wp-katex-eq" data-display="false">log_2 N</span> steps to get from the root of the tree to a leaf node. For 1,000 triangles we get to a single leaf in 10 steps; for 1,000,000 we get there in 20 steps: Twice the cost, for a thousand times the complexity. Even a <em>billion</em> triangles is doable; this only take three times more work than one thousand.</p>



<p>To put that to the test we will create a scene, in which every vertex of the dragon model is replaced by a dragon. The dragon has 11,042 vertices, and 19,332 polygons; the scene thus will have a bit more than 213 million triangles. You&#8217;ll have to believe me when I say that adding another zero to that number will hardly matter.</p>



<p>The scene is constructed in the <code>::Init()</code> function:</p>



<div class="wp-block-urvanov-syntax-highlighter-code-block"><pre class="urvanov-syntax-highlighter-plain-tag">void MassiveApp::Init()
{
    mesh = new Mesh( "assets/dragon.obj", "assets/bricks.png" );
    // load HDR sky
    ...
    // dragons in the shape of a dragon
    bvhInstance = new BVHInstance[11042];
    for( int i = 0; i &lt; 11042; i++ )
    {
        bvhInstance[i] = BVHInstance( mesh-&gt;bvh, i );
        bvhInstance[i].SetTransform( 
            mat4::Translate( mesh-&gt;P[i] * 0.2f ) * 
            mat4::Scale( 0.0025f  ) *
            mat4::Rotate( mesh-&gt;N[i], 0 ) *
            mat4::RotateX( PI / 2 )
        );
    }
    tlas = TLAS( bvhInstance, 11042 );
    tlas.Build();
    ...</pre></div>



<p>To make that work, the <code>BVHInstance</code> array in the application class definition in <code>massive.h</code> is changed to a pointer:</p>



<div class="wp-block-urvanov-syntax-highlighter-code-block"><pre class="urvanov-syntax-highlighter-plain-tag">BVHInstance* bvhInstance;</pre></div>



<p>The <code>::Init()</code> function needs access to vertex positions and normals. These were stored in local arrays (<code>P</code> and <code>N</code>) in the <code>Mesh</code> constructor. We add pointers to this data to the <code>Mesh</code> class, and make a small change to the <code>Mesh</code> constructor:</p>



<div class="wp-block-urvanov-syntax-highlighter-code-block"><pre class="urvanov-syntax-highlighter-plain-tag">Mesh::Mesh( const char* objFile, const char* texFile )
{
    // bare-bones obj file loader; only supports very basic meshes
    ...
    N = new float3[11043], P = new float3[11043];
    ...</pre></div>



<p>Tiny but important detail: Indices in obj files start at 1; we thus either make the arrays 1 element larger, or subtract 1 from every index that we use &#8211; hence the 11043 figure.</p>



<p>We are almost ready to show the scene: The scene is constructed, the (single) BLAS for the 11,042 dragon instances is built, and we have a TLAS &#8211; which constructs in about half a second on my machine. Half a second: That means the TLAS will have to be static, for now. We thus build it and copy it once to the GPU, in the <code>::Init()</code> function. The <code>tlasData-&gt;CopyToDevice()</code> and <code>instData-&gt;CopyToDevice()</code> commands can now also be moved to ::Init(); we will render a static scene.</p>



<p>If you typed along, you now have a &#8216;dragon of dragons&#8217;, and it runs at a respectable speed.</p>



<h2 class="wp-block-heading">Camera</h2>



<p>Such a scene deserves a proper view.</p>



<p>For that, we will move the camera along a smooth path. The <a href="https://qroph.github.io/2018/07/30/smooth-paths-using-catmull-rom-splines.html">Catmull-Rom spline</a> is ideal for this: it is smooth, and moves through a series of points.</p>


<div class="wp-block-image is-resized">
<figure class="aligncenter size-full"><img fetchpriority="high" decoding="async" width="642" height="378" src="https://jacco.ompf2.com/wp-content/uploads/2022/06/Catmull-Rom_Spline.png" alt="" class="wp-image-1479" style="width:512px" srcset="https://jacco.ompf2.com/wp-content/uploads/2022/06/Catmull-Rom_Spline.png 642w, https://jacco.ompf2.com/wp-content/uploads/2022/06/Catmull-Rom_Spline-300x177.png 300w, https://jacco.ompf2.com/wp-content/uploads/2022/06/Catmull-Rom_Spline-360x212.png 360w" sizes="(max-width: 642px) 100vw, 642px" /><figcaption class="wp-element-caption">One segment of the Catmull-Rom spline, from <span class="wp-katex-eq" data-display="false">P_1</span> to <span class="wp-katex-eq" data-display="false">P_2</span>: we need <span class="wp-katex-eq" data-display="false">P_0</span> and <span class="wp-katex-eq" data-display="false">P_3</span> to define the direction at <span class="wp-katex-eq" data-display="false">P_1</span> and <span class="wp-katex-eq" data-display="false">P_2</span>.</figcaption></figure></div>


<p>Given <span class="wp-katex-eq" data-display="false">P_0 .. P_3</span>, we can find a point on the segment <span class="wp-katex-eq" data-display="false">P_1 .. P_2</span> with the following code:</p>



<div class="wp-block-urvanov-syntax-highlighter-code-block"><pre class="urvanov-syntax-highlighter-plain-tag">float3 CatmullRom( float t, float3&amp; p0, float3&amp; p1, float3&amp; p2, float3&amp; p3 )
{
    float3 c = 2 * p0 - 5 * p1 + 4 * p2 - p3, d = 3 * (p1 - p2) + p3 - p0;
    return 0.5f * (2 * p1 + ((p2 - p0) * t) + (c * t * t) + (d * t * t * t));
}</pre></div>



<p>By varying <span class="wp-katex-eq" data-display="false">t</span> from 0..1, this function allows us to smoothly travel the curve. Once we reach <span class="wp-katex-eq" data-display="false">t=1</span> (or <span class="wp-katex-eq" data-display="false">t=0</span>, if we move backwards), we simply select the next set of four points on the curve; this way, the smooth path can consist of any number of points.</p>



<p>Let&#8217;s take this one step further: If we move not just the camera over a smooth curve, but also a <em>point at which the camera is aimed</em>, we get a pretty versatile camera system. Consider the following set of points:</p>



<div class="wp-block-urvanov-syntax-highlighter-code-block"><pre class="urvanov-syntax-highlighter-plain-tag">float3 spline[] = {
    float3( 1.32, 11.35, 0.31 ), float3( 0.35, 11.56, 0.18 ),
    float3( -0.92, 11.35, 2.92 ), float3( -1.58, 11.55, 2.19 ),
    float3( -5.51, 13.43, 4.96 ), float3( -5.82, 13.63, 4.03 ),
    float3( -10.90, 13.48, 4.53 ), float3( -10.39, 13.68, 3.69 ),
    float3( -13.15, 15.33, 2.21 ), float3( -12.20, 15.52, 1.96 ),
    float3( -12.44, 15.33, -1.92 ), float3( -11.92, 15.51, -1.08 ),
    float3( -8.17, 15.48, -4.71 ), float3( -7.32, 15.38, -4.19 ),
    float3( -0.19, 13.22, -6.09 ), float3( 0.31, 12.72, -5.38 ),
    float3( 8.44, 8.37, -5.22 ), float3( 8.01, 7.81, -4.52 ),
    float3( 14.31, 4.71, -1.89 ), float3( 13.40, 4.46, -1.56 ),
    float3( 11.81, 4.97, 6.36 ), float3( 11.19, 4.65, 5.64 ),
    float3( 10.57, 4.58, 5.19 ), float3( 9.85, 4.39, 4.52 ),
    float3( 7.33, 4.66, 2.14 ), float3( 6.61, 4.59, 1.45 ),
    float3( 6.01, 4.77, 0.68 ), float3( 5.28, 4.70, 0 ),
    float3( 3.00, 4.48, -2.16 ), float3( 2.27, 4.42, -2.85 ),
    float3( -1.53, 4.27, -5.49 ), float3( -1.89, 4.21, -4.56 ),
    float3( -3.63, 4.12, -3.77 ), float3( -3.80, 4.06, -2.78 ),
    float3( -4.97, 3.97, 2.62 ), float3( -5.38, 3.98, 3.53 ),
    float3( -9.38, 3.97, 7.47 ), float3( -8.92, 3.98, 6.59 ),
    float3( -16.17, 5.36, 7.89 ), float3( -15.37, 5.37, 7.29 ),
    float3( -27.30, 10.08, -1.143 ), float3( -26.33, 10.00, -0.89 ),
    float3( -30.81, 10.88, -13.78 ), float3( -29.94, 10.80, -13.30 )
};</pre></div>



<p>Each pair in this array contains one camera position (on the left) and a camera target (on the right). I obtained these points by manually navigating the scene, and recording 20 points to a file. The code for that is left in the program; feel free to replace the spline with a new path.</p>



<p>The camera can now be updated in the <code>::Tick()</code> function, with a little help from the new <code>SplineCam</code> function:</p>



<div class="wp-block-urvanov-syntax-highlighter-code-block"><pre class="urvanov-syntax-highlighter-plain-tag">void SplineCam( int seg, float t )
{
    float3 c0 = spline[seg * 2 - 2],
           c1 = spline[seg * 2],
           c2 = spline[seg * 2 + 2], 
           c3 = spline[seg * 2 + 4];
    float3 t0 = spline[seg * 2 - 1], 
           t1 = spline[seg * 2 + 1], 
           t2 = spline[seg * 2 + 3], 
           t3 = spline[seg * 2 + 5];
    camPos = CatmullRom( t, c0, c1, c2, c3 );
    camTarget = CatmullRom( t, t0, t1, t2, t3 );
}

void MassiveApp::Tick( float deltaTime )
{
    // playback spline path
    static int seg = 1;
    static float t = 0;
    t += deltaTime * 0.0005f;
    if (t &gt; 1) { t -= 1.0f; if (++seg == 20) seg = 1; }
    SplineCam( seg, t );
    mat4 M = mat4::LookAt( camPos, camTarget );
    ...</pre></div>



<p>And with that, we have reached our final destination.</p>


<div class="wp-block-image">
<figure class="aligncenter size-large is-resized"><img decoding="async" src="https://raw.githubusercontent.com/jbikker/ompf2/main/collage-1024x1019.jpg" alt="" style="width:512px"/></figure></div>


<h2 class="wp-block-heading">Bandwidth</h2>



<p>There&#8217;s one thing that is rather silly about the current demo, and it has to do with the template used. It is however a generic thing, so let me explain.</p>



<p>To render an image, the CPU code creates a buffer in VRAM. The OpenCL kernel fills this buffer with pixels. Next, we copy the buffer back to the CPU. And then what? Well, under hood the template maintains a single texture, the size of which matches the window size. The rendered pixels are copied to this texture once per frame, after <code>::Tick()</code> completes. OpenGL is then used to draw a screen filling quad using this texture. This is how a frame ends up on the monitor. We thus have:</p>



<ul class="wp-block-list">
<li>Pixels rendered on the GPU using OpenCL</li>



<li>Pixels transferred to CPU RAM</li>



<li>Pixels copied from CPU RAM to a texture <em>in VRAM</em></li>
</ul>



<p>That feels like a rather long route with unnecessary detours, and it is. Luckily, there is a shortcut, and the name of the shortcut is <em>GL/CL interop</em>. This is a technique where OpenGL makes a resource (in this case: a texture) available to OpenCL, so OpenCL can render directly to it. And this saves time, obviously.</p>



<p>To enable the shortcut, we replace one line in <code>::Init()</code>. The line that currently reads</p>



<div class="wp-block-urvanov-syntax-highlighter-code-block"><pre class="urvanov-syntax-highlighter-plain-tag">target = new Buffer( SCRWIDTH * SCRHEIGHT * 4 );</pre></div>



<p>is to be replaced by</p>



<div class="wp-block-urvanov-syntax-highlighter-code-block"><pre class="urvanov-syntax-highlighter-plain-tag">target = new Buffer( GetRenderTarget()-&gt;ID, 0, Buffer::TARGET );
    screen = 0;</pre></div>



<p>This is inevitably highly template-specific. The first line creates the buffer using an OpenGL texture identifier, obtained from the render target of the template. The second line is used to tell the template to stop sending frames to the OpenGL texture &#8211; we are using OpenCL for that now.</p>



<p>A few more changes are needed. In ::Tick(), we delete the two lines that &#8216;obtain the rendered result&#8217;. And, in the kernel code, the first argument is now different:</p>



<div class="wp-block-urvanov-syntax-highlighter-code-block"><pre class="urvanov-syntax-highlighter-plain-tag">__kernel void render( 
    write_only image2d_t target,
    ...
)
{
    ...
}</pre></div>



<p>And finally, plotting to the target changes. We used a unsigned int array before, but now we have a floating point OpenGL texture to work with. We use the following line to write to it:</p>



<div class="wp-block-urvanov-syntax-highlighter-code-block"><pre class="urvanov-syntax-highlighter-plain-tag">write_imagef( target, (int2)(x, y), (float4)( color, 1 ) );</pre></div>



<p>After this change the demo works again, this time without wasting time sending pixel data back and forth.</p>



<h2 class="wp-block-heading">Future Work</h2>



<p>Where do we go from here? Well, as a wise man once said, you can be &#8220;Ray Tracing &#8211; the Rest of Your Life&#8221;&#8230;</p>



<p><em><strong>Faster BVH building</strong></em> &#8211; The BVH for the dragon is constructed in just a few milliseconds, on a single core. For multiple meshes multiple cores can be used &#8211; until they run out. Take it further by optimizing the BVH builder: Some SIMD magic should bring down the time significantly, and beyond that, well, there&#8217;s ways to make it <em>very </em>fast. An important trick is to build your BVH <em>while the GPU is tracing rays</em>: the only thing that needs to happen between frames is sending the updated data. And even that isn&#8217;t strictly necessary.</p>



<p><em><strong>Faster traversal</strong></em> &#8211; We trace hundreds of millions of rays per second now on the GPU &#8211; without RTX. But, the code is far from optimal&#8230; There are BVH layouts that are better suited for the GPU, and there&#8217;s 4-wide and 8-wide BVHs, which further improve performance. On the CPU packet traversal makes a huge difference, especially for primary rays. By the way, we never implemented proper shadow rays, so that should be on the top of your list.</p>



<p><em><strong>Better rendering</strong></em> &#8211; A few reflecting dragons is nice, but what about more interesting materials, normal maps, depth of field, motion blur, soft shadows, indirect light? This is a field in which you can explore endlessly. Start with basic path tracing, and quickly your code will be too slow again, forcing you to look into filtering techniques and ReSTIR for efficiently sampling many lights. A life is not going to be enough, I&#8217;m afraid.</p>



<p><em><strong>Engine flexibility</strong></em> &#8211; The code of this tutorial is short and hopefully clear, but definitely not robust. Handling multiple meshes and textures and being able to delete them and add them at runtime will require a lot of administration &#8211; especially if you still want to render on the GPU. And while you&#8217;re at it: A fixed-size skydome is not how things should be, obviously. Do mind compile times, once you start cleaning things up: you may have noticed that the tutorial code compiles in a flash, and that&#8217;s not just a lucky accident.</p>



<p><em><strong>OptiX-CL</strong></em> &#8211; NVIDIA provides RTX support from CUDA in the form of a library called OptiX. It would be nice if the functionality of this library became available <em>outside of CUDA</em>, and thus for all devices of all vendors. If you see a challenge here: Let me know! Perhaps we can join forces. Especially the now obsolete OptiX Prime API would be very interesting (and relatively simple) to replicate.</p>



<p><em><strong>Lightouse 2</strong></em> &#8211; Speaking of OptiX: My Lighthouse 2 project uses OptiX to quickly render complex scenes on the GPU, but it is NVIDIA only, essentially. A proper render core using OpenCL or even using the CPU would be great to have. One day, perhaps.</p>


<div class="wp-block-image is-resized">
<figure class="aligncenter size-large"><img decoding="async" width="1024" height="651" src="https://jacco.ompf2.com/wp-content/uploads/2020/02/shot4-1024x651.png" alt="" class="wp-image-480" style="width:600px" srcset="https://jacco.ompf2.com/wp-content/uploads/2020/02/shot4-1024x651.png 1024w, https://jacco.ompf2.com/wp-content/uploads/2020/02/shot4-300x191.png 300w, https://jacco.ompf2.com/wp-content/uploads/2020/02/shot4-768x489.png 768w, https://jacco.ompf2.com/wp-content/uploads/2020/02/shot4-400x254.png 400w, https://jacco.ompf2.com/wp-content/uploads/2020/02/shot4.png 1344w" sizes="(max-width: 1024px) 100vw, 1024px" /><figcaption class="wp-element-caption">Frame from the Lighthouse 2 real-time path tracing benchmark.</figcaption></figure></div>


<p>That&#8217;s just my ideas though. Let me know what your plans are, but whatever you do, keep tracing.</p>



<p>And with that, allow me to sign off for once as if it&#8217;s 1999 on Flipcode:</p>



<p>Love you all,</p>



<p>Jacco Bikker, <em>a.k.a. &#8220;The Phantom&#8221;.</em></p>



<h2 class="wp-block-heading">Closing Remarks</h2>



<p>The complete code for this project, in ten convenient incremental stages, <a href="https://github.com/jbikker/bvh_article">can be found on GitHub</a> (for Windows / Visual Studio).</p>



<p>Enjoyed the article? Spotted an error?</p>



<p>Ping me on Twitter (<a href="https://twitter.com/j_bikker">@j_bikker</a>), comment on this article, or send an email to <a href="mailto:bikker.j@gmail.com">bikker.j@gmail.com</a>.<br>You can also find me on Github:  <a href="https://github.com/jbikker/lighthouse2">https://github.com/jbikker</a>.</p>



<p>Or read some more articles: <a href="https://jacco.ompf2.com">https://jacco.ompf2.com</a>. Some favorites:</p>



<ul class="wp-block-list">
<li><a href="https://jacco.ompf2.com/2019/07/18/wavefront-path-tracing/">Wavefront path tracing</a></li>



<li>Probability Theory for Physically Based Rendering &#8211; <a href="https://jacco.ompf2.com/2019/12/11/probability-theory-for-physically-based-rendering/">part 1</a></li>



<li>Probability Theory for Physically Based Rendering &#8211; <a href="https://jacco.ompf2.com/2019/12/13/probability-theory-for-physically-based-rendering-part-2/">part 2</a></li>



<li><a href="https://jacco.ompf2.com/2020/05/12/opt3simd-part-1-of-2/">OPT#3: SIMD</a> (part 1 of 2) &#8211; <em>also check the other optimization blog posts!</em></li>
</ul>
]]></content:encoded>
					
					<wfw:commentRss>https://jacco.ompf2.com/2022/06/15/how-to-build-a-bvh-part-9b-massive/feed/</wfw:commentRss>
			<slash:comments>4</slash:comments>
		
		
			</item>
		<item>
		<title>Demo: RTX Path Tracer</title>
		<link>https://jacco.ompf2.com/2019/03/28/demo-rtx-path-tracer/</link>
					<comments>https://jacco.ompf2.com/2019/03/28/demo-rtx-path-tracer/#respond</comments>
		
		<dc:creator><![CDATA[jbikker]]></dc:creator>
		<pubDate>Thu, 28 Mar 2019 19:52:54 +0000</pubDate>
				<category><![CDATA[Demo]]></category>
		<guid isPermaLink="false">https://jacco.ompf2.com/?p=39</guid>

					<description><![CDATA[How a link to a demo turns out to be an ad for ompf2.com.]]></description>
										<content:encoded><![CDATA[
<p>This is a link to my in-progress Optix Prime / Optix RTX path tracer:</p>



<p><a href="https://ompf2.com/viewtopic.php?f=8&amp;t=2158">https://ompf2.com/viewtopic.php?f=8&amp;t=2158</a></p>



<p>This also happens to link to the ompf2 forum, which is a great place to find information on ray tracing and related topics, accumulated over the years by many wise members of the community. Now on a new host, with new features such as Latex in comments and embedded media. End of shameless plug.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://jacco.ompf2.com/2019/03/28/demo-rtx-path-tracer/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Demo: Simplex Paternitas</title>
		<link>https://jacco.ompf2.com/2019/03/28/simplex-paternitas/</link>
					<comments>https://jacco.ompf2.com/2019/03/28/simplex-paternitas/#respond</comments>
		
		<dc:creator><![CDATA[jbikker]]></dc:creator>
		<pubDate>Thu, 28 Mar 2019 18:41:47 +0000</pubDate>
				<category><![CDATA[Demo]]></category>
		<guid isPermaLink="false">https://jacco.ompf2.com/?p=26</guid>

					<description><![CDATA[Old real-time path tracing demo: parenting skills.]]></description>
										<content:encoded><![CDATA[
<p>So what do you do when your students have a demo compo, the theme is &#8216;parenting skills&#8217;, and the year is 2011? Well, you path trace something of course. The result is a small demo titled &#8220;Simplex Paternitas&#8221;, which to my suprise is still compatible with modern hardware.</p>



<p>Download from <a href="http://www.pouet.net/prod.php?which=57321">pouet.net</a>.</p>



<p>Or watch it on youtube:</p>



<figure class="wp-block-embed-youtube wp-block-embed is-type-video is-provider-youtube wp-embed-aspect-4-3 wp-has-aspect-ratio"><div class="wp-block-embed__wrapper">
<iframe title="Simplex Paternitas.avi" width="1222" height="917" src="https://www.youtube.com/embed/PaTz9tJ7_KY?feature=oembed" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
</div></figure>
]]></content:encoded>
					
					<wfw:commentRss>https://jacco.ompf2.com/2019/03/28/simplex-paternitas/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
