<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>puray on Arunrocks</title>
    <link>https://arunrocks.com/tags/puray/</link>
    <description>Recent articles in puray on Arunrocks</description>
    <generator>Hugo -- gohugo.io</generator>
    <language>en-us</language>
    <lastBuildDate>Mon, 17 Aug 2020 12:08:10 +0530</lastBuildDate><atom:link href="https://arunrocks.com/tags/puray/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>Ray Tracer in Python (Part 6) - Show Notes of &#34;Firing All Cores&#34;</title>
      <link>https://arunrocks.com/ray-tracer-in-python-part-6-of-firing-all-cores/</link>
      <pubDate>Mon, 17 Aug 2020 12:08:10 +0530</pubDate>
      
      <guid>https://arunrocks.com/ray-tracer-in-python-part-6-of-firing-all-cores/</guid>
      <description>

&lt;div class=&#34;series-box&#34;&gt;
  &lt;p&gt;You are reading a post from a multi-part series of articles&lt;/p&gt;
  &lt;ol&gt;
    
    &lt;li&gt;
      &lt;a href=&#34;https://arunrocks.com/ray-tracer-in-python-1-points-in-3d-space-show-notes/&#34;&gt;Ray Tracer in Python (Part 1) - Show Notes of &amp;#34;Points in 3D Space&amp;#34;&lt;/a&gt;
      &lt;/li&gt;
    
    &lt;li&gt;
      &lt;a href=&#34;https://arunrocks.com/ray-tracer-in-python-2-revealing-the-true-colors/&#34;&gt;Ray Tracer in Python (Part 2) - Show Notes of &amp;#34;Revealing the True Colors&amp;#34;&lt;/a&gt;
      &lt;/li&gt;
    
    &lt;li&gt;
      &lt;a href=&#34;https://arunrocks.com/ray-tracer-in-python-3-3d-balls-in-2d-space/&#34;&gt;Ray Tracer in Python (Part 3) - Show Notes of &amp;#34;3D Balls in 2D Space&amp;#34;&lt;/a&gt;
      &lt;/li&gt;
    
    &lt;li&gt;
      &lt;a href=&#34;https://arunrocks.com/ray-tracer-in-python-part-4-let-there-be-light/&#34;&gt;Ray Tracer in Python (Part 4) - Show Notes of &amp;#34;Let there be light&amp;#34;&lt;/a&gt;
      &lt;/li&gt;
    
    &lt;li&gt;
      &lt;a href=&#34;https://arunrocks.com/ray-tracing-a-coronavirus-in-puray-python/&#34;&gt;Ray Tracer in Python - Show Notes of &amp;#34;Ray Tracing a Coronavirus&amp;#34;&lt;/a&gt;
      &lt;/li&gt;
    
    &lt;li&gt;
      &lt;a href=&#34;https://arunrocks.com/ray-tracer-in-python-part-5-light-reflections/&#34;&gt;Ray Tracer in Python (Part 5) - Show Notes of &amp;#34;Some Light Reflections&amp;#34;&lt;/a&gt;
      &lt;/li&gt;
    
    &lt;li&gt;Ray Tracer in Python (Part 6) - Show Notes of &amp;#34;Firing All Cores&amp;#34;&lt;/li&gt;
    &lt;/ol&gt;
&lt;/div&gt;

&lt;p&gt;When it comes to code optimization, there is an overused statement about Premature Optimization. Here is the rarely-shown full quote:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&amp;ldquo;Programmers waste enormous amounts of time thinking about, or worrying about, the speed of noncritical parts of their programs, and these attempts at efficiency actually have a strong negative impact when debugging and maintenance are considered. We should forget about small efficiencies, say about 97% of the time: &lt;strong&gt;premature optimization is the root of all evil&lt;/strong&gt;. Yet we should not pass up our opportunities in that critical 3%.&amp;rdquo; &amp;ndash; Donald Knuth&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;I understand this as not worrying about small optimizations all the time. It is best to focus on the areas which have the most return on (time) investment. Usually you need to do extensive performance measurements to find those areas but there are some natural places to look.&lt;/p&gt;
&lt;p&gt;So far, we have been not too concerned about performance especially when it affected readability (else we wouldn&amp;rsquo;t be writing it in Python). However, in the previous part we got a huge speedup by switching to the PyPy interpreter.&lt;/p&gt;
&lt;p&gt;To me the next big opportunity lies in using all the cores. As an experienced Python programmer, I know this means using the &lt;a href=&#34;https://docs.python.org/3/library/multiprocessing.html&#34;&gt;multiprocessing module&lt;/a&gt;. But I also need to explain why other options, notably Python threads, would not help.&lt;/p&gt;
&lt;p&gt;To demonstrate this I wrote a multi-threaded C program, a multi-threaded Python program and a multi-processing Python program - all doing the same thing. What was most entertaining was to watch the GIL in action where it allows only one thread to execute at a time.&lt;/p&gt;
&lt;h2 id=&#34;race-conditions&#34;&gt;Race Conditions&lt;/h2&gt;
&lt;p&gt;Race conditions are often explained using a bank ATM example. I think it can be explained in a non technical way using many real life scenarios. I wanted to explain it using a cooking example. It&amp;rsquo;s weird how many asynchronous and parallel concepts can be taught using what we do in the kitchen. So much so that technical job interviews can be made more effective by simply checking your culinary skills (&amp;ldquo;Sorry we don&amp;rsquo;t have a whiteboard, just a cutting board for you.&amp;quot;).&lt;/p&gt;
&lt;p&gt;Ideally the entire explanation should be animated. My drawing skills are decent but I cannot animate even a bouncing ball. Don&amp;rsquo;t laugh, just try it. Firstly, there are several cues that any animated object gives which can be only be detected if you watch in slow motion. &lt;a href=&#34;https://en.wikipedia.org/wiki/Twelve_basic_principles_of_animation&#34;&gt;The Twelve Principles of Animation&lt;/a&gt; is a good start.&lt;/p&gt;
&lt;p&gt;Secondly, it is a lot of work. A good animator will know how to give maximum expression with the minimum frames. Timing is also crucial in animation. Even a subtle timing error makes animations look janky or confusing. Mere mortals would need to spend days to eventually produce a 5 second clip.&lt;/p&gt;
&lt;p&gt;&lt;figure&gt;
    &lt;img loading=&#34;lazy&#34; src=&#34;https://arunrocks.com/static/images/blog/race-bakery.png&#34; alt=&#34;Race Conditions&#34;  title=&#34;Animating the Race Conditions&#34;  width=1920 height=&#34;1080&#34;  /&gt;
    &lt;figcaption&gt;Animating the Race Conditions&lt;/figcaption&gt;
  &lt;/figure&gt;&lt;/p&gt;
&lt;p&gt;So I took the safe approach by showing a slideshow. I think it looks decent. I might post it as a separate clip on Race Conditions so that is doesn&amp;rsquo;t get lost in this video.&lt;/p&gt;
&lt;p&gt;These are the topics we will cover in this episode:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Introduction
&lt;ul&gt;
&lt;li&gt;An Embarrassingly Parallel Problems&lt;/li&gt;
&lt;li&gt;What&amp;rsquo;s a Thread?&lt;/li&gt;
&lt;li&gt;Threads in C&lt;/li&gt;
&lt;li&gt;Threads in Python&lt;/li&gt;
&lt;li&gt;Race Condition Animated&lt;/li&gt;
&lt;li&gt;Why Python has GIL&lt;/li&gt;
&lt;li&gt;Multi-processing in Python&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Sub-problem: Firing All Cores&lt;/li&gt;
&lt;li&gt;Coding the solution
&lt;ul&gt;
&lt;li&gt;Command-line argument&lt;/li&gt;
&lt;li&gt;Diving pixels among processes&lt;/li&gt;
&lt;li&gt;Passing Data via Files&lt;/li&gt;
&lt;li&gt;Value for Progressbar&lt;/li&gt;
&lt;li&gt;Bug Hunting&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Performance Comparison&lt;/li&gt;
&lt;li&gt;Topics Not Covered&lt;/li&gt;
&lt;li&gt;Learning More&lt;/li&gt;
&lt;li&gt;Final Words&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Here is the video:

