{"id":125851,"date":"2022-06-09T14:00:13","date_gmt":"2022-06-09T14:00:13","guid":{"rendered":"https:\/\/developer.apple.com\/news\/?id=s25p399b"},"modified":"2022-06-09T14:00:13","modified_gmt":"2022-06-09T14:00:13","slug":"challenge-bindless-ray-tracing","status":"publish","type":"post","link":"https:\/\/sickgaming.net\/blog\/2022\/06\/09\/challenge-bindless-ray-tracing\/","title":{"rendered":"Challenge: Bindless ray tracing"},"content":{"rendered":"<div class=\"inline-article-image\"><img decoding=\"async\" src=\"https:\/\/www.sickgaming.net\/blog\/wp-content\/uploads\/2022\/06\/challenge-bindless-ray-tracing.jpg\" data-hires=\"false\" alt><\/div>\n<p>Mirror, mirror on the &#8230; other mirror. In this challenge, we invite you to explore bindless rendering in Metal 3 and reflect rays on mirrored surfaces.<\/p>\n<p>Thanks to the bindless enhancements in Metal 3, the HybridRendering sample app looks better than ever. It makes all scene resources available to its shaders using Argument Buffers, then uses Metal ray tracing to produce reflections on metallic surfaces \u2014 like the ones below. <\/p>\n<div class=\"inline-article-image\"><img decoding=\"async\" src=\"https:\/\/www.sickgaming.net\/blog\/wp-content\/uploads\/2022\/06\/challenge-bindless-ray-tracing-1.jpg\" data-hires=\"false\" alt><\/div>\n<p>But as beautifully as the app has drawn this scene, there\u2019s still a limitation: It\u2019s unable to show reflections <em>within<\/em> reflections, like the mirrored floor reflecting the mirrored sphere.<\/p>\n<p>In fairness: It\u2019s hard to show mirrors reflecting mirrors! Light infinitely bounces between the two surfaces, creating a situation that can\u2019t be solved computationally. Ray tracing apps work around this issue by adding a limited number of light (or ray) \u201cbounces\u201d in the scene to provide more realism.<\/p>\n<p>In this challenge, we invite you to extend that ray tracing code and increase your image\u2019s realism by adding one (or more) extra ray bounces.<\/p>\n<h3>Begin the challenge<\/h3>\n<p>Before entering this hall of mirrors, we recommend first watching &#8220;Go bindless with Metal 3.&#8221; After you watch, download the &#8220;Rendering reflections in real time using ray tracing&#8221; sample code \u2014&nbsp;we&#8217;ll be using it for this challenge.<\/p>\n<section class=\"grid activity\">\n<section class=\"row\">\n<section class=\"column large-4 small-4 no-padding-top no-padding-bottom\"> <a href=\"https:\/\/developer.apple.com\/wwdc22\/10101\" class=\"activity-image-link\"> <img decoding=\"async\" class=\"actiity-image medium-scale\" width=\"250\" src=\"https:\/\/www.sickgaming.net\/blog\/wp-content\/uploads\/2022\/06\/challenge-bindless-ray-tracing-2.jpg\" data-hires=\"false\" alt> <\/a> <\/section>\n<section class=\"column large-8 small-8 padding-left-small padding-top-small padding-bottom-small no-padding-top no-padding-bottom\"> <a href=\"https:\/\/developer.apple.com\/wwdc22\/10101\"> <\/p>\n<h4 class=\"no-margin-bottom activity-title\">Go bindless with Metal 3<\/h4>\n<p class=\"activity-description\">Learn how you can unleash powerful rendering techniques like ray tracing when you go bindless with Metal 3. We&#8217;ll show you how to make your app\u2019s bindless journey a joy by simplifying argument buffers, allocating acceleration structures from heaps, and benefitting from the improvements to the&#8230;<\/p>\n<p> <\/a> <\/section>\n<\/section>\n<\/section>\n<p><a href=\"https:\/\/developer.apple.com\/documentation\/metal\/metal_sample_code_library\/rendering_reflections_in_real_time_using_ray_tracing\" class=\"icon icon-after icon-chevronright\">Rendering reflections in real time using ray tracing<\/a><\/p>\n<p>The app has a dedicated compute pass that calculates reflections from a thin G-Buffer containing positions and normals for each pixel in the image. <\/p>\n<p>The ray tracing shader reads this data and uses it with the camera\u2019s view direction to calculate the direction of the reflected rays. It then uses Metal to trace these rays, find intersections, and shade reflections.<\/p>\n<pre class=\"code-source\"><code>raytracing::ray r;\nr.origin <span class=\"syntax-operator\">=<\/span> positions.read(tid).xyz;\nr.direction <span class=\"syntax-operator\">=<\/span> normalize(directions.read(tid).xyz);\nr.min_distance <span class=\"syntax-operator\">=<\/span> <span class=\"syntax-number\">0.1<\/span>;\nr.max_distance <span class=\"syntax-operator\">=<\/span> <span class=\"syntax-type\">FLT_MAX<\/span>; raytracing::intersector<span class=\"syntax-operator\">&lt;<\/span>raytracing::instancing, raytracing::triangle_data<span class=\"syntax-operator\">&gt;<\/span> inter;\ninter.assume_geometry_type( raytracing::geometry_type::triangle );\nauto intersection <span class=\"syntax-operator\">=<\/span> inter.intersect( r, accelerationStructure, <span class=\"syntax-number\">0xFF<\/span> );\n<span class=\"syntax-keyword\">if<\/span> ( intersection.type <span class=\"syntax-operator\">==<\/span> raytracing::intersection_type::triangle )\n{ }<\/code><\/pre>\n<p>This produces the following image:<\/p>\n<div class=\"inline-article-image\"><img decoding=\"async\" src=\"https:\/\/www.sickgaming.net\/blog\/wp-content\/uploads\/2022\/06\/challenge-bindless-ray-tracing-3.jpg\" data-hires=\"false\" alt><\/div>\n<p>But there\u2019s a problem! The fire trucks are missing from the sphere\u2019s reflection on the floor. We challenge you to reveal the missing trucks by modifying the ray tracing shader, <code>rtReflection<\/code>, to add an additional ray trace step.<\/p>\n<p>To complete this challenge, you\u2019ll:<\/p>\n<ol>\n<li>Use the reflected normal and intersection position to calculate the next bounce of rays.<\/li>\n<li>Extract the material shading logic into a helper function that allows you to shade reflections within the reflections.<\/li>\n<li>Combine all reflected colors and write them into the <code>outImage<\/code>.<\/li>\n<\/ol>\n<p>When you\u2019re done, use the screenshot tool, GPU Debugger, or QuickTime to capture your solution and show us your work by posting it on Twitter with the hashtag #WWDC22Challenges. And if you\u2019d like to discuss bindless ray tracing and other Graphics &amp; Games topics, join the team at events throughout the remainder of the week at WWDC22.<\/p>\n<p><a href=\"https:\/\/twitter.com\/search?q=%23WWDC22Challenges\" class=\"icon icon-after icon-chevronright\">Explore #WWDC22Challenges on social media<\/a><\/p>\n<p><a href=\"https:\/\/developer.apple.com\/wwdc22\/challenges\/terms\/WWDC22_Challenge_Terms_Conditions.pdf\" class=\"icon icon-after icon-chevronright\">Read the WWDC22 Challenges Terms and Conditions<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Mirror, mirror on the &#8230; other mirror. In this challenge, we invite you to explore bindless rendering in Metal 3 and reflect rays on mirrored surfaces. Thanks to the bindless enhancements in Metal 3, the HybridRendering sample app looks better than ever. It makes all scene resources available to its shaders using Argument Buffers, then [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":125852,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[55],"tags":[],"class_list":["post-125851","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-apple-developer-news"],"_links":{"self":[{"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/posts\/125851","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/comments?post=125851"}],"version-history":[{"count":0,"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/posts\/125851\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/media\/125852"}],"wp:attachment":[{"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/media?parent=125851"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/categories?post=125851"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/tags?post=125851"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}