&lt;div style=&#34;position: relative; padding-bottom: 56.25%; height: 0; overflow: hidden;&#34;&gt;
  &lt;iframe src=&#34;https://www.youtube.com/embed/GZ2reWs4_qY&#34; style=&#34;position: absolute; top: 0; left: 0; width: 100%; height: 100%; border:0;&#34; allowfullscreen title=&#34;YouTube Video&#34;&gt;&lt;/iframe&gt;
&lt;/div&gt;
&lt;/p&gt;
&lt;p&gt;Code for part six is tagged on the &lt;a href=&#34;https://github.com/arocks/puray/tree/episode06&#34;&gt;Puray Github project&lt;/a&gt;&lt;/p&gt;
&lt;h3 id=&#34;show-notes&#34;&gt;Show Notes&lt;/h3&gt;
&lt;p&gt;Books and articles that can help understand this part:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;https://amzn.to/3141v7j&#34;&gt;The Art of Multiprocessor Programming&lt;/a&gt; book&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://amzn.to/2WzdwPh&#34;&gt;The Ray Tracer Challenge&lt;/a&gt; book&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://raytracing.github.io/&#34;&gt;Ray Tracing in One Weekend&lt;/a&gt; free books&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://news.developer.nvidia.com/ray-tracing-essentials-part-1-basics-of-ray-tracing/&#34;&gt;NVIDIA Ray Tracing Essentials&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;em&gt;Note: References may contain affiliate links&lt;/em&gt;&lt;/p&gt;
&lt;h2 id=&#34;wrapping-up&#34;&gt;Wrapping up&lt;/h2&gt;
&lt;p&gt;This concludes the ray tracing series that I had conceived more than a year back. If you make your own ray tracer, please don&amp;rsquo;t forget to tag me.&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>Ray Tracer in Python (Part 5) - Show Notes of &#34;Some Light Reflections&#34;</title>
      <link>https://arunrocks.com/ray-tracer-in-python-part-5-light-reflections/</link>
      <pubDate>Tue, 12 May 2020 22:08:10 +0530</pubDate>
      
      <guid>https://arunrocks.com/ray-tracer-in-python-part-5-light-reflections/</guid>
      <description>

&lt;div class=&#34;series-box&#34;&gt;
  &lt;p&gt;You are reading a post from a multi-part series of articles&lt;/p&gt;
  &lt;ol&gt;
    
    &lt;li&gt;
      &lt;a href=&#34;https://arunrocks.com/ray-tracer-in-python-1-points-in-3d-space-show-notes/&#34;&gt;Ray Tracer in Python (Part 1) - Show Notes of &amp;#34;Points in 3D Space&amp;#34;&lt;/a&gt;
      &lt;/li&gt;
    
    &lt;li&gt;
      &lt;a href=&#34;https://arunrocks.com/ray-tracer-in-python-2-revealing-the-true-colors/&#34;&gt;Ray Tracer in Python (Part 2) - Show Notes of &amp;#34;Revealing the True Colors&amp;#34;&lt;/a&gt;
      &lt;/li&gt;
    
    &lt;li&gt;
      &lt;a href=&#34;https://arunrocks.com/ray-tracer-in-python-3-3d-balls-in-2d-space/&#34;&gt;Ray Tracer in Python (Part 3) - Show Notes of &amp;#34;3D Balls in 2D Space&amp;#34;&lt;/a&gt;
      &lt;/li&gt;
    
    &lt;li&gt;
      &lt;a href=&#34;https://arunrocks.com/ray-tracer-in-python-part-4-let-there-be-light/&#34;&gt;Ray Tracer in Python (Part 4) - Show Notes of &amp;#34;Let there be light&amp;#34;&lt;/a&gt;
      &lt;/li&gt;
    
    &lt;li&gt;
      &lt;a href=&#34;https://arunrocks.com/ray-tracing-a-coronavirus-in-puray-python/&#34;&gt;Ray Tracer in Python - Show Notes of &amp;#34;Ray Tracing a Coronavirus&amp;#34;&lt;/a&gt;
      &lt;/li&gt;
    
    &lt;li&gt;Ray Tracer in Python (Part 5) - Show Notes of &amp;#34;Some Light Reflections&amp;#34;&lt;/li&gt;
    
    &lt;li&gt;
      &lt;a href=&#34;https://arunrocks.com/ray-tracer-in-python-part-6-of-firing-all-cores/&#34;&gt;Ray Tracer in Python (Part 6) - Show Notes of &amp;#34;Firing All Cores&amp;#34;&lt;/a&gt;
      &lt;/li&gt;
    &lt;/ol&gt;
&lt;/div&gt;

&lt;p&gt;One of the fascinating ways to build a complex system like a computer is to build it from scratch using simple logic gates (a good book which shows how is &lt;a href=&#34;https://amzn.to/2YXRwQc&#34;&gt;The Elements of Computing Systems&lt;/a&gt;). Same goes for late John Conway&amp;rsquo;s &lt;a href=&#34;https://bitstorm.org/gameoflife/&#34;&gt;Game of Life&lt;/a&gt; which starts with a simple set of rules but shows very life-like behaviour. This is called &lt;a href=&#34;https://en.wikipedia.org/wiki/Emergence&#34;&gt;Emergent complexity&lt;/a&gt;. I guess the only way to understand something that seems complex is to understand its basic principles.&lt;/p&gt;
&lt;p&gt;Look carefully at the, by now familiar, image that we will be rendering by the end of this part:&lt;/p&gt;
&lt;p&gt;&lt;figure&gt;
    &lt;img loading=&#34;lazy&#34; src=&#34;https://arunrocks.com/static/images/blog/rt05-two-balls.png&#34; alt=&#34;Render of two balls&#34;  title=&#34;Render of the two balls scene&#34;  width=1920 height=&#34;1080&#34;  /&gt;
    &lt;figcaption&gt;Render of the two balls scene&lt;/figcaption&gt;
  &lt;/figure&gt;&lt;/p&gt;
&lt;p&gt;Notice within the pinkish-purple ball there is a reflection of the red ball reflecting the pink ball. This kind of detailing that unfolds on closer inspection is what gives realistic renders its beauty. Yet it is governed by the most basic laws of Physics like the laws of reflection.&lt;/p&gt;
&lt;h2 id=&#34;reflection&#34;&gt;Reflection&lt;/h2&gt;
&lt;p&gt;The law tells us that the angle of reflection is the same as the angle of incidence. But if we apply it to the world of vectors a rather different looking formula emerges that &lt;a href=&#34;https://www.scratchapixel.com/lessons/3d-basic-rendering/introduction-to-shading/reflection-refraction-fresnel&#34;&gt;could be derived&lt;/a&gt; from the very same law. The reflected ray is again traced and the process continues.&lt;/p&gt;
&lt;p&gt;If you have been following the series closely so far, then you might point out that we have already dealt with this earlier. Yes, diffuse and specular shading are special cases of a material reflecting light. But since we are now considering mirror-like reflecting surfaces it is time to look at the general formula for reflection.&lt;/p&gt;
&lt;p&gt;The computation for each pixel will now increase many fold so the overall render time will increase proportional to the maximum depth of reflections we need.&lt;/p&gt;
&lt;h2 id=&#34;procedural-materials&#34;&gt;Procedural Materials&lt;/h2&gt;
&lt;p&gt;A plainly colored object is not quite interesting so you would find even the earliest ray traced images containing a chessboard pattern:&lt;/p&gt;
&lt;p&gt;&lt;figure&gt;
    &lt;img loading=&#34;lazy&#34; src=&#34;https://arunrocks.com/static/images/blog/rt05-angler.png&#34; alt=&#34;The Compleat Angler&#34;  title=&#34;The Compleat Angler (1978) by Turner Whitted&#34;  width=640 height=&#34;484&#34;  /&gt;
    &lt;figcaption&gt;The Compleat Angler (1978) by Turner Whitted&lt;/figcaption&gt;
  &lt;/figure&gt;&lt;/p&gt;
&lt;p&gt;So I introduce a chessboard pattern generated procedurally into the scene. Procedural textures are fascinating and a lot of fun to make. Compared to image textures, they have almost infinite detail. Sort of like analog versus digital.&lt;/p&gt;
&lt;p&gt;The chessboard pattern&amp;rsquo;s formula is easy to guess so it is an ideal introduction. Once you start playing around there is an &lt;a href=&#34;http://www.upvector.com/?section=Tutorials&amp;amp;subsection=Intro%20to%20Procedural%20Textures&#34;&gt;entire universe of textures&lt;/a&gt; to explore with marble, Voronoi and Perlin noise patterns. Some even go to the extend of building entire scenes with only procedural textures. This is deeply satisfying but probably pointless.&lt;/p&gt;
&lt;h2 id=&#34;plugin-scenes&#34;&gt;Plugin Scenes&lt;/h2&gt;
&lt;p&gt;Most toy raytracers are happy generating their scene in the main program. But this quickly becomes frustrating when you want to render a couple of examples. The straightforward solution would be to define a scene as data say using JSON and import the scene given as an argument. This is how games like &lt;a href=&#34;https://en.wikipedia.org/wiki/Doom_(1993_video_game)&#34;&gt;Doom&lt;/a&gt; load levels.&lt;/p&gt;
&lt;p&gt;JSON, YAML and other configuration languages are deceptively simple to read but you could spend a lot of time writing them due to their tiny quirks with commas and whitespaces. It is also not suited for scenes generated procedurally which is happens quite a bit in ray tracers. You would soon wish if these languages were Turing complete. So I decided to ditch all that and use plain old Python instead.&lt;/p&gt;
&lt;p&gt;To be honest, I was not comfortable in allowing a given Python file to describe a scene. But the power and flexibility it allows is really a great tradeoff for the security. I used &lt;a href=&#34;https://docs.python.org/3/library/importlib.html&#34;&gt;importlib&lt;/a&gt; to import modules inspired by Django.&lt;/p&gt;
&lt;p&gt;I can now define a new procedural texture material class inside a scene! This makes the ray tracer quite extensible like a plugin system. I love this approach and look forward to trying this in future projects.&lt;/p&gt;
&lt;h2 id=&#34;accelerating-python&#34;&gt;Accelerating Python&lt;/h2&gt;
&lt;p&gt;Towards the end we see a dramatic 7X speedup of the ray tracer due to the use of &lt;a href=&#34;https://www.pypy.org/index.html&#34;&gt;PyPy&lt;/a&gt;. I also mention my rough rule of thumb to increase Python performance:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Processor Bound? Try Pypy. &lt;br&gt;
IO Bound? Try AsyncIO.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;If you are learning to improve the performance of your Python program, this would be pretty bad advice. In that case, make sure you first profile your program and identify the performance hotspots. Then try different ways to optimize those places. After you have tried all that and the performance is still bad, then you can use my rule of thumb for unconventional ways to get great results.&lt;/p&gt;
&lt;h2 id=&#34;ray-tracing-concepts&#34;&gt;Ray tracing concepts&lt;/h2&gt;
&lt;p&gt;With this part, I would have covered all the basic ray tracing concepts that I had planned to cover. The next part would be about improving the performance of the ray tracer by using multiple cores.&lt;/p&gt;
&lt;p&gt;Many have contacted me asking whether I would be covering topics like Dielectrics, Depth of Field, Anti-aliasing etc. I think there are enough books like &lt;a href=&#34;https://amzn.to/2Wt4x2s&#34;&gt;Ray Tracing Gems&lt;/a&gt; and &lt;a href=&#34;(https://amzn.to/2Aqp679)&#34;&gt;Ray Tracing in One Weekend&lt;/a&gt; which cover all that and much more. If you have followed this series then reading those books would be much easier and you would have a ready implementation to tinker with.&lt;/p&gt;
&lt;p&gt;Nevertheless, I may work on a follow-up if people find that useful and time permits. So do let me know.&lt;/p&gt;
&lt;p&gt;These are the topics we will cover in this episode:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Introduction
&lt;ul&gt;
&lt;li&gt;Laws of Reflection&lt;/li&gt;
&lt;li&gt;Stack Overflow&lt;/li&gt;
&lt;li&gt;Scene Definition&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Sub-problem: Some Light Reflections&lt;/li&gt;
&lt;li&gt;Coding the solution
&lt;ul&gt;
&lt;li&gt;Chessboard Material&lt;/li&gt;
&lt;li&gt;Ground Plane&lt;/li&gt;
&lt;li&gt;Config vs Code as Config&lt;/li&gt;
&lt;li&gt;Speedup&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Here is the video:&lt;/p&gt;

&lt;div style=&#34;position: relative; padding-bottom: 56.25%; height: 0; overflow: hidden;&#34;&gt;
  &lt;iframe src=&#34;https://www.youtube.com/embed/bB0KFHB5KGc&#34; style=&#34;position: absolute; top: 0; left: 0; width: 100%; height: 100%; border:0;&#34; allowfullscreen title=&#34;YouTube Video&#34;&gt;&lt;/iframe&gt;
&lt;/div&gt;

&lt;p&gt;Code for part five is tagged on the &lt;a href=&#34;https://github.com/arocks/puray/tree/episode05&#34;&gt;Puray Github project&lt;/a&gt;&lt;/p&gt;
&lt;h3 id=&#34;show-notes&#34;&gt;Show Notes&lt;/h3&gt;
&lt;p&gt;Books and articles that can help understand this part:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;https://www.scratchapixel.com/lessons/3d-basic-rendering/introduction-to-shading/reflection-refraction-fresnel&#34;&gt;Derive Vector Reflection Formula&lt;/a&gt;: Understand how the formula can be derived from the laws of reflection.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Further reading on ray tracing:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;(https://amzn.to/2Aqp679)&#34;&gt;Ray Tracing in One Weekend&lt;/a&gt; - The first in a series of minibooks. This is followed by two more minibooks &lt;a href=&#34;https://amzn.to/2Lm9gN9&#34;&gt;Ray Tracing: the Next Week&lt;/a&gt; and &lt;a href=&#34;https://amzn.to/2ySjG4n&#34;&gt;Ray Tracing: The Rest Of Your Life&lt;/a&gt;. You may find free editions of these books online but I am not completely sure they are approved by the author.&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://amzn.to/2Wt4x2s&#34;&gt;Ray Tracing Gems&lt;/a&gt; - An excellent update to the previous set of books explaining the latest techniques focusing on real-time ray tracing.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;em&gt;Note: References may contain affiliate links&lt;/em&gt;&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>Ray Tracer in Python - Show Notes of &#34;Ray Tracing a Coronavirus&#34;</title>
      <link>https://arunrocks.com/ray-tracing-a-coronavirus-in-puray-python/</link>
      <pubDate>Fri, 10 Apr 2020 20:08:28 +0530</pubDate>
      
      <guid>https://arunrocks.com/ray-tracing-a-coronavirus-in-puray-python/</guid>
      <description>

&lt;div class=&#34;series-box&#34;&gt;
  &lt;p&gt;You are reading a post from a multi-part series of articles&lt;/p&gt;
  &lt;ol&gt;
    
    &lt;li&gt;
      &lt;a href=&#34;https://arunrocks.com/ray-tracer-in-python-1-points-in-3d-space-show-notes/&#34;&gt;Ray Tracer in Python (Part 1) - Show Notes of &amp;#34;Points in 3D Space&amp;#34;&lt;/a&gt;
      &lt;/li&gt;
    
    &lt;li&gt;
      &lt;a href=&#34;https://arunrocks.com/ray-tracer-in-python-2-revealing-the-true-colors/&#34;&gt;Ray Tracer in Python (Part 2) - Show Notes of &amp;#34;Revealing the True Colors&amp;#34;&lt;/a&gt;
      &lt;/li&gt;
    
    &lt;li&gt;
      &lt;a href=&#34;https://arunrocks.com/ray-tracer-in-python-3-3d-balls-in-2d-space/&#34;&gt;Ray Tracer in Python (Part 3) - Show Notes of &amp;#34;3D Balls in 2D Space&amp;#34;&lt;/a&gt;
      &lt;/li&gt;
    
    &lt;li&gt;
      &lt;a href=&#34;https://arunrocks.com/ray-tracer-in-python-part-4-let-there-be-light/&#34;&gt;Ray Tracer in Python (Part 4) - Show Notes of &amp;#34;Let there be light&amp;#34;&lt;/a&gt;
      &lt;/li&gt;
    
    &lt;li&gt;Ray Tracer in Python - Show Notes of &amp;#34;Ray Tracing a Coronavirus&amp;#34;&lt;/li&gt;
    
    &lt;li&gt;
      &lt;a href=&#34;https://arunrocks.com/ray-tracer-in-python-part-5-light-reflections/&#34;&gt;Ray Tracer in Python (Part 5) - Show Notes of &amp;#34;Some Light Reflections&amp;#34;&lt;/a&gt;
      &lt;/li&gt;
    
    &lt;li&gt;
      &lt;a href=&#34;https://arunrocks.com/ray-tracer-in-python-part-6-of-firing-all-cores/&#34;&gt;Ray Tracer in Python (Part 6) - Show Notes of &amp;#34;Firing All Cores&amp;#34;&lt;/a&gt;
      &lt;/li&gt;
    &lt;/ol&gt;
&lt;/div&gt;

&lt;p&gt;The first ray-traced animation I had ever seen was in my first year of Engineering. My senior showed us a gold-plated logo of the institution slowly spinning and glinting in the light. It had an amazing level of detail - a triangular frame, a gear wheel on the left, a tower on the right and even a palm tree in the center. We were dying to know how he did it. When he showed us, it blew our minds - it was all &lt;a href=&#34;https://en.wikipedia.org/wiki/POV-Ray&#34;&gt;code&lt;/a&gt;! Every shape was made by combining (or subtracting) primitive solids like spheres, cylinders and cubes. It featured on the masthead of the first edition of our online magazine (distributed on ​3 1⁄2 inch floppies).&lt;/p&gt;
&lt;div data-pullquote=&#34;&amp;#34;you can be more creative under constraints&#34;&gt;
&lt;/div&gt;
&lt;p&gt;Of course, these days 3D modelling is mostly done by artists in a graphics program like 3ds Max or Maya. But not everything is tinkered by the hand of an artist. Procedural code is still used to create thousands of unique soldiers in an army scene or an infinite world in a multiplayer game. Computer generated art can often surprise or amuse you.&lt;/p&gt;
&lt;p&gt;So when I had to design the model of the omnipresent SAR-Cov-2 virus for a poster, even though I was very tempted to use such tools, I opted to generate the model in code. My &lt;a href=&#34;https://github.com/arocks/puray&#34;&gt;Python raytracer&lt;/a&gt; (currently in it&amp;rsquo;s fourth part of the video series) was decent enough to create 3D looking spheres. Having only spheres is a big constraint but you can be more creative under constraints.&lt;/p&gt;
&lt;h2 id=&#34;deconstruction&#34;&gt;Deconstruction&lt;/h2&gt;
&lt;p&gt;There is a process fundamental to artistically recreating any real world object &amp;ndash; Deconstruction. When you learn to draw you are asked to &amp;ldquo;block out&amp;rdquo; the simple shapes you are trying to draw. So a face becomes an elongated sphere, a nose becomes a triangle etc. If your big shapes are correctly proportioned then it will be a lot easier to add in the details.&lt;/p&gt;
&lt;p&gt;In good old days, the computer artists used graph paper. Like my senior who traced the logo from the college magazine, enlarged it on graph paper and wrote down all the coordinates. These days you could use a 2D drawing program like Inkscape to overlay a photograph and trace over it. But the idea is essentially the same - find all the large blocking shapes that make your image.&lt;/p&gt;
&lt;p&gt;&lt;figure&gt;
    &lt;img loading=&#34;lazy&#34; src=&#34;https://arunrocks.com/static/images/blog/prince-of-persia-graphpaper.jpg&#34; alt=&#34;Prince of Persia art&#34;  title=&#34;Graph paper sketch of Prince of Persia by Jordan Mechner in 1987&#34;  width=1080 height=&#34;786&#34;  /&gt;
    &lt;figcaption&gt;Graph paper sketch of Prince of Persia by Jordan Mechner in 1987&lt;/figcaption&gt;
  &lt;/figure&gt;&lt;/p&gt;
&lt;h2 id=&#34;reconstruction&#34;&gt;Reconstruction&lt;/h2&gt;
&lt;p&gt;Generating the model in the computer can be a process of trial and error. In the days of slower computers, rendering a simple object took nearly an hour. Even with today&amp;rsquo;s dramatically faster machines, rendering a complex scene could take hours. There is simply a ton of numbers to crunch.&lt;/p&gt;
&lt;p&gt;In the case of the coronavirus, I needed to figure out how to make a crown. Essentially I needed to position points evenly around a circle. People say a lot of things about high school trigonometry and how much of a waste of time it was. But I found it quite useful not only to arrange the spikes of the crown but also give it a slight random shift. This would mean each time you render the virus would look sightly different. I had a lot of fun animating several renders to a beat in the video.&lt;/p&gt;
&lt;h2 id=&#34;presentation&#34;&gt;Presentation&lt;/h2&gt;
&lt;p&gt;I couldn&amp;rsquo;t stop playing with the model even after the poster was made. I tweaked it into various color combinations that I found online. Ironically, it looks distinctively charming in any avatar.&lt;/p&gt;
&lt;p&gt;It shows that simple things are awesome than the most professionally done creations. Especially if you could make your own. Looking forward to seeing what others would create with this.&lt;/p&gt;
&lt;p&gt;Here is the video:&lt;/p&gt;

&lt;div style=&#34;position: relative; padding-bottom: 56.25%; height: 0; overflow: hidden;&#34;&gt;
  &lt;iframe src=&#34;https://www.youtube.com/embed/HH0rka1uF_g&#34; style=&#34;position: absolute; top: 0; left: 0; width: 100%; height: 100%; border:0;&#34; allowfullscreen title=&#34;YouTube Video&#34;&gt;&lt;/iframe&gt;
&lt;/div&gt;

&lt;p&gt;&lt;a href=&#34;https://github.com/arocks/puray/tree/episode04&#34;&gt;Code for part four&lt;/a&gt; is the starting point of the video.&lt;/p&gt;
&lt;p&gt;&lt;a href=&#34;https://github.com/arocks/puray/tree/virusmodel&#34;&gt;Final code&lt;/a&gt; is also tagged in the repository.&lt;/p&gt;
&lt;h3 id=&#34;show-notes&#34;&gt;Show Notes&lt;/h3&gt;
&lt;p&gt;Links:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href=&#34;https://www.youtube.com/watch?v=KaCe63v4D_Q&amp;amp;list=PL8ENypDVcs3H-TxOXOzwDyCm5f2fGXlIS&#34;&gt;Puray Video Series playlist&lt;/a&gt; Watch the entire video tutorial to understand how this ray tracer was made from scratch.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href=&#34;https://www.scripps.edu/news-and-events/press-room/2020/20200317-andersen-covid-19-coronavirus.html&#34;&gt;SARS-CoV-2 Electron Microsocope Image&lt;/a&gt; This article has the reference image I used.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
</description>
    </item>
    
    <item>
      <title>Ray Tracer in Python (Part 4) - Show Notes of &#34;Let there be light&#34;</title>
      <link>https://arunrocks.com/ray-tracer-in-python-part-4-let-there-be-light/</link>
      <pubDate>Sat, 28 Mar 2020 18:39:36 +0530</pubDate>
      
      <guid>https://arunrocks.com/ray-tracer-in-python-part-4-let-there-be-light/</guid>
      <description>

&lt;div class=&#34;series-box&#34;&gt;
  &lt;p&gt;You are reading a post from a multi-part series of articles&lt;/p&gt;
  &lt;ol&gt;
    
    &lt;li&gt;
      &lt;a href=&#34;https://arunrocks.com/ray-tracer-in-python-1-points-in-3d-space-show-notes/&#34;&gt;Ray Tracer in Python (Part 1) - Show Notes of &amp;#34;Points in 3D Space&amp;#34;&lt;/a&gt;
      &lt;/li&gt;
    
    &lt;li&gt;
      &lt;a href=&#34;https://arunrocks.com/ray-tracer-in-python-2-revealing-the-true-colors/&#34;&gt;Ray Tracer in Python (Part 2) - Show Notes of &amp;#34;Revealing the True Colors&amp;#34;&lt;/a&gt;
      &lt;/li&gt;
    
    &lt;li&gt;
      &lt;a href=&#34;https://arunrocks.com/ray-tracer-in-python-3-3d-balls-in-2d-space/&#34;&gt;Ray Tracer in Python (Part 3) - Show Notes of &amp;#34;3D Balls in 2D Space&amp;#34;&lt;/a&gt;
      &lt;/li&gt;
    
    &lt;li&gt;Ray Tracer in Python (Part 4) - Show Notes of &amp;#34;Let there be light&amp;#34;&lt;/li&gt;
    
    &lt;li&gt;
      &lt;a href=&#34;https://arunrocks.com/ray-tracing-a-coronavirus-in-puray-python/&#34;&gt;Ray Tracer in Python - Show Notes of &amp;#34;Ray Tracing a Coronavirus&amp;#34;&lt;/a&gt;
      &lt;/li&gt;
    
    &lt;li&gt;
      &lt;a href=&#34;https://arunrocks.com/ray-tracer-in-python-part-5-light-reflections/&#34;&gt;Ray Tracer in Python (Part 5) - Show Notes of &amp;#34;Some Light Reflections&amp;#34;&lt;/a&gt;
      &lt;/li&gt;
    
    &lt;li&gt;
      &lt;a href=&#34;https://arunrocks.com/ray-tracer-in-python-part-6-of-firing-all-cores/&#34;&gt;Ray Tracer in Python (Part 6) - Show Notes of &amp;#34;Firing All Cores&amp;#34;&lt;/a&gt;
      &lt;/li&gt;
    &lt;/ol&gt;
&lt;/div&gt;

&lt;p&gt;Probably a &lt;a href=&#34;https://en.wikipedia.org/wiki/2019%E2%80%9320_coronavirus_pandemic&#34;&gt;global lockdown&lt;/a&gt; is a good time to resume a series that demands a lot of your time. Not really if your kids are home too. But I&amp;rsquo;ve been getting enough reminders through comments and emails that I thought it&amp;rsquo;s time to tackle this challenging episode.&lt;/p&gt;
&lt;p&gt;Yes, this is an episode with a lot of Physics and Mathematics. But you will observe it has a very gentle learning curve since there is enough background presented in the problem requirements and in previous episodes. The real challenge is in translating the math to code.&lt;/p&gt;
&lt;p&gt;Computers are computing devices crunching numbers all the time. So you might think implementing math formulas should be straightforward. Unless you are a scientist or a mathematician, in which case, you would know the truth which is &amp;ndash; it is not straightforward at all.&lt;/p&gt;
&lt;div data-pullquote=&#34;&amp;#34;There are many ways you could get it wrong. But only one way to get it right.&#34;&gt;
&lt;/div&gt;
&lt;p&gt;I remember before Doom came out, it was very hard to develop a 3D engine. Most of the available research involved understanding computer graphics text books with a lot of math theory. It&amp;rsquo;s a painful task to translate formulas into algorithms and later performant code. There are many ways you could get it wrong. But only one way to get it right. Even more frustrating is forgetting to account for edge conditions like a negative result or divide by zero and floating point errors.&lt;/p&gt;
&lt;p&gt;I remember referring one of the most popular books at that time &lt;a href=&#34;https://amzn.to/33Wz5vM&#34;&gt;Numerical Recipes&lt;/a&gt; in C++ to understand how to implement some of the algorithms. But I had to abandon the project after a working prototype because making a game engine (alone) is a tonne of work!&lt;/p&gt;
&lt;p&gt;In this part, I have used a lot of images and slides to make sure that I don&amp;rsquo;t skip any explanations (like how cosine and dot products are related). I know that these videos are being watched by all kinds people &amp;ndash; students, experienced programmers and non-programmers. So I have not made any assumptions.&lt;/p&gt;
&lt;p&gt;Hopefully you would enjoy this part without any challenges. Even if you do, it should be fun 😊&lt;/p&gt;
&lt;p&gt;These are the topics we will cover in this episode:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Introduction
&lt;ul&gt;
&lt;li&gt;Adding lights&lt;/li&gt;
&lt;li&gt;Phong reflection model&lt;/li&gt;
&lt;li&gt;Ambient, Diffuse and Specular Shading&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Sub-problem: Let there be light&lt;/li&gt;
&lt;li&gt;Coding the solution
&lt;ul&gt;
&lt;li&gt;New classes&lt;/li&gt;
&lt;li&gt;Command-line arguments with argparse&lt;/li&gt;
&lt;li&gt;Progress Bar(?)&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Here is the video:&lt;/p&gt;

&lt;div style=&#34;position: relative; padding-bottom: 56.25%; height: 0; overflow: hidden;&#34;&gt;
  &lt;iframe src=&#34;https://www.youtube.com/embed/fu_LuFU7iFo&#34; style=&#34;position: absolute; top: 0; left: 0; width: 100%; height: 100%; border:0;&#34; allowfullscreen title=&#34;YouTube Video&#34;&gt;&lt;/iframe&gt;
&lt;/div&gt;

&lt;p&gt;Code for part four is tagged on the &lt;a href=&#34;https://github.com/arocks/puray/tree/episode04&#34;&gt;Puray Github project&lt;/a&gt;&lt;/p&gt;
&lt;h3 id=&#34;show-notes&#34;&gt;Show Notes&lt;/h3&gt;
&lt;p&gt;Books and articles that can help understand this part:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href=&#34;https://amzn.to/33Xwh1h&#34;&gt;Game Engine Architecture&lt;/a&gt; Great introduction to graphics concepts and techniques used in computer games. It might be different from raytracing since focus is on realtime rendering rather than realism.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href=&#34;https://docs.python.org/3/howto/argparse.html&#34;&gt;Argparse Tutorial&lt;/a&gt; &lt;code&gt;argparse&lt;/code&gt; is the new standard for Python argument parsing.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;em&gt;Note: References may contain affiliate links&lt;/em&gt;&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>Ray Tracer in Python (Part 3) - Show Notes of &#34;3D Balls in 2D Space&#34;</title>
      <link>https://arunrocks.com/ray-tracer-in-python-3-3d-balls-in-2d-space/</link>
      <pubDate>Wed, 04 Dec 2019 22:19:43 +0530</pubDate>
      
      <guid>https://arunrocks.com/ray-tracer-in-python-3-3d-balls-in-2d-space/</guid>
      <description>

&lt;div class=&#34;series-box&#34;&gt;
  &lt;p&gt;You are reading a post from a multi-part series of articles&lt;/p&gt;
  &lt;ol&gt;
    
    &lt;li&gt;
      &lt;a href=&#34;https://arunrocks.com/ray-tracer-in-python-1-points-in-3d-space-show-notes/&#34;&gt;Ray Tracer in Python (Part 1) - Show Notes of &amp;#34;Points in 3D Space&amp;#34;&lt;/a&gt;
      &lt;/li&gt;
    
    &lt;li&gt;
      &lt;a href=&#34;https://arunrocks.com/ray-tracer-in-python-2-revealing-the-true-colors/&#34;&gt;Ray Tracer in Python (Part 2) - Show Notes of &amp;#34;Revealing the True Colors&amp;#34;&lt;/a&gt;
      &lt;/li&gt;
    
    &lt;li&gt;Ray Tracer in Python (Part 3) - Show Notes of &amp;#34;3D Balls in 2D Space&amp;#34;&lt;/li&gt;
    
    &lt;li&gt;
      &lt;a href=&#34;https://arunrocks.com/ray-tracer-in-python-part-4-let-there-be-light/&#34;&gt;Ray Tracer in Python (Part 4) - Show Notes of &amp;#34;Let there be light&amp;#34;&lt;/a&gt;
      &lt;/li&gt;
    
    &lt;li&gt;
      &lt;a href=&#34;https://arunrocks.com/ray-tracing-a-coronavirus-in-puray-python/&#34;&gt;Ray Tracer in Python - Show Notes of &amp;#34;Ray Tracing a Coronavirus&amp;#34;&lt;/a&gt;
      &lt;/li&gt;
    
    &lt;li&gt;
      &lt;a href=&#34;https://arunrocks.com/ray-tracer-in-python-part-5-light-reflections/&#34;&gt;Ray Tracer in Python (Part 5) - Show Notes of &amp;#34;Some Light Reflections&amp;#34;&lt;/a&gt;
      &lt;/li&gt;
    
    &lt;li&gt;
      &lt;a href=&#34;https://arunrocks.com/ray-tracer-in-python-part-6-of-firing-all-cores/&#34;&gt;Ray Tracer in Python (Part 6) - Show Notes of &amp;#34;Firing All Cores&amp;#34;&lt;/a&gt;
      &lt;/li&gt;
    &lt;/ol&gt;
&lt;/div&gt;

&lt;p&gt;Graphics is what made Mathematics enjoyable for me. I first heard of trigonometric functions like sine and cosine when I read &lt;a href=&#34;https://en.wikipedia.org/wiki/IBM_BASIC#IBM_Advanced_BASIC&#34;&gt;GW-BASIC&lt;/a&gt; manual. Geometry was easy to visualize with the rudimentary graphics of LINE and CIRCLE statements. While I could see many struggle with Mathematics, I always found it interesting.&lt;/p&gt;
&lt;div data-pullquote=&#34;&amp;#34;I needed to give personalities to the Ray and Sphere before I could show their intersection formula&#34;&gt;
&lt;/div&gt;
&lt;p&gt;So my challenge was to make this math-heavy episode interesting so that you see how I see it. I needed to give personalities to Ray and Sphere before I could show their intersection formula. This needed a lot of illustration and animation work. But I believe the end result was worth it.&lt;/p&gt;
&lt;p&gt;This time there is a lot of furious typing and less talking because of the number of lines entered in this part. I did not want to fast forward code writing segments because it doesn&amp;rsquo;t help the learners. In any case, YouTube can speed up videos if you choose to.&lt;/p&gt;
&lt;p&gt;These are the topics we will cover in this episode:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Introduction
&lt;ul&gt;
&lt;li&gt;Why meshes in movies and spheres in raytracers&lt;/li&gt;
&lt;li&gt;Simplified ray-tracing&lt;/li&gt;
&lt;li&gt;Ray-sphere intersection&lt;/li&gt;
&lt;li&gt;Aspect Ratio Corrections&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;First sub-problem: 3D Balls in 2D Space&lt;/li&gt;
&lt;li&gt;Coding the solution
&lt;ul&gt;
&lt;li&gt;Hex colors&lt;/li&gt;
&lt;li&gt;Classes for Engine, Ray, Sphere, etc.&lt;/li&gt;
&lt;li&gt;Rendering Algorithm&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Here is the video:&lt;/p&gt;

&lt;div style=&#34;position: relative; padding-bottom: 56.25%; height: 0; overflow: hidden;&#34;&gt;
  &lt;iframe src=&#34;https://www.youtube.com/embed/1DKlb3BQ_k8&#34; style=&#34;position: absolute; top: 0; left: 0; width: 100%; height: 100%; border:0;&#34; allowfullscreen title=&#34;YouTube Video&#34;&gt;&lt;/iframe&gt;
&lt;/div&gt;

&lt;p&gt;Code for part three is tagged on the &lt;a href=&#34;https://github.com/arocks/puray/tree/episode03&#34;&gt;Puray Github project&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Bonus (Traffic Lights) Code is &lt;a href=&#34;https://www.toneden.io/ar-td/post/traffic-lights-bonus-content&#34;&gt;available for download&lt;/a&gt;.&lt;/p&gt;
&lt;h3 id=&#34;show-notes&#34;&gt;Show Notes&lt;/h3&gt;
&lt;p&gt;Books and articles that can help understand this part:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href=&#34;https://amzn.to/2DKMISd&#34;&gt;Real-Time Collision Detection&lt;/a&gt; Great introduction and overview of different intersection and collision algorithms&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href=&#34;https://en.wikipedia.org/wiki/Line%E2%80%93sphere_intersection&#34;&gt;Line–sphere intersection - Wikipedia&lt;/a&gt; Wikipedia page with the mathematical derivation of the formula we have used.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;em&gt;Note: References may contain affiliate links&lt;/em&gt;&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>Ray Tracer in Python (Part 2) - Show Notes of &#34;Revealing the True Colors&#34;</title>
      <link>https://arunrocks.com/ray-tracer-in-python-2-revealing-the-true-colors/</link>
      <pubDate>Sun, 17 Nov 2019 12:41:50 +0530</pubDate>
      
      <guid>https://arunrocks.com/ray-tracer-in-python-2-revealing-the-true-colors/</guid>
      <description>

&lt;div class=&#34;series-box&#34;&gt;
  &lt;p&gt;You are reading a post from a multi-part series of articles&lt;/p&gt;
  &lt;ol&gt;
    
    &lt;li&gt;
      &lt;a href=&#34;https://arunrocks.com/ray-tracer-in-python-1-points-in-3d-space-show-notes/&#34;&gt;Ray Tracer in Python (Part 1) - Show Notes of &amp;#34;Points in 3D Space&amp;#34;&lt;/a&gt;
      &lt;/li&gt;
    
    &lt;li&gt;Ray Tracer in Python (Part 2) - Show Notes of &amp;#34;Revealing the True Colors&amp;#34;&lt;/li&gt;
    
    &lt;li&gt;
      &lt;a href=&#34;https://arunrocks.com/ray-tracer-in-python-3-3d-balls-in-2d-space/&#34;&gt;Ray Tracer in Python (Part 3) - Show Notes of &amp;#34;3D Balls in 2D Space&amp;#34;&lt;/a&gt;
      &lt;/li&gt;
    
    &lt;li&gt;
      &lt;a href=&#34;https://arunrocks.com/ray-tracer-in-python-part-4-let-there-be-light/&#34;&gt;Ray Tracer in Python (Part 4) - Show Notes of &amp;#34;Let there be light&amp;#34;&lt;/a&gt;
      &lt;/li&gt;
    
    &lt;li&gt;
      &lt;a href=&#34;https://arunrocks.com/ray-tracing-a-coronavirus-in-puray-python/&#34;&gt;Ray Tracer in Python - Show Notes of &amp;#34;Ray Tracing a Coronavirus&amp;#34;&lt;/a&gt;
      &lt;/li&gt;
    
    &lt;li&gt;
      &lt;a href=&#34;https://arunrocks.com/ray-tracer-in-python-part-5-light-reflections/&#34;&gt;Ray Tracer in Python (Part 5) - Show Notes of &amp;#34;Some Light Reflections&amp;#34;&lt;/a&gt;
      &lt;/li&gt;
    
    &lt;li&gt;
      &lt;a href=&#34;https://arunrocks.com/ray-tracer-in-python-part-6-of-firing-all-cores/&#34;&gt;Ray Tracer in Python (Part 6) - Show Notes of &amp;#34;Firing All Cores&amp;#34;&lt;/a&gt;
      &lt;/li&gt;
    &lt;/ol&gt;
&lt;/div&gt;

&lt;p&gt;It is always a good idea to create a visible output at the start of a long project. If you are making a game, start with showing something moving on the screen. It keeps you motivated and gives you something cool to show your friends as progress. In the second part of our ray tracer tutorial, I will introduce you to PPM a very simple image format that will be used for our renders. You don&amp;rsquo;t need to install any image libraries and yet PPM files can be read by most image viewers.&lt;/p&gt;
&lt;div data-pullquote=&#34;&amp;#34;Features like gamma correction and linear interpolation seemed like an overkill&#34;&gt;
&lt;/div&gt;
&lt;p&gt;The color class is a lot simpler than what I originally designed. Features like gamma correction and linear interpolation seemed like an overkill for a project like this. But I plan to add some convenience constructors later. Hopefully, this will be a good introduction to how colors are manipulated in computer graphics.&lt;/p&gt;
&lt;p&gt;These are the topics we will cover in this episode:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Introduction
&lt;ul&gt;
&lt;li&gt;Compressed Image are Hard&lt;/li&gt;
&lt;li&gt;What Images are Made of&lt;/li&gt;
&lt;li&gt;RGB triplets&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;First sub-problem: Revealing the True Colors&lt;/li&gt;
&lt;li&gt;Coding the solution
&lt;ul&gt;
&lt;li&gt;Use the shebang line&lt;/li&gt;
&lt;li&gt;Separate classes in separate files&lt;/li&gt;
&lt;li&gt;Why fileobj instead of filename?&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Here is the video:&lt;/p&gt;

&lt;div style=&#34;position: relative; padding-bottom: 56.25%; height: 0; overflow: hidden;&#34;&gt;
  &lt;iframe src=&#34;https://www.youtube.com/embed/92tLWv_gajA&#34; style=&#34;position: absolute; top: 0; left: 0; width: 100%; height: 100%; border:0;&#34; allowfullscreen title=&#34;YouTube Video&#34;&gt;&lt;/iframe&gt;
&lt;/div&gt;

&lt;p&gt;Code for part two is tagged on the &lt;a href=&#34;https://github.com/arocks/puray/tree/episode02&#34;&gt;Puray Github project&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Bonus (Gradient) Code is &lt;a href=&#34;https://www.toneden.io/ar-td/post/gradient-image-generator&#34;&gt;available for download&lt;/a&gt;.&lt;/p&gt;
&lt;h3 id=&#34;show-notes&#34;&gt;Show Notes&lt;/h3&gt;
&lt;p&gt;Books and articles that can help understand this part:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href=&#34;https://amzn.to/2WHBU06&#34;&gt;Understanding Compression by Colt McAnlis, Aleks Haecky&lt;/a&gt; A book covering image formats like JPG, PNG etc&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href=&#34;https://pillow.readthedocs.io/en/stable/&#34;&gt;Python Imaging Library PIL or Pillow&lt;/a&gt; Popular Python library for reading and writing different image formats&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href=&#34;https://amzn.to/2r9x28b&#34;&gt;A Field Guide to Digital Color by Maureen Stone&lt;/a&gt; Understand color theory beyond RGB triplets into vision and various color systems.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;em&gt;Note: References may contain affiliate links&lt;/em&gt;&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>Ray Tracer in Python (Part 1) - Show Notes of &#34;Points in 3D Space&#34;</title>
      <link>https://arunrocks.com/ray-tracer-in-python-1-points-in-3d-space-show-notes/</link>
      <pubDate>Fri, 01 Nov 2019 13:55:59 +0530</pubDate>
      
      <guid>https://arunrocks.com/ray-tracer-in-python-1-points-in-3d-space-show-notes/</guid>
      <description>

&lt;div class=&#34;series-box&#34;&gt;
  &lt;p&gt;You are reading a post from a multi-part series of articles&lt;/p&gt;
  &lt;ol&gt;
    
    &lt;li&gt;Ray Tracer in Python (Part 1) - Show Notes of &amp;#34;Points in 3D Space&amp;#34;&lt;/li&gt;
    
    &lt;li&gt;
      &lt;a href=&#34;https://arunrocks.com/ray-tracer-in-python-2-revealing-the-true-colors/&#34;&gt;Ray Tracer in Python (Part 2) - Show Notes of &amp;#34;Revealing the True Colors&amp;#34;&lt;/a&gt;
      &lt;/li&gt;
    
    &lt;li&gt;
      &lt;a href=&#34;https://arunrocks.com/ray-tracer-in-python-3-3d-balls-in-2d-space/&#34;&gt;Ray Tracer in Python (Part 3) - Show Notes of &amp;#34;3D Balls in 2D Space&amp;#34;&lt;/a&gt;
      &lt;/li&gt;
    
    &lt;li&gt;
      &lt;a href=&#34;https://arunrocks.com/ray-tracer-in-python-part-4-let-there-be-light/&#34;&gt;Ray Tracer in Python (Part 4) - Show Notes of &amp;#34;Let there be light&amp;#34;&lt;/a&gt;
      &lt;/li&gt;
    
    &lt;li&gt;
      &lt;a href=&#34;https://arunrocks.com/ray-tracing-a-coronavirus-in-puray-python/&#34;&gt;Ray Tracer in Python - Show Notes of &amp;#34;Ray Tracing a Coronavirus&amp;#34;&lt;/a&gt;
      &lt;/li&gt;
    
    &lt;li&gt;
      &lt;a href=&#34;https://arunrocks.com/ray-tracer-in-python-part-5-light-reflections/&#34;&gt;Ray Tracer in Python (Part 5) - Show Notes of &amp;#34;Some Light Reflections&amp;#34;&lt;/a&gt;
      &lt;/li&gt;
    
    &lt;li&gt;
      &lt;a href=&#34;https://arunrocks.com/ray-tracer-in-python-part-6-of-firing-all-cores/&#34;&gt;Ray Tracer in Python (Part 6) - Show Notes of &amp;#34;Firing All Cores&amp;#34;&lt;/a&gt;
      &lt;/li&gt;
    &lt;/ol&gt;
&lt;/div&gt;

&lt;p&gt;I&amp;rsquo;m really excited to start a new video tutorial series on creating a ray tracer from scratch. This a set of intermediate-level Python tutorials. Recently realtime ray tracing became a hot topic in the gaming community after various Minecraft Ray tracing videos started popping up. Of course, you need a monster of a machine to get decent framerates. However, we will be making an non-realtime ray tracer entirely in Python.&lt;/p&gt;
&lt;p&gt;These are the topics we will cover in this episode:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Introduction&lt;/li&gt;
&lt;li&gt;Who should watch this tutorial?&lt;/li&gt;
&lt;li&gt;What will you cover?&lt;/li&gt;
&lt;li&gt;Ray tracing in a Nutshell&lt;/li&gt;
&lt;li&gt;Getting Familiarized with my Emacs&lt;/li&gt;
&lt;li&gt;First sub-problem: Points in 3D Space&lt;/li&gt;
&lt;li&gt;Coding the solution
&lt;ul&gt;
&lt;li&gt;TDD (Test Driven Development)&lt;/li&gt;
&lt;li&gt;Data Structures&lt;/li&gt;
&lt;li&gt;3D Vectors&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Here is the video:&lt;/p&gt;

&lt;div style=&#34;position: relative; padding-bottom: 56.25%; height: 0; overflow: hidden;&#34;&gt;
  &lt;iframe src=&#34;https://www.youtube.com/embed/KaCe63v4D_Q&#34; style=&#34;position: absolute; top: 0; left: 0; width: 100%; height: 100%; border:0;&#34; allowfullscreen title=&#34;YouTube Video&#34;&gt;&lt;/iframe&gt;
&lt;/div&gt;

&lt;p&gt;Code for part one is tagged on the &lt;a href=&#34;https://github.com/arocks/puray/tree/episode01&#34;&gt;Puray Github project&lt;/a&gt;&lt;/p&gt;
&lt;h3 id=&#34;show-notes&#34;&gt;Show Notes&lt;/h3&gt;
&lt;p&gt;Books I recommend for learning Python:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;https://amzn.to/32Yv2NW&#34;&gt;Learn Python 3 the Hard Way&lt;/a&gt; For a hands-on approach&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://amzn.to/32X0R9U&#34;&gt;Learning Python, 5th Edition&lt;/a&gt; More detailed intro&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://docs.python.org/3/tutorial/&#34;&gt;Official Python Tutorial&lt;/a&gt; A quick tutorial for programmers&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Some links to learn the Vector math I cover, in more detail:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;https://chortle.ccsu.edu/VectorLessons/vectorIndex.html&#34;&gt;Vector Math for 3D Computer Graphics&lt;/a&gt; Excellent free tutorial&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://amzn.to/326VQdC&#34;&gt;3D Math Primer For Graphics and Game Development&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://www.khanacademy.org/math/linear-algebra&#34;&gt;Khan Academy on Linear algebra&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;em&gt;Note: References may contain affiliate links&lt;/em&gt;&lt;/p&gt;
&lt;h2 id=&#34;a-dream-forever-in-making&#34;&gt;A Dream Forever in Making&lt;/h2&gt;
&lt;p&gt;I have been forever interested in Computer Graphics since creating computer games is what really got me interested in programming (or &amp;ldquo;coding&amp;rdquo; as it is the fashionable term now). In early days, ray traced images used to blow my mind compared to the blocky graphics that 3D games generated.&lt;/p&gt;
&lt;p&gt;But trying to learn the algorithms was frustrating for two reasons - the mathematics seemed too dense and it took a really long time for each render. In 2015, I spent a weekend playing with various algorithms to create a simple ray tracer in Python by heavily leveraging NumPy.&lt;/p&gt;
&lt;blockquote class=&#34;twitter-tweet&#34; data-lang=&#34;en&#34;&gt;&lt;p lang=&#34;en&#34; dir=&#34;ltr&#34;&gt;Wrote a toy raytracer over the weekend in Python and NumPy. ~200 lines. Render time about 10 mins. Shiny ✨😆 &lt;a href=&#34;http://t.co/ar0GDGXCWh&#34;&gt;pic.twitter.com/ar0GDGXCWh&lt;/a&gt;&lt;/p&gt;&amp;mdash; Arun &amp;#39;Rocks&amp;#39; Ravindran (@arocks) &lt;a href=&#34;https://twitter.com/arocks/status/587304954148163585?ref_src=twsrc%5Etfw&#34;&gt;April 12, 2015&lt;/a&gt;&lt;/blockquote&gt;
&lt;script async src=&#34;https://platform.twitter.com/widgets.js&#34; charset=&#34;utf-8&#34;&gt;&lt;/script&gt;
&lt;p&gt;I felt the NumPy parts looked &amp;ldquo;un-pythonic&amp;rdquo;, so I reimplemented it without NumPy. It hit a sweet spot between functionality and readability. You needn&amp;rsquo;t be a math guru to figure out how it worked. I had to share what a learnt not because there was a lack of ray tracing tutorials but I wanted to make an accessible tutorial with gentle learning curve.&lt;/p&gt;
&lt;p&gt;However the process of creating video tutorials have changed over the years. Gone are the days of a simple screen recording or screencasts. Now we have to have slick intros, animations and click-baity thumbnails with a face overlay having a shocked expression. But honestly I am in awe of how much time people spend on making each video (it is way, way more than you think) and how frequently they make them (&amp;ldquo;new video every week&amp;rdquo;).&lt;/p&gt;
&lt;div data-pullquote=&#34;&amp;#34;Gone are the days of a simple screen recording or screencasts. Now we have to have slick intros, animations and click-baity thumbnails with a face overlay having a shocked expression.&#34;&gt;
&lt;/div&gt;
&lt;p&gt;The challenge is even harder when you need to break down all that math and physics behind computer graphics into simple concepts in a logical flow. That also takes way more time than you would expect. Sometimes you find that one clear diagram would explain an idea perfectly but nobody has made one so far so you need to draw a fresh one. Or you need to cut down your explanation because listeners are getting lost in the details. Plus your real life slows you down with work deadlines and goof ups like out of focus video recordings. This process of iterating until my script (and code) became streamlined took me months.&lt;/p&gt;
&lt;p&gt;My approach has always been about posting higher quality stuff at low frequencies. So I am happy if the end result was worth the wait (and I hope it is). This could be a tutorial that might outlive many of my other videos and that is satisfying in itself. Hope you&amp;rsquo;ll enjoy this journey with me as much as I did.&lt;/p&gt;
&lt;p&gt;Check back for &lt;a href=&#34;https://arunrocks.com/ray-tracer-in-python-2-revealing-the-true-colors&#34;&gt;part 2&lt;/a&gt; (EDIT: it is out)!&lt;/p&gt;
</description>
    </item>
    
  </channel>
</rss>
