<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Ahmet Kürşad Şaşmaz on Medium]]></title>
        <description><![CDATA[Stories by Ahmet Kürşad Şaşmaz on Medium]]></description>
        <link>https://medium.com/@ahmetksasmaz?source=rss-b8f6732d47a4------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*MDMXBbWZCkszX84g</url>
            <title>Stories by Ahmet Kürşad Şaşmaz on Medium</title>
            <link>https://medium.com/@ahmetksasmaz?source=rss-b8f6732d47a4------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 22 Nov 2026 01:09:55 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ahmetksasmaz/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[High Dynamic Range Imaging : HW 1 - 2026F]]></title>
            <link>https://ahmetksasmaz.medium.com/high-dynamic-range-imaging-hw-1-2026f-35ac2c3e6ffb?source=rss-b8f6732d47a4------2</link>
            <guid isPermaLink="false">https://medium.com/p/35ac2c3e6ffb</guid>
            <category><![CDATA[high-dynamic-range]]></category>
            <category><![CDATA[hdr]]></category>
            <dc:creator><![CDATA[Ahmet Kürşad Şaşmaz]]></dc:creator>
            <pubDate>Thu, 22 Oct 2026 12:21:05 GMT</pubDate>
            <atom:updated>2026-11-03T17:14:40.999Z</atom:updated>
            <content:encoded><![CDATA[<p>Hello everyone!</p><p>In this article, we will implement the paper below and campaign an experimentation with respect to algorithm parameters on given examples and my camera : Canon EOS R10</p><p><strong>Recovering High Dynamic Range Radiance Maps from Photographs</strong><br><em>Debevec &amp; Malik</em></p><h3><strong>Notation</strong></h3><p>P = Number of images in the sequence<br>W = Width of the image<br>H = Height of the image<br>R = Required good pixel number (explained in the selecting good pixels part)<br>S = Sampled pixel number (explained in the selecting good pixels part)<br>L = Lambda coefficient for smoothing factor<br>N = 256, constant, the number of possible quantization levels of 8-bit image</p><p>The experimentation flow explained below:</p><pre>1. Load images and set exposures according the index of the image. Exposure time = 2^index<br>2. Extract 1D histograms of three channels in a single plot for each image in the sequence<br>3. (Optional) Plot log-linear and srgb curves in order to compare log inverse crf of synthetic sequences<br>4. Select good pixels of each channel for a sequence, record time<br>5. Construct an equation system with the good pixels and solve it by SVD, record time<br>6. Construct HDR image, record time</pre><h3><strong>Loading Images</strong></h3><p>I will give the code block to loading images for sample examples.</p><pre>EXPOSURE_SEQUENCES = {<br>    &quot;Canon_EOS_550D/&quot;: [{&quot;image_name&quot;: str(i)+&quot;.JPG&quot;, &quot;exposure_time&quot;: 2**i} for i in range(9)],<br>    &quot;Minolta_DiMAGE_A1/&quot; : [{&quot;image_name&quot;: str(i)+&quot;.JPG&quot;, &quot;exposure_time&quot;: 2**i} for i in range(13)],<br>    &quot;Nikon_Coolpix_E5400/&quot;: [{&quot;image_name&quot;: str(i)+&quot;.JPG&quot;, &quot;exposure_time&quot;: 2**i} for i in range(13)],<br>    &quot;Nikon_D2H/&quot;: [{&quot;image_name&quot;: str(i)+&quot;.JPG&quot;, &quot;exposure_time&quot;: 2**i} for i in range(9)],<br>    &quot;virtual_camera/linear/&quot;: [{&quot;image_name&quot;: str(i)+&quot;.JPG&quot;, &quot;exposure_time&quot;: 2**i} for i in range(7)],<br>    &quot;virtual_camera/noise25/&quot;: [{&quot;image_name&quot;: str(i)+&quot;.JPG&quot;, &quot;exposure_time&quot;: 2**i} for i in range(9)],<br>    &quot;virtual_camera/noise50/&quot;: [{&quot;image_name&quot;: str(i)+&quot;.JPG&quot;, &quot;exposure_time&quot;: 2**i} for i in range(9)],<br>    &quot;virtual_camera/noise100/&quot;: [{&quot;image_name&quot;: str(i)+&quot;.JPG&quot;, &quot;exposure_time&quot;: 2**i} for i in range(9)],<br>    &quot;virtual_camera/noise150/&quot;: [{&quot;image_name&quot;: str(i)+&quot;.JPG&quot;, &quot;exposure_time&quot;: 2**i} for i in range(9)],<br>    &quot;virtual_camera/srgb/&quot;: [{&quot;image_name&quot;: str(i)+&quot;.JPG&quot;, &quot;exposure_time&quot;: 2**i} for i in range(9)],<br>}</pre><h3><strong>Extracting Histograms</strong></h3><p>I have extracted three channel 1D histograms of each image in the sequence to inspect visually. Here is the histograms of NikonD2H sequence.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*GJOyzlv5GCp0aXq88x8NbA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*VwQd7TZ4eVCOVxEyb0abFA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*jt8gEV2_L9l3OBrfZ2cV6A.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*0h9aYnKRU_3JPpVnEErc1w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*aZ1mIy_-IaHDsBLSA7nSWw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*fRHeIY-XMQRHQsTlt19M4w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*v0jmXQTCjkGlkK8tup5bnw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*_cOsrJIh9Tku_mjwbxJDYQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*5aCwacjZ6QDb-QNc1Yjwcg.png" /><figcaption>The 1D histogram of RGB channels in the images of NikonD2H sequence.</figcaption></figure><h3><strong>(Optional) Plotting Log Linear and sRGB Curves</strong></h3><p>I have plotted log-linear and sRGB curves to visually compare log inverse camera response function of sequences “virtual_camera/linear” and “virtual_camera/sRGB”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*B9aoQ-5VbBmXhrBnhdOTqg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*RfGBDJTuojnZ1qcPOypYCA.png" /><figcaption>Plotting of log linear (x=y) and sRGB curves</figcaption></figure><h3><strong>Selecting Good Pixels</strong></h3><p>The next step is constructing an equation and solving with SVD. The complexity of that problem is O(M*K*min(M,K)) where M = (H*W*P+N+1) and K = (H*W+N). For Canon Eos 550D, W=5184 and H=3456 equals to W*H~=18 Million pixels. The number of pixels results as huge computatational work. Instead of using 18M pixels, we select the good pixels where our equation system gives a plausible result.</p><p>To analyze the problem, we should select R number of pixels, so that we get the optimal spread across all quantization levels. By doing this, we will have equally distributed equations on pixel values. Each pixel value should have T=P*R/N equations to be equally distributed.</p><p>I have searched on the internet and this problem can be represented as several different problems:</p><p><em>Multidimensional Subset Sum (Vector Subset Selection): </em>The exact fitting algorithmic problem is this one. We have Nx1 dimensional WxH vectors. The sum of one vector is P. We will select R number of them. And at the end, sum of each dimension should be P*R/N. However, this problem is <strong>NP-Hard.</strong></p><p><em>Balanced Sampling:</em> Think about a population so that different regions have different weights. For example, the number of visitings of each city in Türkiye, in this year, by the citizens of the country. Suppose that Istanbul takes the 10% of all visitings, Ankara takes 8%, İzmir takes 5% and so on. Then, we survey people, ”Which cities have you visited in this year?”. One will say “Ankara, Istanbul, Kocaeli”, the other will say “Kahramanmaraş, Istanbul, Antalya” etc. The problem borns here, as a statistician, we should select R number of people, so that their answers give the approximately mathing distribution. This problem and its answer still are a research area.</p><p><em>Budgeted maximum coverage:</em> We relax the problem with this requirement: Each bin should have <strong>“at least” </strong>T items instead of exact. And there is a proven greedy solution that converges the real solution. The greedy iteration is below:</p><pre>1. Create a vector of needings (Which bin needs how much item?)<br>2. For the remaining canditates, calculate which candidate fills how much needing<br>3. Among all the remaining candidates, choose the maximum filler, update vector of needings and chosen list<br>4. Turn back to Step 2 until R number of candidate is chosen</pre><p>As you can guess, the complexity is still high because we iterate over all available candidates, O(R*W*H). Then, I changed the candidates part, so that instead of W*H we will have S number of samples among all candidates to iterate over each time.</p><pre>1. Create a vector of needings (Which bin needs how much item?)<br>2. For the remaining canditates, choose random S number of candidates<br>3. calculate which sampled candidate fills how much needing<br>4. Among all the sampled candidates, choose the maximum filler, update vector of needings and chosen list<br>5. Turn back to Step 2 until R number of candidate is chosen</pre><p>Surprisingly, I worked! The code is below.</p><pre>def good_pixel_selector(list_of_pixel_list, required_number_of_pixels, sampling_number):<br>  n = 256<br>  P = list_of_pixel_list.shape[0]<br>  R = required_number_of_pixels<br>  S = sampling_number<br>  # Turn to NxP<br>  pixel_list = np.array(list_of_pixel_list, dtype=np.int32)<br>  pixel_list = pixel_list.reshape(pixel_list.shape[0], -1)<br>  pixel_list = pixel_list.T<br>  N = pixel_list.shape[0]<br><br>  rng = np.random.default_rng(0)<br>  T = max(1, int(np.ceil(P*R/n)))<br>  needs = [T] * n<br>  available = [True] * N<br>  chosen = []<br><br>  for _ in range(R):<br>    # Choose random S pixels in pixel_list<br>    candidates = []<br>    while len(candidates) &lt; S:<br>      idx = int(rng.integers(0, N))<br>      if available[idx] and idx not in candidates:<br>        candidates.append(idx)<br><br>    # Find the candidate that fills the most empty bins<br>    best_idx = -1<br>    best_gain = -1<br>    for idx in candidates:<br>      temp_needs = needs.copy()<br>      gain = 0<br>      for p in range(P):<br>        v = pixel_list[idx][p]<br>        if temp_needs[v] &gt; 0:<br>          gain += 1<br>          temp_needs[v] -= 1<br>      if gain &gt; best_gain:<br>        best_gain = gain<br>        best_idx = idx<br><br>    # Take the best candidate and update the needs<br>    chosen.append(best_idx)<br>    available[best_idx] = False<br>    for p in range(P):<br>      v = pixel_list[best_idx][p]<br>      needs[v] -= 1<br><br>  return pixel_list[chosen]</pre><h3><strong>Constructing The Equation System and Solving</strong></h3><p>For this part, I have directly write the Python version of Debevec &amp; Malik’s Matlab implementation. (Struggled with differences of index representations between Matlab and Python)</p><pre>def svd_solver(pixel_list, log_exposure_list, lambda_coefficient, weight_function):<br>  n = 256<br>  A = np.zeros(shape=(pixel_list.shape[0]*pixel_list.shape[1]+n+1, n+pixel_list.shape[0]))<br>  b = np.zeros(shape=(A.shape[0], 1))<br>  <br>  # Include data fitting eqs<br>  k = 0<br>  for i in range(pixel_list.shape[0]):<br>    for j in range(pixel_list.shape[1]):<br>      z = pixel_list[i,j]<br>      wij = weight_function[z,0]<br>      A[k,z] = wij<br>      A[k,n+i] = -wij<br>      b[k,0] = wij * log_exposure_list[j,0]<br>      k += 1<br>  <br>  # Fix curve setting<br>  A[k,128] = 1<br>  k += 1<br>  <br>  # Smoothness equations<br>  for i in range(n-2):<br>    A[k,i] = lambda_coefficient * weight_function[i+1,0]<br>    A[k,i+1] = -2 * lambda_coefficient * weight_function[i+1,0]<br>    A[k,i+2] = lambda_coefficient * weight_function[i+1,0]<br>    k += 1<br>  <br>  # Solve the system<br>  x = np.linalg.lstsq(A, b, rcond=None)[0]<br>  log_inverse_crf = x[:n]<br>  log_irradiance = x[n:]<br>  return log_inverse_crf, log_irradiance</pre><h3><strong>Constructing The HDR Image</strong></h3><p>For this part, I have implemented the proposed method in the paper, weighted contribution of pixels.</p><pre>blue_irradiance = np.ndarray(shape=(H,W), dtype=np.float32)<br>green_irradiance = np.ndarray(shape=(H,W), dtype=np.float32)<br>red_irradiance = np.ndarray(shape=(H,W), dtype=np.float32)<br><br>blue_w = weight_function[blue_pixels]<br>green_w = weight_function[green_pixels]<br>red_w = weight_function[red_pixels]<br><br>blue_g = blue_log_inverse_crf[blue_pixels]<br>green_g = green_log_inverse_crf[green_pixels]<br>red_g = red_log_inverse_crf[red_pixels]<br><br>blue_irradiance = np.sum(blue_w * (blue_g - log_exposure_list), axis=0) / (np.sum(blue_w, axis=0) + 1e-9)<br>green_irradiance = np.sum(green_w * (green_g - log_exposure_list), axis=0) / (np.sum(green_w, axis=0) + 1e-9)<br>red_irradiance = np.sum(red_w * (red_g - log_exposure_list), axis=0) / (np.sum(red_w, axis=0) + 1e-9)<br><br>hdr = np.exp(np.dstack([blue_irradiance, green_irradiance, red_irradiance])).astype(np.float32)</pre><h3><strong>Results</strong></h3><p>Before analyzing the plottings, I have recorded working times of algorithms and apply Pearson correlation with their complexities. I have done this because each CPU is different and processes are affected by other processes. And because I wasn’t comparing different algorithms, I thought that the relation between the complexity and recorded time would be better to express.</p><p>I have used these values for experimentation for both given examples and my sequence.</p><pre>LAMBDA_COEFFICIENTS = [0.1, 1, 10]<br>REQUIRED_GOOD_PIXELS = [50, 500, 1000]<br>SAMPLING_NUMBERS = [250, 500]</pre><h4>Complexity Analysis</h4><p><strong>Good Pixel Finder [O(P*R*S)]</strong><br>Correlation with given examples : <strong>0,9856103591</strong><br>Correlation with my sequences : <strong>0,8866753829 → 0,8734597992 (Updated with new data on 3 Nov 2026)</strong></p><p><strong>SVD Solver [O(P*R)]</strong><br>Correlation with given examples : <strong>0,9560820136</strong><br>Correlation with my sequences : <strong>0,9538535879 → 0,9547362634 (Updated with new data on 3 Nov 2026)</strong></p><p><strong>HDR Construct [O(P*W*H)]</strong><br>Correlation with given examples : <strong>0,9942027691</strong><br>Correlation with my sequences : <strong>0,9954271562 →0,970790473 (Updated with new data on 3 Nov 2026)</strong></p><h4>Lambda Coefficient Analysis</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*Gidoc2_c9tONpDZtVfWxyA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*ZgXIwppakcHoyj4er5OZTg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*wcQAH2EAsyo7FRgZlw14WQ.png" /><figcaption>Log Inverse CRFs of Canon EOS 550D. Lambda values left to right [0.1, 1, 10] R=1000 S=500 each</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*LmLbQk6I3SsvEGosbTAHow.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*srxePityX09mgV3seO-HNQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*yE6S3SxrS138A4aIAs5EEg.png" /><figcaption>Log Inverse CRFs of Nikon Coolpix E5400. Lambda values left to right [0.1, 1, 10] R=50 S=250 each</figcaption></figure><p>I have tried to select the least noist w.r.t. R and S and the most noisy ones to show the effect of lambda value. As it can be seen, the lambda value makes the curve smoother, however it may create drift between channels because each channel is solved differently and smoothness may be directed in the wrong way due to noise differences in that channel.</p><h4>Required Pixel Number Analysis</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*5uxjV6qG3j63We99KXaeQQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*4O9zIdI5oREnNIWRr-RrMg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*d3mIYnh2khbrEp6jjP-S8g.png" /><figcaption>Log Inverse CRFs of Minolta DiIMAGE A1. R values left to right [50, 500, 1000] L=0.1 S=500 each</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*a_KPFRsQDcp5Sy4GevC5oA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*gRRSb-rhngJDZtckIk4EZA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*TYXbRVmi2PqdFAr4_VmKNQ.png" /><figcaption>Log Inverse CRFs of Minolta DiIMAGE A1. R values left to right [50, 500, 1000] L=10 S=500 each</figcaption></figure><p>It can be seen that increasing the R value, decreases the noise itself in the plotting. And it can be seen that L value is also decreases the noise, but the effect of the noise, not the noise itself. The false smoothing can be seen in the images of L=0.1 and L=10 with R=50 S=500. The false fluctuation in red channel around the value 230 still not represents the true log inverse crf.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*nFHcDefseceF_oYBCyznAA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*IhwWvONLsxEhQf-bbcIOsQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*qS9g9NhzPtolW2yLUU1TCg.png" /><figcaption>Log Inverse CRFs of Nikon D2H. R values left to right [50, 500, 1000] L=1 S=250 each</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*nsV-i3vFHGpRysmS3Y4Elw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*BQw5ZRiwtos3gcIaJCbxVw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*n8SaGDs_VhgIViQnYWo9_w.png" /><figcaption>Log Inverse CRFs of Nikon D2H. R values left to right [50, 500, 1000] L=1 S=500 each</figcaption></figure><p>The effect of S can’t be seen clearly. The top and bottom images of the same column seems like they have drift between channels, but I think no reliable reasoning can be done about that drift.</p><h4>Synthetic Log Linear</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*B9aoQ-5VbBmXhrBnhdOTqg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*iUTfhF_z-vdaSDP79Ji4sg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*2vO_TyVklAZY9G-d3mSayw.png" /><figcaption>Log Linear (log(x/255)) Plotting, Log Inverse CRF of virtual_camera/linear, Inverse CRF of virtual_camera/linear. [L=10, R=1000, S=500]</figcaption></figure><p>The log linear plotting is always negative. We set the log inverse crf of pixel value 128 as 0. In addition the true plotting goes to -Inf, so that the scaling does not fit. The right plotting is the inverse CRF, which is freed from log. It goes linear from 0 to 200, but goes exponential after 200. It may be due to linearity is preserved between these values by the camera or my implementation couldn’t find the high pixel value parts.</p><p><strong>Synthetic sRGB with Noise</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*RfGBDJTuojnZ1qcPOypYCA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*dXqhJee9vR-22MDTjNUkEg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*8miX_9uGPBZyTwvevMflKg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*3QiQz4d-Nyc9zgH2k06mVg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*XLiSyO_POpNTJv-wG8dxSg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*rVXjmPthklpxt7JAkngvWg.png" /><figcaption>sRGB Curve, Log Inverse CRFs Noiseless, Noise = 25, Noise = 50, Noise = 100, Noise = 150 with L=10 R=1000 S=500</figcaption></figure><p>This was the first image I have tested and ensure that my algorithm works. We can see the effect of noise in the plottings. As the noise increases, the curves have more fluctiation and the channels have variance between themselves. Again, the region between 230 and 255 are not reconstructed well.</p><h3>My Camera</h3><p>I have put my camera on a block and take the pictures of the scene from my window. Here is my camera (Canon EOS R10 Mirrorless) sequence:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WhpCi8Tk_za0c_ePL6pZUA.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9GHAQcbc9bEtgLMYKkSFvQ.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vaqm8_a2tBa4bAPffPkY6w.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cUSQmyPhQhGZ__yzmA_gIQ.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ONQKTObmLhDr7B2RajnjSw.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lwpWh4ceKGt1eaIr0DTGxA.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*u-HfQefNvb8g9vA6IC4HFA.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*R7RwRvosHiV_d-brKDy_4w.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kYjuwt5XILO2NTB_bMLKwA.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6h90vny59VnYfDmm9g8rZQ.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FNutK0ozC8AaLRKsTXGAbQ.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IWud1JW6ipS-fR31__RTnQ.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZUbiHtjprMCRGiS8yX6nfw.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7ZrdFJF1IH7j4pTme5EKpw.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gHsC71l7PMETeT1mWetfNg.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*L_hVJcgrU0JrMPATfqBIzA.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UUexzqiUpjhPsE8hnnOcNg.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FqNAFPwRgzNrZ3caMvBb-Q.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*n4lpFvJfUYxhXPo04aywQQ.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4qdFdJhNrKKhTpdqOvUacg.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-jLBJAfFU7H12Hhxpm9Kfg.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*L3qmMhEIC-coAGWrIMOhlQ.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vP8vuwLD5yZoZ15p_yy9EQ.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Kl84JAPrmNOGEOnP3S6lGQ.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-jsUqsP03YZiKHqqVPsqRg.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*npauN6LCf3HcXqGVcqQKhw.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mmQSCy_-FA3U9SlhYVtdQw.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uYo59L5wvQZG8FKjkXIkjg.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VAjhYLmUi0achlZavEubyQ.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YV9tkEzYrONpgZBo7Aw9ng.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ryvplrCB0EuBdS49WSQ5Lw.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*R3LZoNylPq1MbRijIKCiXg.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PvmfpjlvrF_DJutjBrW4PA.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Jk_pteiubwv5AdLh51svIw.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*r6v4XSkqEdABnxlxZjFzIQ.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*koiCJcIHquwJRfRzKgGF0g.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ijwiohQO4qDzEVGA9MtjaQ.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1cyjPnUqcwsfjKDC9z7Cbg.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KzXULFHjDlQ0a7HV2lDGGg.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XMyQzjXvXS6oxffiLEx5tw.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xfKC2KVinxB8s7NKXH3_Nw.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BbsXQ0e8ukl7U9RLpWxdAA.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DUZSUX6rO0Nx1GMyALSwAA.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YYYWUl6MGvxo9U8KLacw8Q.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*skrMVGNV-HPxor8fPpNK9Q.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xta4JGesYBSVRG_sq-Q4Pw.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*karMLxLz_qQ70XS-OdfaFg.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BNFC_z1N-haPcnkjEeVNBg.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cwoOJeDqIR0hsmqWhVArMw.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*62O8zvm5BUefwPbWiqWRGQ.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZPiqwF_y-BA2vhEFDQsT1g.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gVKsFo4qEL0W5HXswcuTbQ.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TUWjDVq2vDtKExugFd3zxw.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vl2pOqtKmJn9lA_DRJWQNw.jpeg" /><figcaption>The exposure stack with exposure times(s) from left to right [1/4000, 1/3200, 1/3200, 1/2500, 1/2000, 1/1600, 1/1250, 1/1000, 1/800, 1/640, 1/500, 1/400, 1/400, 1/320, 1/250, 1/200, 1/160, 1/125, 1/100, 1/80, 1/60, 1/50, 1/40, 1/30, 1/25, 1/20, 1/15, 1/13, 1/10, 1/8, 1/6, 1/5, 1/4, 3/10, 2/5, 1/2, 3/5, 4/5, 1, 13/10, 8/5, 2, 5/2, 16/5, 4, 5, 6, 8, 10, 13, 15, 20, 25, 30] Resolution 6000x4000 f1/8 ISO100 50mm for all captures</figcaption></figure><p>As an important note: The captures of 1/3200 and 1/400 are mistakenl ycaptured twice , one of each is chosen. Even touching the camera for rolling exposure time ring slightly vibrates the camera and changes the angle, so I have used Canon Camera Connect application and connected to my camera to set exposure times with wireless connection.</p><p>And I want to say another thing that can be crucial when capturing photos. For the well exposed and over exposed images, the auto focus didn’t affect the focus ring. However, for the under exposed images the camera couldn’t focus or change the focus differently. Here is an information which nobody knows: focusing process slightly changes the focal length! The focal length information on the lens (16mm/50mm) is the number when the objective focuses at hyperfocal distance (where everything is in focus / theoretically) In addition, when extracting the intrinsic values of the camera, assuming f = the number on the lens is a common mistake!</p><p>As a result of slightly changed focal length, all irradiance levels and even field of view changes! Thus, I have focused on auto-focus mode and turn back to manual focus.</p><h3>My Phone (Added on 3 Nov 2026)</h3><p>Here, I will only add three exposures per each camera of my phone (Xiaomi Redmi Note 10). Normally MIUI allows only for two cameras in its camera app, also limits the exposure times. With the power of AI tools, I have been able to create an app such that we can capture images from the hidden cameras with an arbitrary exposure time. They are actually used for depth estimation or color correction, as a helper. Then, I figured out that the predefined exposure times are only a preset, actually they all can be an arbitrary numbers but the product is designed to be as it is. In a way, all cameras can be considered as industrial cameras, depending on how much you are able to control the parameters of it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*f3ox7F6Gytbm5pSj_JGeNA.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*G1vspG-ykgEbRl2tBdj2CQ.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5VwZul3Nc0Dlni3a7Y7l1w.jpeg" /><figcaption>Xiaomi Redmi Note 10 Cam1 with exposure times 2000, 20000, 500000 us</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*i7dvnGBR5jpp8u82P-R3sQ.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1pO3q2RGiIPzVPamaTjTgQ.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uLU81OwrnVgwg16pyc8TPQ.jpeg" /><figcaption>Xiaomi Redmi Note 10 Cam2 with exposure times 2000, 20000, 500000 us</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5nTfhwo0ZpIdo5W6eKXZcw.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eeF_JN56X_7qYYkf0k-oTA.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qcdjmwvbSus4vRXiq1BLlA.jpeg" /><figcaption>Xiaomi Redmi Note 10 Cam3 with exposure times 200, 2000, 20000 us</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fJykUymQzvwOqwQ94aWYZg.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ix1v7kYtgu0rgAohWcpEbA.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gvtT42VRStWcusNZKzxh_A.jpeg" /><figcaption>Xiaomi Redmi Note 10 Cam4 with exposure times 2000, 20000, 500000 us</figcaption></figure><p>As it can be seen, over exposed images have blue tint, it may cause a corrupted blue curve. Also for the over exposed images, the sunlight coming from the window hides the middle column of the window. I wasn’t expecting that. It may be due to the lens or the blooming effect (when a photoreceptor is saturated, it starts to affect nearby photoreceptors, named as charge spillover in literature.)</p><h3><strong>Sequences</strong></h3><p>I have created multiple sequences from these variety of images.</p><pre>EXPOSURE_SEQUENCES = {<br>    &quot;canon_eos_r10_full_range/&quot;: [{&quot;image_name&quot;: &quot;canon_eos_r10/&quot;+CANON_LIST_OF_IMAGE_NAMES[i], &quot;exposure_time&quot;: CANON_LIST_OF_EXPOSURE_TIMES[i]} for i in range(len(CANON_LIST_OF_IMAGE_NAMES)//1)],<br>    &quot;canon_eos_r10_every_3/&quot;: [{&quot;image_name&quot;: &quot;canon_eos_r10/&quot;+CANON_LIST_OF_IMAGE_NAMES[3*i], &quot;exposure_time&quot;: CANON_LIST_OF_EXPOSURE_TIMES[3*i]} for i in range(len(CANON_LIST_OF_IMAGE_NAMES)//3)],<br>    &quot;canon_eos_r10_every_5/&quot;: [{&quot;image_name&quot;: &quot;canon_eos_r10/&quot;+CANON_LIST_OF_IMAGE_NAMES[5*i], &quot;exposure_time&quot;: CANON_LIST_OF_EXPOSURE_TIMES[5*i]} for i in range(len(CANON_LIST_OF_IMAGE_NAMES)//5)],<br>    &quot;canon_eos_r10_every_7/&quot;: [{&quot;image_name&quot;: &quot;canon_eos_r10/&quot;+CANON_LIST_OF_IMAGE_NAMES[7*i], &quot;exposure_time&quot;: CANON_LIST_OF_EXPOSURE_TIMES[7*i]} for i in range(len(CANON_LIST_OF_IMAGE_NAMES)//7)],<br>    # below added after 3 Nov 2026<br>    &quot;redmi_cam_1_full_range/&quot;: [{&quot;image_name&quot;: &quot;redmi_cam_1/&quot; + REDMI_CAM_1_LIST_OF_IMAGE_NAMES[i], &quot;exposure_time&quot;: REDMI_CAM_1_LIST_OF_EXPOSURE_TIMES[i]} for i in range(len(REDMI_CAM_1_LIST_OF_IMAGE_NAMES)//1)],<br>    &quot;redmi_cam_1_every_3/&quot;: [{&quot;image_name&quot;: &quot;redmi_cam_1/&quot; + REDMI_CAM_1_LIST_OF_IMAGE_NAMES[3*i], &quot;exposure_time&quot;: REDMI_CAM_1_LIST_OF_EXPOSURE_TIMES[3*i]} for i in range(len(REDMI_CAM_1_LIST_OF_IMAGE_NAMES)//3)],<br>    &quot;redmi_cam_1_every_5/&quot;: [{&quot;image_name&quot;: &quot;redmi_cam_1/&quot; + REDMI_CAM_1_LIST_OF_IMAGE_NAMES[5*i], &quot;exposure_time&quot;: REDMI_CAM_1_LIST_OF_EXPOSURE_TIMES[5*i]} for i in range(len(REDMI_CAM_1_LIST_OF_IMAGE_NAMES)//5)],<br>    &quot;redmi_cam_1_every_7/&quot;: [{&quot;image_name&quot;: &quot;redmi_cam_1/&quot; + REDMI_CAM_1_LIST_OF_IMAGE_NAMES[7*i], &quot;exposure_time&quot;: REDMI_CAM_1_LIST_OF_EXPOSURE_TIMES[7*i]} for i in range(len(REDMI_CAM_1_LIST_OF_IMAGE_NAMES)//7)],<br>    &quot;redmi_cam_2_full_range/&quot;: [{&quot;image_name&quot;: &quot;redmi_cam_2/&quot; + REDMI_CAM_2_LIST_OF_IMAGE_NAMES[i], &quot;exposure_time&quot;: REDMI_CAM_2_LIST_OF_EXPOSURE_TIMES[i]} for i in range(len(REDMI_CAM_2_LIST_OF_IMAGE_NAMES)//1)],<br>    &quot;redmi_cam_2_every_3/&quot;: [{&quot;image_name&quot;: &quot;redmi_cam_2/&quot; + REDMI_CAM_2_LIST_OF_IMAGE_NAMES[3*i], &quot;exposure_time&quot;: REDMI_CAM_2_LIST_OF_EXPOSURE_TIMES[3*i]} for i in range(len(REDMI_CAM_2_LIST_OF_IMAGE_NAMES)//3)],<br>    &quot;redmi_cam_2_every_5/&quot;: [{&quot;image_name&quot;: &quot;redmi_cam_2/&quot; + REDMI_CAM_2_LIST_OF_IMAGE_NAMES[5*i], &quot;exposure_time&quot;: REDMI_CAM_2_LIST_OF_EXPOSURE_TIMES[5*i]} for i in range(len(REDMI_CAM_2_LIST_OF_IMAGE_NAMES)//5)],<br>    &quot;redmi_cam_2_every_7/&quot;: [{&quot;image_name&quot;: &quot;redmi_cam_2/&quot; + REDMI_CAM_2_LIST_OF_IMAGE_NAMES[7*i], &quot;exposure_time&quot;: REDMI_CAM_2_LIST_OF_EXPOSURE_TIMES[7*i]} for i in range(len(REDMI_CAM_2_LIST_OF_IMAGE_NAMES)//7)],<br>    &quot;redmi_cam_3_full_range/&quot;: [{&quot;image_name&quot;: &quot;redmi_cam_3/&quot; + REDMI_CAM_3_LIST_OF_IMAGE_NAMES[i], &quot;exposure_time&quot;: REDMI_CAM_3_LIST_OF_EXPOSURE_TIMES[i]} for i in range(len(REDMI_CAM_3_LIST_OF_IMAGE_NAMES)//1)],<br>    &quot;redmi_cam_3_every_3/&quot;: [{&quot;image_name&quot;: &quot;redmi_cam_3/&quot; + REDMI_CAM_3_LIST_OF_IMAGE_NAMES[3*i], &quot;exposure_time&quot;: REDMI_CAM_3_LIST_OF_EXPOSURE_TIMES[3*i]} for i in range(len(REDMI_CAM_3_LIST_OF_IMAGE_NAMES)//3)],<br>    &quot;redmi_cam_3_every_5/&quot;: [{&quot;image_name&quot;: &quot;redmi_cam_3/&quot; + REDMI_CAM_3_LIST_OF_IMAGE_NAMES[5*i], &quot;exposure_time&quot;: REDMI_CAM_3_LIST_OF_EXPOSURE_TIMES[5*i]} for i in range(len(REDMI_CAM_3_LIST_OF_IMAGE_NAMES)//5)],<br>    &quot;redmi_cam_3_every_7/&quot;: [{&quot;image_name&quot;: &quot;redmi_cam_3/&quot; + REDMI_CAM_3_LIST_OF_IMAGE_NAMES[7*i], &quot;exposure_time&quot;: REDMI_CAM_3_LIST_OF_EXPOSURE_TIMES[7*i]} for i in range(len(REDMI_CAM_3_LIST_OF_IMAGE_NAMES)//7)],<br>    &quot;redmi_cam_4_full_range/&quot;: [{&quot;image_name&quot;: &quot;redmi_cam_4/&quot; + REDMI_CAM_4_LIST_OF_IMAGE_NAMES[i], &quot;exposure_time&quot;: REDMI_CAM_4_LIST_OF_EXPOSURE_TIMES[i]} for i in range(len(REDMI_CAM_4_LIST_OF_IMAGE_NAMES)//1)],<br>    &quot;redmi_cam_4_every_3/&quot;: [{&quot;image_name&quot;: &quot;redmi_cam_4/&quot; + REDMI_CAM_4_LIST_OF_IMAGE_NAMES[3*i], &quot;exposure_time&quot;: REDMI_CAM_4_LIST_OF_EXPOSURE_TIMES[3*i]} for i in range(len(REDMI_CAM_4_LIST_OF_IMAGE_NAMES)//3)],<br>    &quot;redmi_cam_4_every_5/&quot;: [{&quot;image_name&quot;: &quot;redmi_cam_4/&quot; + REDMI_CAM_4_LIST_OF_IMAGE_NAMES[5*i], &quot;exposure_time&quot;: REDMI_CAM_4_LIST_OF_EXPOSURE_TIMES[5*i]} for i in range(len(REDMI_CAM_4_LIST_OF_IMAGE_NAMES)//5)],<br>    &quot;redmi_cam_4_every_7/&quot;: [{&quot;image_name&quot;: &quot;redmi_cam_4/&quot; + REDMI_CAM_4_LIST_OF_IMAGE_NAMES[7*i], &quot;exposure_time&quot;: REDMI_CAM_4_LIST_OF_EXPOSURE_TIMES[7*i]} for i in range(len(REDMI_CAM_4_LIST_OF_IMAGE_NAMES)//7)],<br>}</pre><p>Full range takes all 52 of the images and every_X takes one image in every X image. Here are the reconstructed log inverse crfs:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*DScbPSPpJS9B5Op7Xw4cZQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*fCafC3ZckyawdDypIzwfnQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*bHKM2NzAZP9dzosYME59zA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*cIdV76bSeU3FIwnlQZpqKA.png" /><figcaption>Log Inverse CRFs of Full Range, Canon EOS R10, Every 3, Every 5, Every 7 [L=10, R=1000, S=500]</figcaption></figure><p>See? How magnificent! We can see the smoothness difference between the one with 52 images and the one with every 7 images.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*GxMRzFNmOxo8pmPwdZiTnw.png" /><figcaption>Log Inverse CRFs of Full Range, Xiaomi Redmi Note 10 Cam1</figcaption></figure><p>We can see the effect of the blooming, it breaks the curve after ~225, where blooming effect starts to hide the actual pixels of that value.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*fE0NZLUCYB3VTXinP0Kdfw.png" /><figcaption>Log Inverse CRFs of Full Range, Xiaomi Redmi Note 10 Cam2</figcaption></figure><p>The fluctuation starts from low-mid pixel values. I think this is because the blooming effect for this camera begin to be seen earlier.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*VuQ6qsMJsHL5_w6HHVsaRQ.png" /><figcaption>Log Inverse CRFs of Full Range, Xiaomi Redmi Note 10 Cam3</figcaption></figure><p>As it can be guessed, all three channels nearly the same for the black-white camera. And surprisingly there is no noisy plotting at the saturation region. This may be because the maximum exposure time limit of this camera is lower than the others.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*ZfaWUqi2WcToLlmijpD2ww.png" /><figcaption>Log Inverse CRFs of Full Range, Xiaomi Redmi Note 10 Cam4</figcaption></figure><p>I think the drift between the curves is due to blooming effect region is larger than the Cam2. So it partially-hides the pixels with nearly every value, this causes a noise and a drift between channels.</p><p>Thank you for reading!</p><p>See you on the future blog posts!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=35ac2c3e6ffb" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Advanced Ray Tracing : Kürşad Box –2025F]]></title>
            <link>https://ahmetksasmaz.medium.com/advanced-ray-tracing-k%C3%BCr%C5%9Fad-box-2025f-2b2f088e7a25?source=rss-b8f6732d47a4------2</link>
            <guid isPermaLink="false">https://medium.com/p/2b2f088e7a25</guid>
            <dc:creator><![CDATA[Ahmet Kürşad Şaşmaz]]></dc:creator>
            <pubDate>Sat, 24 Jan 2026 19:57:08 GMT</pubDate>
            <atom:updated>2026-01-24T19:57:08.473Z</atom:updated>
            <content:encoded><![CDATA[<h3>Advanced Ray Tracing : Kürşad Box –2025F</h3><p>Hello everyone! Here is the final part of the Advanced Ray Tracing series : Kürşad Box.</p><p>Throughout our journey, we rendered a box. A box that is used as a ground truth to our ray tracers made by Cornell University. This is why it is named as Cornell Box.</p><p>This time, I would like to introduce Kürşad Box to you.</p><p>First we need a light. A mini studio light with tripod stick is fixed to a board. It has total of 10W power with a grid of leds.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kMv5zNv5ImpFuOVOfsmaWQ.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yaCXErEFybkvYefs46N9fQ.jpeg" /></figure><p>Then we need diffuse surfaces. Left and right surface are red and blue textile, which are an old t-shirts glued to the board.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qUkCoa-obucQ0FjC-JDFqg.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gq6IEghG6uFZtDY-Pi_gQQ.jpeg" /></figure><p>Then we need a procedural and specular surface and a back surface. However, I forgot to take photos of them one by one. You will see at the further steps.</p><p>As a material we need a mirror to increase complexity. After many failures of cutting the mirror at the house, I bought a small mirror with a standing.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Jz24SH-n9EKHwipDw-WDWQ.jpeg" /></figure><p>Here is a demonstration of what I will build so good at the end.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*S9CStd-PizflxnIMnaY3_Q.jpeg" /></figure><p>After setting the scene, painting the back wall and gluing the checkerboard pattern to the board. All pieces are brought together.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*favTmaefBrN4ZEmx46JJ2w.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fZEWaG5RLxYR6jnOqQ4dyA.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dNjLo6MJf42dVoqCHSyvOQ.jpeg" /><figcaption>This was the most complex region of the scene.</figcaption></figure><p>Then I started taking photos.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qevj4U9iaIsj-hDZUnAHcg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bbm5KeDT76ipbmSBNLRhGA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZeGiG9UINeebcJDIV2CqLQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*s-dg42z0yf-6qJlLHmRn2g.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nyvuzxakJ0bfh3CFjWe-cg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IMIldHYzIoOpA-4OtbHANQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*q0umTD5dzPss77SyQas_FQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KzlcQEtSsKM_uPeSbk-vIg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JpEgPUk0hvIFqqL1aepC0A.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tocLYdc97cPA_BthWawPsQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qvBi--lwsiLJaiXzSeFFfg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8DLGzd9rb88YqEsqSy9CzA.png" /><figcaption>The photographs of the scene with different exposure times.</figcaption></figure><p>Thanks to Adobe Lightroom, it was too easy to undistort them and construct HDR image with these raw photos. Otherwise I wouldn’t complete the project.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WAMUMVsAMyN_1uNs5h4EPg.png" /><figcaption>Here is the HDR photo, because it is not tone mapped, it looks so dark.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/638/1*v-PRruaNnVNDVZDf4lFXMw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/638/1*LLzXLMKDRkl1R9ebMKoW7Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/638/1*QAco5UgYkIil0Hcw9e2KQQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/638/1*7kICFl0eg7IRlX2atUXopA.png" /><figcaption>I capture the photos of the Ezio Painting and extract its useful information (Original, Luminance Map, Chrominance Map, Sobel Map (For Bump Mapping))</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vb03p0EBbDfrlUz6EOQm9Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UqDUwYG9uP25fQvtQmKP3A.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KY1xabF1vnQ5dJ3QoeIdRw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VzYgrFHeOgpCSOcyPY30BA.png" /><figcaption>I capture the photos of the Strasbourg Magnet and extract its useful information (Original, Luminance Map, Chrominance Map, Sobel Map (For Bump Mapping))</figcaption></figure><p>Finally, export my HDR image as EXR and tonemapped PNG file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*X1BJnY47iQm_8SDmKRUQqA.jpeg" /><figcaption>The Ground Truth Tone Mapped Image</figcaption></figure><p>As a final, I started to write JSON file, but this was insane! Really insane, not a sane human job! Then render the scene that I got until the deadline :(</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iRSqemIapxk2pr0GDJSpaA.jpeg" /></figure><p>It has to be optimized so much! I’m really aware of that. But rendering a real scene (Especially the one I created) is so exciting! I was so happy when the meshes of the Ezio painting fits exactly, or my tracer renders the checkerboard reflection on the back yellow reflective ball.</p><p>Now, the time for a rest!</p><p>Have a good holiday!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2b2f088e7a25" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Advanced Ray Tracing : Part 6–2025F]]></title>
            <link>https://ahmetksasmaz.medium.com/advanced-ray-tracing-part-6-2025f-a5813648cafa?source=rss-b8f6732d47a4------2</link>
            <guid isPermaLink="false">https://medium.com/p/a5813648cafa</guid>
            <category><![CDATA[path-tracing]]></category>
            <category><![CDATA[ray-tracing]]></category>
            <dc:creator><![CDATA[Ahmet Kürşad Şaşmaz]]></dc:creator>
            <pubDate>Sat, 24 Jan 2026 19:17:44 GMT</pubDate>
            <atom:updated>2026-01-24T19:17:44.502Z</atom:updated>
            <content:encoded><![CDATA[<h3>Advanced Ray Tracing : Part 6–2025F</h3><p>Hello everyone!</p><p>You are reading the sixth part of the Advanced Ray Tracing series. In this part we will build advanced lighting with some nerdy statistical approaches.</p><p>We will trace the paths, as our ancestors taught us. But, won’t we question them? Will we follow the paths that are already determined, or will we change our fate and decide where to go? Here is the answer.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FsIboWHJjHAk%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DsIboWHJjHAk&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FsIboWHJjHAk%2Fhqdefault.jpg&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/e55cbd24baf89de75c169edcbdc5379c/href">https://medium.com/media/e55cbd24baf89de75c169edcbdc5379c/href</a></iframe><p>Usually, we implement our homework and that was enough to get enough results. However, I had to improve and optimize my BVH structure and also shared pointer based perspective. A one may say that I have returned to the primitives, basics. (Remembering the basics is the fundamental thing of victory!) And sacrificed high randomness for speed. (Integrated a fast RNG.)</p><p>I haven’t campaign a detailed experiment about the optimization but I can say that there is significant change!</p><p>We have some new classes. But because I don’t want to fill my blog post with code snippets. I will introduce the strugglings that I have met.</p><h4>BRDFs</h4><p><strong>BaseBRDF [exponent, normalized]<br></strong>This is the base class of brdfs that have two member variables with pure virtual “Evaluate” function.</p><p>Evaluate function takes ray_coming_direction, light_coming_direction, surface_normal, kd, ks, refraction_index, absorption_index.</p><p><strong>ModifiedBlinnPhong [exponent, normalized] : BaseBRDF<br>ModifiedPhong [exponent, normalized] : BaseBRDF<br>OriginalBlinnPhong [exponent] : BaseBRDF<br>OriginalPhong [exponent] : BaseBRDF<br>TorranceSparrow [exponent, kd_fresnel] : BaseBRDF<br></strong>All above are the inherited BRDF classes from BaseBRDF class. All above overrides the Evaluate function in their manner. Only TorranceSparrow uses the refraction_index and absorption_index parameters.</p><p>Their formulas are too simple to implement. However the hardest thing is that dot products in their values. At the beginning, they were not harmful but with the beginning of direct lighting, there were points that were sampled from the back of the object, which corrupts dot products of the normals. So I had to do sanity checks for them.</p><p>And for the OriginalPhong and ModifiedPhong, we should have calculate the perfect reflection of the incoming light, not the incoming ray. That was a little letter in the PDF that I couldn’t see at the first time, but the twentieth time.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*ejLkjYYWJyT5oxEl1oAVqw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*mojAcz-AQm-Ij4SRg5wZRA.png" /><figcaption>BlinnPhong — TorranceSparrow</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*8Rm3bCuYPLiHAwrqroDqHg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*9namALMExRr4LqXlEIkTPg.png" /><figcaption>BlinnPhong — TorranceSparrow</figcaption></figure><h4>Object Lights</h4><p>In here, there is multiple inheritence due to being an object at the same time being a light. So I defined a base class for the object lights.</p><p><strong>ObjectLightSource [radiance] : BaseLightSource<br></strong>This class have radiance as a member variable and pure virtual function for sampling. The function takes intersection_point and returns sample_point, sample_normal and pdf.</p><p><strong>LightMeshObject : BaseObject, ObjectLigthSource<br></strong>All the things related to being an object are the same. But we override the sample function and the preprocess function. In the preprocess stage, we also calculate pdf and cdf for all transformed triangle in the mesh with respect to their areas. When sampling, we choose a triangle according to its cdf value by looking with binary search. Then we choose a random point on the triangle and transform it to global frame.</p><p><strong>LightSphereObject : BaseObject, ObjectLightSource<br></strong>All the things related to being an object are the same. But we override the sample function. When sampling we choose a random direction from the region of theta max and phi. Then we choose the intersection point with the sphere and return it by transforming them to global frame.</p><p>Here, the same looking normals (a sample from the back of the object) caused that returned pdf is NaN or +Inf. So, I added sanity check to it also.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/512/1*ziPJPpbhQK93EYk07L6NNw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/512/1*f5fH67RfymTnPlLUfcxFxA.png" /><figcaption>Glossy and Diffuse objects under point light</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/512/1*2PcKvNe__B1TLMowOVKukA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/512/1*HYOcyfBntR4IoXrI5inZBg.png" /><figcaption>Glossy and Diffuse objects under area light</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/512/1*TzEDBG64yZ8Yr-XQNdpIXw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/512/1*KMJkHkMF33c9V3vLZ3U9Xg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/512/1*PMdOmIJRNSoII20ahz0Wtg.png" /><figcaption>Glossy objects under object lights with shapes : Box, Sphere, Ellipsoid</figcaption></figure><h3>Path Tracing</h3><p>I need to re-implement my tracing algorithm, due to both spaghetti-like and needing to be reordered.</p><p>All the things are the same with our regular ray tracer. (Object intersection check, texturing, shading with lights)</p><p>I added some small code block for Russian Roulette kills current ray at the beginning with respect to the possibility calculated with throughput. (The throughput is transferred between bounces as a parameter of the recursive function.)</p><p>At the end of the regular ray tracing code. I added path tracing part. Here is the pseudocode.</p><ol><li>Define sample count (For primary rays, it’s splitting factor, otherwise 1)</li><li>Build orthonormal basis for intersection normal.</li><li>For every sample:<br>1. Sample the angles (Cosine for importance sampling, otherwise uniform)<br>2. Create sample ray<br>3. Calculate pdf value of the current surface BRDF<br>4. Trace path of the sample ray<br>5. Take the return value as indirect_light<br>6. Clip indirect_light value of sample_max_val is enabled<br>7. If NEE is enabled, sample a point from a light object and calculate light value, then clip if sample_max_val is enabled<br>8. If MIS_BALANCE is disabled, use indirect_light_value<br>8. If MIS_BALANCE is enabled but light didn’t hit, use the indirect_light value<br>9. If MIS_BALANCE is enabled and the light hit, use the balanced light value</li><li>Divide the total light value to sample count.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/512/1*4pFWos4Gs4r4yE7jf2ljMg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/512/1*QlG5dUSp6y24xsnziwQGOA.png" /><figcaption>Path Tracing diffuse objects under object lights : Prism and Sphere</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/512/1*GOpROBXKIZqn-zefCqtA8g.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/512/1*xGWY4INJAmpCKhS2PkprDQ.png" /><figcaption>Default path tracing of advanced objects and diffuse objects</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/512/1*3-Uu8w6d1ZU9xjmGwZAJ2w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/512/1*5Lre82ihKERTxXuaIhLymQ.png" /><figcaption>Importance sampling of advanced objects and diffuse objects</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/512/1*666v1f0Dg_A2TAqL2sNn-Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/512/1*QZDJutgJYdyAHvouPWGFVQ.png" /><figcaption>Importance sampling and NEE with MIS_BALANCE of advanced objects and diffuse objects</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/512/1*ehx9XsDNcsUvRv1AMHc9Kg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/512/1*1Z84PHr6bh4pjUcC-UpvCg.png" /><figcaption>With Splitting Importance sampling and NEE with MIS_BALANCE of advanced objects and diffuse objects</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/512/1*UL64q6QBihQxYJTBbFDLAA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/512/1*wjkiuqZ6QkqzYq7OFI9aYA.png" /><figcaption>With Russian Roulette Importance sampling and NEE with MIS_BALANCE of advanced objects and diffuse objects</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/512/1*tgmH0bpz8J0iOVZ1uFYY1g.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/512/1*rWie_jGsgfx2tudaAQBvnQ.png" /><figcaption>With Clamping Importance sampling and NEE with MIS_BALANCE of advanced objects and diffuse objects</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/512/1*o18pTYKQX6yvAAXk5SbRmg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/512/1*zOIoLvxXWFEMPYcCiXxyWA.png" /><figcaption>With Splitting and Clamping Importance sampling and NEE with MIS_BALANCE of advanced objects and diffuse objects</figcaption></figure><h3>Results</h3><ol><li>Importance sampling slightly decreased the noise, but it’s effect may be negligible.</li><li>It is obvious that NEE makes us easier to find the light comparing with default sampling.</li><li>Splitting and decreasing number of samples per pixel really holds the same variance with the high number of samples per pixel. However, we can see some variance increase in glass and mirror objects. (There may be due to my implementation, or there may be a real problem in there)</li><li>Russian Roulette increased some noise at some points, but it is negligible I think.</li><li>Clamping corrects salt and pepper noise in addition to white explosions. I wasn’t expecting that!</li></ol><p>Thank you for reading!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a5813648cafa" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Advanced Ray Tracing : Part 5–2025F]]></title>
            <link>https://ahmetksasmaz.medium.com/advanced-ray-tracing-part-5-2025f-dd5d29cee44f?source=rss-b8f6732d47a4------2</link>
            <guid isPermaLink="false">https://medium.com/p/dd5d29cee44f</guid>
            <category><![CDATA[ray-tracing]]></category>
            <category><![CDATA[tone-mapping]]></category>
            <dc:creator><![CDATA[Ahmet Kürşad Şaşmaz]]></dc:creator>
            <pubDate>Tue, 06 Jan 2026 18:30:58 GMT</pubDate>
            <atom:updated>2026-01-06T18:30:58.939Z</atom:updated>
            <content:encoded><![CDATA[<h3>Advanced Ray Tracing : Part 5–2025F</h3><p>Hello everyone!</p><p>You are reading the fifth part of the Advanced Ray Tracing series. In this part we will build HDR images and tonemapped images of our scenes.</p><p>But first, let Jacob Seed brainwashes you, the player itself! (I was planning that the intro will be a single paragraph, but couldn’t handle myself. Please read them on your free time.)</p><p>Far Cry 5, is a game that I admire because of the usage of psychology in the game. A man, named Joseph Seed, is a leader of a cult that controls the people of the town. He has 3 children. I don’t remember the first one because we eliminate him first. The second one hypnotizes you by smells spreading from some hallucinogenic plants. The third one, that I can’t forget because of the things he made it to me, Jacob Seed, is a perfect manipulator and a professional animal tamer.</p><p>Every time he captures and puts us into jail, he doesn’t give us any food or water, treats to us like a dog to tame. Then the music starts from the music box;</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FGCk1Ld11th4%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DGCk1Ld11th4&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FGCk1Ld11th4%2Fhqdefault.jpg&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/da483b9e9266dc05d2a1682a4c7ff7cb/href">https://medium.com/media/da483b9e9266dc05d2a1682a4c7ff7cb/href</a></iframe><p>We wake up in a room with a gun. The timer starts and every man that we killed gives us extra time. We run and shoot. When the labrinth is finished, we wake up in the dead bodies in real life. As you can guess, they are the ones that we killed.</p><p>For the second iteration, the timer starts with a narrow interval and the bonus time is decreased. The labrinth is longer. We try to finish as soon as possible. And wake up in the dead bodies.</p><p>For the third, above applies again, but we are professional in this game now. Finally we turn around at the corner and kill the last armored guy. And wake up in the dead bodies.</p><p>But the fourth and the last, above applies again. We think that we are pro, we turn around and shoot. But we couldn’t figure out before the bullet is fired; that the last kill is our group’s leader. As you guess, we wake up with the dead body of the leader.</p><p>Here is the detailed video of explanation:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FsWe8qH_DzKw%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DsWe8qH_DzKw&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FsWe8qH_DzKw%2Fhqdefault.jpg&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/c67393c73c1c7decf7af759789f1ac8b/href">https://medium.com/media/c67393c73c1c7decf7af759789f1ac8b/href</a></iframe><p>I will skip the unrelated parts that are about parsing the JSON file and integrating the EXR reader/writer.</p><p>We have new types of classes. First start with light sources.</p><p><strong>DirectionalLightSource [direction, radiance] : BaseLightSource</strong></p><p>This class is an inherited class of BaseLightSource. It does not have any private function but variables. We calculate directional light effects as below. We send a shadow ray through the inverse light direction from the intersection point. The remaining calculation is the same with shadow check and shading.</p><pre>for(auto&amp; directional_light : directional_lights_)<br>{<br>  Vec3f light_direction = -normalize(directional_light-&gt;direction_);<br><br>  Ray shadow_ray = {<br>      ray.pixel_, intersection_point,<br>      light_direction, ray.diff_,<br>      ray.time_};<br>  ...<br>}</pre><p><strong>SpotLightSource [position, direction, intensity, coverage_angle, falloff_angle] : BaseLightSource</strong></p><p>This class is an inherited class of BaseLightSource. It does not have any private function but variables. We calculate directional light effects as below. We send a shadow ray through the spot light position from the intersection point. Shadow check is the same but the shading differs.</p><pre>for(auto&amp; spot_light : spot_lights_)<br>{<br>  Vec3f direction_from_light = normalize(intersection_point - spot_light-&gt;position_);<br>  FP_PRECISION angle = acos(dot(direction_from_light, normalize(spot_light-&gt;direction_)));<br>  FP_PRECISION coverage_radian = spot_light-&gt;coverage_angle_ * M_PI / 180.0f;<br>  FP_PRECISION falloff_radian = spot_light-&gt;falloff_angle_ * M_PI / 180.0f;<br>  if(angle &gt; coverage_radian / 2.0f)<br>  {<br>    continue;<br>  }<br>  Vec3f value;<br>  if(angle &gt; falloff_radian / 2.0f){<br>    FP_PRECISION coeff_s = (cos(angle) - cos(coverage_radian / 2.0f)) /<br>                          (cos(falloff_radian / 2.0f) - cos(coverage_radian / 2.0f));<br>    coeff_s = coeff_s * coeff_s; // Power of 2<br>    coeff_s = coeff_s * coeff_s; // Power of 4<br>    value = spot_light-&gt;intensity_ * coeff_s / norm2(spot_light-&gt;position_ - intersection_point);<br>  }<br>  else{<br>    value = spot_light-&gt;intensity_ / norm2(spot_light-&gt;position_ - intersection_point);<br>  }<br><br>  Ray shadow_ray = {<br>      ray.pixel_, intersection_point,<br>      -direction_from_light, ray.diff_,<br>      ray.time_};<br>  ...<br>}</pre><p><strong>SphericalDirectionalLightSource [environment_type, image, sampler] : BaseLightSource</strong></p><p>This class is an inherited class of BaseLightSource. It has a public function that samples the light and returns the light value. After the light intensity value is calculated, we treat this light like ambient light source and background image at the same time. If our ray hits, it will shade the object with “sampled” light intensity. Otherwise, it will return the pixel value with “not sampled” light intensity, meaning texture coordinates determined by the ray direction / normal itself.</p><p>The algorithm below does this.</p><ol><li>Sample uniform/cosine if needed. Find orthonormal basis of the surface normal and calculate new direction with sampled angles by using the orthonormal bases. Set PDF value according to the sampling.</li><li>Find the texture coordinates according to environment map type.</li><li>Get the texture value and divide it by PDF, finally return the value.</li></ol><pre>Vec3f GetIntensity(const Vec3f&amp; surface_normal, Vec3f&amp; direction, bool no_sample = false) const<br>  {<br>    // Map direction to texture coordinates<br>    FP_PRECISION u = 0.0f;<br>    FP_PRECISION v = 0.0f;<br><br>    FP_PRECISION pdf;<br>    if(!no_sample){<br><br>      FP_PRECISION theta;<br>      FP_PRECISION phi;<br>      <br>      if(sampler_ == kUniform){<br>        uniform_hemisphere_sample(theta, phi, pdf);<br>      }<br>      else if(sampler_ == kCosine){<br>        cosine_hemisphere_sample(theta, phi, pdf);<br>      }<br>      // Find orthonormal basis<br>      Vec3f normal_prime;<br>      normal_prime.x = surface_normal.x;<br>      normal_prime.y = surface_normal.y;<br>      normal_prime.z = surface_normal.z;<br>      int min_index = 0;<br>      FP_PRECISION min_value = surface_normal.x;<br>      if (surface_normal.y &lt; min_value)<br>      {<br>        min_value = surface_normal.y;<br>        min_index = 1;<br>      }<br>      if (surface_normal.z &lt; min_value)<br>      {<br>        min_value = surface_normal.z;<br>        min_index = 2;<br>      }<br>      switch (min_index)<br>      {<br>      case 0:<br>        normal_prime.x = 1.0f;<br>        break;<br>      case 1:<br>        normal_prime.y = 1.0f;<br>        break;<br>      case 2:<br>        normal_prime.z = 1.0f;<br>        break;<br>      }<br>      normal_prime = normalize(normal_prime);<br>      Vec3f tangent = normalize(cross(normal_prime, surface_normal));<br>      Vec3f bitangent = cross(surface_normal, tangent);<br><br>      direction = normalize(tangent * (std::sin(theta) * std::cos(phi)) +<br>        bitangent * (std::sin(theta) * std::sin(phi)) +<br>        surface_normal * std::cos(theta));<br>    }<br>    else{<br>      direction = surface_normal;<br>      pdf = 1/(2*M_PI);<br>    }<br><br>    if (type_ == kLatLong)<br>    {<br>      u = (1+atan2(direction.x, -direction.z)/M_PI)/2.0;<br>      v = acos(direction.y)/M_PI;<br>    }<br>    else if (type_ == kProbe)<br>    {<br>      FP_PRECISION r = (acos(-direction.z)) / (M_PI * sqrt(direction.x * direction.x + direction.y * direction.y));<br>      u = (r*direction.x + 1.0) / 2.0;<br>      v = (-r*direction.y + 1.0) / 2.0;<br>    }<br><br>    int x = static_cast&lt;int&gt;(u * image_-&gt;width_);<br>    int y = static_cast&lt;int&gt;(v * image_-&gt;height_);<br><br>    Vec3f color_value = (*image_)(x, y);<br><br>    return color_value / pdf;<br>  }</pre><p><strong>BaseTonemapping [width, height, key_value, burn, saturation, gamma, filename]</strong></p><p>This class simply stores the tonemapping related parameters and their getter functions. Because every tonemapping algorithm uses these parameters in a different way. It has a pure virtual function with the name “ApplyToneMapping” that takes the filtered image data and updates the member variable : tonemapped image data. Every interited class from this base class overrides this function.</p><p><strong>Applying Tone Mapping</strong></p><p>Every algorithm that we will implement differs at the mapping phase. So I will explain the common sides with a blank.</p><p><strong>Common Tone Mapping</strong></p><p><em>Centering To The Key Value</em></p><pre>std::vector&lt;FP_PRECISION&gt; Lw(width_ * height_);<br>for(int i = 0; i &lt; width_ * height_; i++){<br>    Lw[i] = 0.2126 * image_data[i].x + 0.7152 * image_data[i].y + 0.0722 * image_data[i].z;<br>}<br>FP_PRECISION delta = 0.00001;<br>FP_PRECISION log_average_Lw = 0.0;<br>for(int i = 0; i &lt; width_ * height_; i++){<br>    log_average_Lw += log(delta + Lw[i]);<br>}<br>log_average_Lw = exp(log_average_Lw / (width_ * height_));<br>for(int i = 0; i &lt; width_ * height_; i++){<br>    Lw[i] = (key_value_ / log_average_Lw) * Lw[i];<br>}</pre><p><em>Mapping</em></p><pre>{<br>  ...<br>}</pre><p><em>Calculate Mapped Color &amp; Saturate &amp; Gamma &amp; Clip &amp; Normalize</em></p><pre>for(int i = 0; i &lt; width_ * height_; i++){<br>    FP_PRECISION r = image_data[i].x;<br>    FP_PRECISION g = image_data[i].y;<br>    FP_PRECISION b = image_data[i].z;<br>    FP_PRECISION L = 0.2126 * r + 0.7152 * g + 0.0722 * b;<br>    FP_PRECISION r_coeff = r / L;<br>    FP_PRECISION g_coeff = g / L;<br>    FP_PRECISION b_coeff = b / L;<br>    FP_PRECISION saturated_r = Lw[i] * pow(r_coeff, saturation_);<br>    FP_PRECISION saturated_g = Lw[i] * pow(g_coeff, saturation_);<br>    FP_PRECISION saturated_b = Lw[i] * pow(b_coeff, saturation_);<br>    FP_PRECISION gamma_corrected_r = 255 * pow(std::min(std::max(saturated_r, 0.0), 1.0), 1.0 / gamma_);<br>    FP_PRECISION gamma_corrected_g = 255 * pow(std::min(std::max(saturated_g, 0.0), 1.0), 1.0 / gamma_);<br>    FP_PRECISION gamma_corrected_b = 255 * pow(std::min(std::max(saturated_b, 0.0), 1.0), 1.0 / gamma_);<br>    tonemapped_image_data_[i * 3 + 0] = (unsigned char)(gamma_corrected_r);<br>    tonemapped_image_data_[i * 3 + 1] = (unsigned char)(gamma_corrected_g);<br>    tonemapped_image_data_[i * 3 + 2] = (unsigned char)(gamma_corrected_b);<br>}</pre><p><strong>Where The Tone Mapping Differs</strong></p><p><em>PhotographicToneMapping</em></p><pre>// We do not do any extra thing rather than the core tone mapping algorithm.<br>if(burn_ &gt; 0.0){<br>    FP_PRECISION l_white = 0.0;<br>    std::vector&lt;FP_PRECISION&gt; Lw_sorted = Lw;<br>    std::sort(Lw_sorted.begin(), Lw_sorted.end());<br>    int burn_index = static_cast&lt;int&gt;((1.0 - burn_/100.0) * Lw_sorted.size());<br>    l_white = Lw_sorted[burn_index];<br>    for(int i = 0; i &lt; width_ * height_; i++){<br>        Lw[i] = (Lw[i] * (1.0 + (Lw[i] / (l_white * l_white)))) / (1.0 + Lw[i]);<br>    }<br>} else {<br>    for(int i = 0; i &lt; width_ * height_; i++){<br>        Lw[i] = Lw[i] / (1.0 + Lw[i]);<br>    }<br>}</pre><p><em>ACESToneMapping</em></p><pre>// A = 2.51<br>// B = 0.03<br>// C = 2.43<br>// D = 0.59<br>// E = 0.14<br>// map(L) = ((L(LA+B))/(L(LC+D)+E))<br><br>std::function&lt;FP_PRECISION(FP_PRECISION)&gt; map = [](FP_PRECISION L){<br>    FP_PRECISION A = 2.51;<br>    FP_PRECISION B = 0.03;<br>    FP_PRECISION C = 2.43;<br>    FP_PRECISION D = 0.59;<br>    FP_PRECISION E = 0.14;<br>    return (L * (L * A + B)) / (L * (L * C + D) + E);<br>};<br><br>if(burn_ &gt; 0.0){<br>    FP_PRECISION l_white = 0.0;<br>    std::vector&lt;FP_PRECISION&gt; Lw_sorted = Lw;<br>    std::sort(Lw_sorted.begin(), Lw_sorted.end());<br>    int burn_index = static_cast&lt;int&gt;((1.0 - burn_/100.0) * Lw_sorted.size());<br>    l_white = Lw_sorted[burn_index];<br><br>    for(int i = 0; i &lt; width_ * height_; i++){<br>        Lw[i] = map(Lw[i]) / map(l_white);<br>    }<br>} else {<br>    for(int i = 0; i &lt; width_ * height_; i++){<br>        Lw[i] = map(Lw[i]);<br>    }<br>}</pre><p><em>FilmicToneMapping</em></p><pre>// a = 0.22;<br>// b = 0.30;<br>// c = 0.10;<br>// d = 0.20;<br>// e = 0.01;<br>// f = 0.30;<br>// map(L) = ((L(aL + cb) + de)/(L(aL + b) + df)) – e/f;<br><br>std::function&lt;FP_PRECISION(FP_PRECISION)&gt; map = [](FP_PRECISION L){<br>    FP_PRECISION a = 0.22;<br>    FP_PRECISION b = 0.30;<br>    FP_PRECISION c = 0.10;<br>    FP_PRECISION d = 0.20;<br>    FP_PRECISION e = 0.01;<br>    FP_PRECISION f = 0.30;<br>    return ((L * (a * L + c * b) + d * e) / (L * (a * L + b) + d * f)) - e / f;<br>};<br><br>if(burn_ &gt; 0.0){<br>    FP_PRECISION l_white = 0.0;<br>    std::vector&lt;FP_PRECISION&gt; Lw_sorted = Lw;<br>    std::sort(Lw_sorted.begin(), Lw_sorted.end());<br>    int burn_index = static_cast&lt;int&gt;((1.0 - burn_/100.0) * Lw_sorted.size());<br>    l_white = Lw_sorted[burn_index];<br><br>    for(int i = 0; i &lt; width_ * height_; i++){<br>        Lw[i] = map(Lw[i]) / map(l_white);<br>    }<br>} else {<br>    for(int i = 0; i &lt; width_ * height_; i++){<br>        Lw[i] = map(Lw[i]);<br>    }<br>}</pre><p>Literally, they just change the shape of the curve, nothing else. Here are the results. There are some bugs that I couldn’t understand the actual reason yet. (Some ply files create malloc rush, etc.)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*OpY8CceHxcQMOj4JqPbv8Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*0jY797vkhqayFD0QALw3Mg.png" /><figcaption>Example of Directional Light and Point Light</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*u0i5_I19ygsX52531ZvsDQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*010VCPuAedgt0p30o6BViA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*sHgisQCBWZRt9SVrbfLArA.png" /><figcaption>Photographic Tonemapping — Filmic Tonemapping — ACES Tonemapping</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*ovlr64NvQBlOUuaMb7ts_g.png" /><figcaption>Example of Spot Light</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/512/1*sNxkq2zEDakHbHH7F7zglQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/512/1*v-cMyQZscU8u0VdndzDSJg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/512/1*ZlWsoLYuNBdWz0gPWq38rw.png" /><figcaption>Example of LatLong Environment Map With Photographic Tonemapping — Filmic Tonemapping — ACES Tonemapping</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/512/1*2WTcJln-MnzWAYJZoRre8w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/512/1*pb13M8QjaWB0dZplp5jDTQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/512/1*s0xJlN2-BZe6--utTB0IJA.png" /><figcaption>Example of Probe Environment Map With Photographic Tonemapping — Filmic Tonemapping — ACES Tonemapping</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*OPwRzK3mjP5Gx1GNBbfTkw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*DsYZhETlbaJGUQjVgN0spw.png" /><figcaption>Glass Sphere &amp; Mirror Sphere with Spherical Directional Light with Photographic Tonemapping</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*rr5j26M-4B5c5U6xIkgtAw.png" /><figcaption>An Example of Spherical Directional Light Shading</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*3KB0wanL4iFeRKJhoc-tsw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*c-MK_ZGgrhVAsynOFITiuQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*22HITrGx098ApRvmC0knyw.png" /><figcaption>Spherical Directional Light Shading with Photographic Tonemapping — Filmic Tonemapping — ACES Tonemapping</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ihTg0YJ-DM6dyKMcFAyxkA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*itrcJN5GZqFWWXk3kCvoFw.png" /><figcaption>ACES Tonemapping with Burn 0% &amp; Burn 1%</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*02t8HbJIhSoXVUz4t0_EGA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bQBzWc8bezURGEL1WbCJjQ.png" /><figcaption>Filmic Tonemapping with Burn 0% and Burn 1%</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BpLkED2cfOW61miEBVzRsA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BjVuFoZGgldqhLOJncqDkA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RdP83CGx-nvYvqPMbqSDmw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tozWKwkF9Oem2lRQbSqcmQ.png" /><figcaption>All Photographic Tonemapping — Top Left : Key 0.09 Saturation 1.0 Burn 1% — Top Right : Key 0.18 Saturation 1.0 Burn 0% — Bottom Left : Key 0.18 Saturation 1.0 Burn 1% — Bottom Right : Key 0.18 Saturation 1.2 Burn 1%</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dd5d29cee44f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Advanced Ray Tracing : Part 4–2025F]]></title>
            <link>https://ahmetksasmaz.medium.com/advanced-ray-tracing-part-3-2025f-1a1306884fe0?source=rss-b8f6732d47a4------2</link>
            <guid isPermaLink="false">https://medium.com/p/1a1306884fe0</guid>
            <category><![CDATA[mapping]]></category>
            <category><![CDATA[texture]]></category>
            <category><![CDATA[trilinear]]></category>
            <category><![CDATA[bilinear]]></category>
            <category><![CDATA[ray-tracing]]></category>
            <dc:creator><![CDATA[Ahmet Kürşad Şaşmaz]]></dc:creator>
            <pubDate>Mon, 22 Dec 2025 18:39:32 GMT</pubDate>
            <atom:updated>2025-12-22T18:42:51.145Z</atom:updated>
            <content:encoded><![CDATA[<h3>Advanced Ray Tracing : Part 4–2025F</h3><p>Hello everyone!</p><p>You are reading the fourth part of the Advanced Ray Tracing series. In this part we will struggle with textures in general. Actually, struggle with weird math behind it. (It gets more sophisticated as you read the blog).</p><p>Starting with my traditional introduction: A series of information that takes place in your brain without any reason but you don’t regret it. Here it is.</p><p>There is no simulation more realistic than a multiplayer game! And there is no greater experimentation about pandemics in an RPG game because you have the log of every single player!</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2F9nP0ot-gnso&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3D9nP0ot-gnso&amp;image=http%3A%2F%2Fi.ytimg.com%2Fvi%2F9nP0ot-gnso%2Fhqdefault.jpg&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/3aac8e50d170a3b8a4d23e67b220e838/href">https://medium.com/media/3aac8e50d170a3b8a4d23e67b220e838/href</a></iframe><p>First of all, talk about small details. This homework enforced me to define all matrix and vector operations for size 2. In addition, parsing the JSON file and new type of ply files was like a side quest. You can’t kill a dragon without catching a mouse. (Skyrim taught that.)</p><p>Secondly, we have new types of classes.</p><p><strong>BaseImage [path]</strong></p><p>It simply reads the image without any modification on it. We will upgrade this class at implementing trilinear interpolation.</p><p><strong>BaseTextureMap [decal_mode, bump_factor]</strong></p><p>Every texture map needs to be inherited from this class. Bump factor doesn’t have to be specified. There are some getter functions for returning the coefficients of the decal mode. (For example, GetDiffuseCoefficient returns 1.0 if decal mode is replace_kd, 0.5 if decal_mode is blend_kd and 0.0 else.)</p><p>In addition to these, this class have pure virtual functions for getting color value and getting gradient value, so that every texture map requires to implement the functions. GetColorAt function will be upgraded for trilinear interpolation later.</p><p><strong>CheckerboardTextureMap [decal_mode, bump_factor, scale, offset, black_color, white_color] : BaseTextureMap</strong></p><p>This class overrides GetColorAt function as below:</p><pre>bool x = ((int) floor((space_coords.x + offset_) * scale_)) % 2;<br>bool y = ((int) floor((space_coords.y + offset_) * scale_)) % 2;<br>bool z = ((int) floor((space_coords.z + offset_) * scale_)) % 2;<br><br>bool xorXY = x != y;<br>if (xorXY != z){<br>  return black_color_;<br>}<br>else{<br>  return white_color_;<br>}</pre><p>And the GetGradientAt function will be overriden as below because gradient is always zero except edges, undefined on the edges:</p><pre>gradient_u = Vec3f{0.0, 0.0, 0.0};<br>gradient_v = Vec3f{0.0, 0.0, 0.0};</pre><p><strong>PerlinTextureMap [decal_mode, bump_factor, noise_conversion, noise_scale, num_octaves] : BaseTextureMap</strong></p><p>I couldn’t even understand and implement Perlin Noise in the undergrad course 477. Correctly implementing this is a success for me, and probably that course was not the right time to understand the concept. This class overrides GetColorAt function as below:</p><pre>FP_PRECISION s = 0.0;<br>for (int i = 0; i &lt; num_octaves_; i++){<br>  FP_PRECISION frequency = pow(2.0, i);<br>  FP_PRECISION amplitude = pow(0.5, i);<br>  s += amplitude *  perlin_noise(frequency * noise_scale_ * space_coords);<br>}<br>return Vec3f{s,s,s};</pre><p>However, we need a helper function to calculate Perlin noise, this function is as below. At first I was expecting that Perlin noise would work, the problem was not permutating the index table.</p><pre>Vec3f gradients[16] = { ... }; // Shrinked<br>int table[16] = { 15, 10, 5, 0, 14, 9, 4, 3, 13, 8, 7, 2, 12, 11, 6, 1 };<br>auto fade = [](FP_PRECISION t) {<br>  return t * t * t * (t * (t * -6 + 15) - 10) + 1;<br>};<br><br>int xi = (int)floor(p.x);<br>int yi = (int)floor(p.y);<br>int zi = (int)floor(p.z);<br><br>FP_PRECISION n_prime = 0.0;<br>for (int dx = 0; dx &lt;= 1; dx++) {<br>  for (int dy = 0; dy &lt;= 1; dy++) {<br>    for (int dz = 0; dz &lt;= 1; dz++) {<br>      int idx;<br>      idx = table[abs(zi + dz) % 16];<br>      idx = table[abs(yi + dy + idx) % 16];<br>      idx = table[abs(xi + dx + idx) % 16];<br><br>      Vec3f distance_vector = Vec3f{p.x - (xi + dx), p.y - (yi + dy), p.z - (zi + dz)};<br>      n_prime += dot(gradients[idx], distance_vector) * fade(abs(distance_vector.x)) * fade(abs(distance_vector.y)) * fade(abs(distance_vector.z));<br>    }<br>  }<br>}<br><br>if(noise_conversion_ == RawTextureMapNoiseConversionType::kAbsVal) {<br>  n_prime = abs(n_prime);<br>}else{<br>  n_prime = (n_prime + 1.0) / 2.0;<br>}<br><br>return n_prime;</pre><p>GetGradientAt function of PerlinNoise is just taking derivative from the limit formula:</p><pre>FP_PRECISION delta = 1e-4;<br>Vec3f point_x1 = space_coords + delta * normalize(hit_tangent_vector);<br>Vec3f point_x0 = space_coords - delta * normalize(hit_tangent_vector);<br>Vec3f point_y1 = space_coords + delta * normalize(hit_bitangent_vector);<br>Vec3f point_y0 = space_coords - delta * normalize(hit_bitangent_vector);<br>Vec3f color_x1 = GetColorAt(tex_coords, point_x1, Vec2f{}, Vec2f{});<br>Vec3f color_x0 = GetColorAt(tex_coords, point_x0, Vec2f{}, Vec2f{});<br>Vec3f color_y1 = GetColorAt(tex_coords, point_y1, Vec2f{}, Vec2f{});<br>Vec3f color_y0 = GetColorAt(tex_coords, point_y0, Vec2f{}, Vec2f{});<br>FP_PRECISION grad_u_x = (color_x1.x - color_x0.x) * (1.0 / (2.0 * delta));<br>FP_PRECISION grad_u_y = (color_x1.y - color_x0.y) * (1.0 / (2.0 * delta));<br>FP_PRECISION grad_u_z = (color_x1.z - color_x0.z) * (1.0 / (2.0 * delta));<br>FP_PRECISION grad_v_x = (color_y1.x - color_y0.x) * (1.0 / (2.0 * delta));<br>FP_PRECISION grad_v_y = (color_y1.y - color_y0.y) * (1.0 / (2.0 * delta));<br>FP_PRECISION grad_v_z = (color_y1.z - color_y0.z) * (1.0 / (2.0 * delta));<br>gradient_u = Vec3f{grad_u_x, grad_u_y, grad_u_z};<br>gradient_v = Vec3f{grad_v_x, grad_v_y, grad_v_z};</pre><p><strong>ImageTextureMap [decal_mode, bump_factor, image &lt;BaseImage&gt;, interpolation_mode normalizer] : BaseTextureMap</strong></p><p>Let’s dive into the most troublesome thing.</p><p>GetColorAt function is overriden as below (will be upgraded when trilinear interpolation is explained):</p><pre>FP_PRECISION u = tex_coords.x - floor(tex_coords.x);<br>FP_PRECISION v = tex_coords.y - floor(tex_coords.y);<br><br>FP_PRECISION x = u * image_-&gt;width_;<br>FP_PRECISION y = v * image_-&gt;height_;<br><br>if (interpolation_mode_ == RawTextureMapInterpolationMode::kNearest){<br>  int xi = static_cast&lt;int&gt;(round(x));<br>  int yi = static_cast&lt;int&gt;(round(y));<br>  Vec3f color_uc = (*image_)(xi, yi) / normalizer_;<br>  return Vec3f{color_uc.x, color_uc.y, color_uc.z};<br>}<br>else if (interpolation_mode_ == RawTextureMapInterpolationMode::kBilinear){<br>  int x0 = static_cast&lt;int&gt;(floor(x));<br>  int x1 = x0 + 1;<br>  int y0 = static_cast&lt;int&gt;(floor(y));<br>  int y1 = y0 + 1;<br><br>  FP_PRECISION sx = x - x0;<br>  FP_PRECISION sy = y - y0;<br><br>  Vec3f c00 = (*image_)(x0, y0) / normalizer_;<br>  Vec3f c10 = (*image_)(x1, y0) / normalizer_;<br>  Vec3f c01 = (*image_)(x0, y1) / normalizer_;<br>  Vec3f c11 = (*image_)(x1, y1) / normalizer_;<br><br>  Vec3f c0 = (1 - sx) * c00 + sx * c10;<br>  Vec3f c1 = (1 - sx) * c01 + sx * c11;<br>  Vec3f c = (1 - sy) * c0 + sy * c1;<br><br>  return c;<br>}</pre><p>GetGradientAt function is overriden as below:</p><pre>FP_PRECISION delta_u = 1.0 / image_-&gt;width_;<br>FP_PRECISION delta_v = 1.0 / image_-&gt;height_;<br><br>Vec2f tex_coords_u1 = tex_coords + delta_u * Vec2f{1,0};// * normalize(hit_u_vector);<br>Vec2f tex_coords_u2 = tex_coords - delta_u * Vec2f{1,0};// * normalize(hit_u_vector);<br>Vec3f color_u1 = GetColorAt(tex_coords_u1, space_coords);<br>Vec3f color_u2 = GetColorAt(tex_coords_u2, space_coords);<br><br>Vec2f tex_coords_v1 = tex_coords + delta_v * Vec2f{0,1};// * normalize(hit_v_vector);<br>Vec2f tex_coords_v2 = tex_coords - delta_v * Vec2f{0,1};// * normalize(hit_v_vector);<br>Vec3f color_v1 = GetColorAt(tex_coords_v1, space_coords);<br>Vec3f color_v2 = GetColorAt(tex_coords_v2, space_coords);<br><br>Vec3f grad_vec_u = (color_u1 - color_u2) / (2*delta_u);<br>Vec3f grad_vec_v = (color_v1 - color_v2) / (2*delta_v);<br>FP_PRECISION grad_vec_u_gray = (grad_vec_u.x + grad_vec_u.y + grad_vec_u.z)/3.0;<br>FP_PRECISION grad_vec_v_gray = (grad_vec_v.x + grad_vec_v.y + grad_vec_v.z)/3.0;<br>gradient_u = Vec3f{grad_vec_u_gray, grad_vec_u_gray, grad_vec_u_gray};<br>gradient_v = Vec3f{grad_vec_v_gray, grad_vec_v_gray, grad_vec_v_gray};</pre><p>The function looks so normal and correct, but it breaks when computing bump mapping with an image texture. However, because I had just understood the term <strong>bump </strong>actually, I didn’t have much time to implement and debug it.</p><p><strong>Changes on Other Structures</strong></p><p>Overriden <strong>Intersect</strong> function now carries hit point texture coordinates, hit point tangent vector and hit point bitangent vector also.</p><p>Every primitive (my primitives are Triangle (meshes have triangles inside in my design (to make easier low level bvh)) and Sphere) have <strong>textures</strong> member now. So that the shading and normal calculations include texture information of the hit primitive. Triangular objects (Mesh, MeshInstance, Triangle) now have texture coordinates vector in addition to vertex coordinates vector (only if they have a texture).</p><p>Texture coordinates of Sphere is calculated as below:</p><pre>FP_PRECISION x = local_point.x - center_.x;<br>FP_PRECISION y = local_point.y - center_.y;<br>FP_PRECISION z = local_point.z - center_.z;<br>FP_PRECISION r = sqrt(x * x + y * y + z * z);<br>FP_PRECISION p = atan2(z, x);<br>FP_PRECISION t = acos(y / r);<br><br>FP_PRECISION u = (-p + M_PI) / (2.0 * M_PI);<br>FP_PRECISION v = (t / M_PI);<br>tex_coords = Vec2f{u, v};</pre><p>Tangent and bitangent vector of Sphere is calculated as below (not certain about vector transformation to global frame, these vectors fail at transformed bump mapping):</p><pre>Vec3f P_val = {r*sin(t)*cos(p), r*cos(t), r*sin(t)*sin(p)};<br>Vec3f tangent;<br>tangent.x = (2 * M_PI * P_val.z);<br>tangent.y = 0;<br>tangent.z = (-2 * M_PI * P_val.x);<br>Vec3f bitangent;<br>bitangent.x = (M_PI * P_val.y * cos(p));<br>bitangent.y = (-M_PI * r * sin(t));<br>bitangent.z = (M_PI * P_val.y * sin(p));<br>tangent_vector = transform_matrix_ ^ tangent;<br>bitangent_vector = transform_matrix_ ^ bitangent;</pre><p>Texture coordinates of Triangle is calculated as below (u and v are barycentric coordinates):</p><pre>FP_PRECISION w = 1 - u - v;<br>FP_PRECISION tex_u =<br>    tex_v0_.x * w + tex_v1_.x * u + tex_v2_.x * v;<br>FP_PRECISION tex_v =<br>    tex_v0_.y * w + tex_v1_.y * u + tex_v2_.y * v;<br>tex_coords = Vec2f{tex_u, tex_v};</pre><p>Tangent and bitangent vector of Triangle is calculated as below (not certain about vector calculation and transformation to global frame, these vectors fail at transformed bump mapping):</p><pre>// Calculate hit u and v gradient vectors<br>hit_u_vector = Vec2f{tex_v1_.x - tex_v0_.x, tex_v1_.y - tex_v0_.y};<br>hit_v_vector = Vec2f{tex_v2_.x - tex_v0_.x, tex_v2_.y - tex_v0_.y};<br>// Calculate tangent and bitangent vectors<br>Mat2x2f uv_matrix = Mat2x2f{{{hit_u_vector.x, hit_u_vector.y},<br>                                 {hit_v_vector.x, hit_v_vector.y}}};<br>FP_PRECISION det_uv = uv_matrix.m[0][0] * uv_matrix.m[1][1] - uv_matrix.m[0][1] * uv_matrix.m[1][0];<br>Mat2x2f inv_uv_matrix;<br>inv_uv_matrix.m[0][0] = uv_matrix.m[1][1] / det_uv;<br>inv_uv_matrix.m[0][1] = -uv_matrix.m[0][1] / det_uv;<br>inv_uv_matrix.m[1][0] = -uv_matrix.m[1][0] / det_uv;<br>inv_uv_matrix.m[1][1] = uv_matrix.m[0][0] / det_uv;<br>tangent_vector = Vec3f{<br>    inv_uv_matrix.m[0][0] * edge1.x + inv_uv_matrix.m[0][1] * edge2.x,<br>    inv_uv_matrix.m[0][0] * edge1.y + inv_uv_matrix.m[0][1] * edge2.y,<br>    inv_uv_matrix.m[0][0] * edge1.z + inv_uv_matrix.m[0][1] * edge2.z};<br>bitangent_vector = Vec3f{<br>    inv_uv_matrix.m[1][0] * edge1.x + inv_uv_matrix.m[1][1] * edge2.x,<br>    inv_uv_matrix.m[1][0] * edge1.y + inv_uv_matrix.m[1][1] * edge2.y,<br>    inv_uv_matrix.m[1][0] * edge1.z + inv_uv_matrix.m[1][1] * edge2.z};<br><br>// if(dot(cross(tangent_vector, bitangent_vector), normal_) &lt; 0) {<br>//   tangent_vector = tangent_vector * -1.0;<br>// }<br>tangent_vector = transform_matrix_ ^ tangent_vector;<br>bitangent_vector = transform_matrix_ ^ bitangent_vector;</pre><p><strong>RecursiveRayTracingAlgorithm</strong> function changed little bit. After check intersection and before shading, I iterate all textures belong to the hit object and specify coefficients (kd, ks, replacing or bumping normal etc.)</p><p>If we have things to do about shading coefficients, I forward the coefficients and the texture color value to shading part. If we have things to do about normals, I calculate them immediately after iterating textures.</p><p>Replace normal procedure does these:</p><pre>Mat4x4f tbn_matrix;<br>Vec3f normalized_tangent = normalize(hit_tangent_vector);<br>Vec3f normalized_bitangent = normalize(hit_bitangent_vector);<br>tbn_matrix.m[0][0] = normalized_tangent.x;<br>tbn_matrix.m[1][0] = normalized_tangent.y;;<br>tbn_matrix.m[2][0] = normalized_tangent.z;<br>tbn_matrix.m[0][1] = normalized_bitangent.x;<br>tbn_matrix.m[1][1] = normalized_bitangent.y;;<br>tbn_matrix.m[2][1] = normalized_bitangent.z;<br>tbn_matrix.m[0][2] = hit_normal.x;<br>tbn_matrix.m[1][2] = hit_normal.y;<br>tbn_matrix.m[2][2] = hit_normal.z;<br>texture_normal_value = normalize(texture_value * 2.0 - Vec3f{1.0f, 1.0f, 1.0f});<br>Vec3f modified_normal = tbn_matrix ^ texture_normal_value;<br>hit_normal = normalize(modified_normal);</pre><p>Bump normal procedure does these (not so sure works correctly, it fails with transformed or image textures as bump value, but I will explain later what I did wrong):</p><pre>texture-&gt;GetGradientAt(hit_tex_coords, ray.origin_ + ray.direction_ * t_hit,  hit_u_vector, hit_v_vector,<br>                       hit_tangent_vector, hit_bitangent_vector, texture_bump_value_u, texture_bump_value_v);<br>FP_PRECISION grad_u_scalar = (texture_bump_value_u.x + texture_bump_value_u.y + texture_bump_value_u.z) / 3.0;<br>FP_PRECISION grad_v_scalar = (texture_bump_value_v.x + texture_bump_value_v.y + texture_bump_value_v.z) / 3.0;<br><br>hit_normal = normalize(hit_normal -<br>                       texture_bump_coeff * grad_u_scalar * normalize(hit_tangent_vector) -<br>                       texture_bump_coeff * grad_v_scalar * normalize(hit_bitangent_vector));</pre><p>As not-ordinary procedure (because their if condition enforces us to walk on a completely different path), replace_all type of texture skips shading and I save the replace_background type of texture at the scene construction phase and use it if there is no hit at first recursion depth.</p><p>Here are the exports that I can render:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*X9NBBdZyaALXtxUFnNgOqw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*4KycJPX_8t7q-4awZcnguw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*lbs_apjW9XtwmrYpx3uOiA.png" /><figcaption>Normal Mapping — Bump Mapping with Transform (Fails) — Bump Mapping wo Transform (Succeeds)</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*VA1it0eZcQCDk_ISbaZJkQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*OwVmw3NcT7HvnDyMeKcFxA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*EKHLYnxJHu6hxMr6Udybbg.png" /><figcaption>Perlin Noise Shading — Perlin Noise Bump Mapping (Succeeds) — Just A Wall Textured Box</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*1oz-CUVdIGu2Cdh-mEfcgw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*lEkbMGvmwdRRK2or4QYcew.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*xYG0rP6ockCXl7TSPMWyVQ.png" /><figcaption>A Wall Textured and Normal Mapped Box — A Box With Normal Texture — Transformed Walls With Bump Mapping (Fails)</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*onoXH92gDO_NhNkXAffQuA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*08cd_7OCVOJS5zBW1Lb84w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*ldt4I5BANzn5efNjWzY5Kg.png" /><figcaption>Bilinear Interpolation — Nearest Interpolation — Nearest &amp; Bilinear Comparison on Sphere</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*WzlGHzQDRxS4LsTIGV4muw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*eee00ysh_1tCJTPdpiRnDg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*AqjNbxQwJlIgjyGi3ZpdIA.png" /><figcaption>Left And Middle Are Bump Mapping With Image Texture (Fails) — Normal Mapping With Image Texture (Succeeds)</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*RPzOZ4beeFghI4phFc4N8w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*sxNuj7ZvpSvIqizUbh3Dyw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*i4zhp_eHkhNmN4_vQP4Rgg.png" /><figcaption>Perlin Noise Shading and Bump Mapping</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*OEOmpangUDo8duh35T16mw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*nevtTTkBRuFkwgu8orjrcQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*sbvdz3yOjijUF9dfCia3PA.png" /><figcaption>Texture Shading</figcaption></figure><h4>Trilinear Interpolation</h4><p>We must update some structures to enable trilinear interpolation. We create levels of averaged and downsampled copies of the image. And we calculate what would happen if the next pixel rays were hit the object. And finally we find the interpolated color value.</p><p><strong>Image Loading Phase</strong></p><pre>unsigned char* image =<br>    stbi_load(path.c_str(), &amp;width_, &amp;height_, nullptr, 3);<br><br>if (image) {<br>  mipmapping_.push_back(std::vector&lt;std::vector&lt;Vec3f&gt;&gt;(height_, std::vector&lt;Vec3f&gt;(width_)));<br>  for (int i = 0; i &lt; height_; i++) {<br>    for (int j = 0; j &lt; width_; j++) {<br>      mipmapping_[0][i][j] = Vec3f{FP_PRECISION(image[3 * (i * width_ + j) + 0]),<br>                           FP_PRECISION(image[3 * (i * width_ + j) + 1]),<br>                           FP_PRECISION(image[3 * (i * width_ + j) + 2])};<br>    }<br>  }<br><br>  free(image);<br>} else {<br>  throw std::runtime_error(&quot;Error: The image &quot; + path_ + &quot; cannot be loaded.&quot;);<br>}<br><br>// Initialize first mipmapping level<br>int current_width = width_;<br>int current_height = height_;<br>int current_depth = 0;<br>do{<br>  current_width /= 2;<br>  current_height /= 2;<br>  current_depth++;<br>  mipmapping_.push_back(std::vector&lt;std::vector&lt;Vec3f&gt;&gt;(current_height, std::vector&lt;Vec3f&gt;(current_width)));<br><br>  for(int i = 0; i &lt; current_height; i++) {<br>    for(int j = 0; j &lt; current_width; j++) {<br>      Vec3f avg_color = (mipmapping_[current_depth-1][2*i][2*j] + mipmapping_[current_depth-1][2*i][2*j+1] + mipmapping_[current_depth-1][2*i+1][2*j] + mipmapping_[current_depth-1][2*i+1][2*j+1]) / 4.0;<br>      mipmapping_[current_depth][i][j] = avg_color;<br>    }<br>  }<br>}<br>while(current_height &gt; 1 &amp;&amp; current_width &gt; 1);</pre><p><strong>Ray Differences Phase</strong></p><p>Our rays have two new values now.</p><pre>Vec3f direction_i = {0,0,0};<br>Vec3f direction_j = {0,0,0};</pre><p>And ray tracing algorithm is expanded to find the intersection plane using hit point and hit normal and calculate intersections of both differential rays. Then compute the texture coordinate of differentials (result_di and result_dj). The remaining belongs to ImageTextureMap class.</p><pre>// Find plane at hit point and hit normal<br>// Ray plane intersection with direction_i_delta and direction_j_delta<br>// Find texture value at other hit points<br><br>Vec3f hit_point = ray.origin_ + ray.direction_ * t_hit;<br>// Plane equation: N.(P - P0) = 0<br>// P0 = hit_point<br>// N = hit_normal<br>// P = ray.origin_ + t * di_direction<br>// t = N.(P0 - ray.origin_) / N.di_direction<br>FP_PRECISION t_hit_di = dot(hit_normal, hit_point - ray.origin_) / dot(hit_normal, ray.direction_i_);<br>FP_PRECISION t_hit_dj = dot(hit_normal, hit_point - ray.origin_) / dot(hit_normal, ray.direction_j_);<br><br>// Compute texture coordinates at these new hit points<br>Vec3f hit_point_di = ray.origin_ + ray.direction_i_ * t_hit_di;<br>Vec3f hit_point_dj = ray.origin_ + ray.direction_j_ * t_hit_dj;<br>Vec3f pijdi = hit_point_di - hit_point;<br>Vec3f pijdj = hit_point_dj - hit_point;<br>Vec3f pxyzdu = hit_tangent_vector;<br>Vec3f pxyzdv = hit_bitangent_vector;<br>Mat2x2f small_matrix;<br>Vec2f pijdi_small;<br>Vec2f pijdj_small;<br>Vec2f pxyzdu_small;<br>Vec2f pxyzdv_small;<br>Vec2f result_di;<br>Vec2f result_dj;<br>if(hit_normal.x &gt;= hit_normal.y &amp;&amp; hit_normal.x &gt;= hit_normal.z) {<br>  // x is the largest<br>  pijdi_small = Vec2f{pijdi.y, pijdi.z};<br>  pijdj_small = Vec2f{pijdj.y, pijdj.z};<br>  pxyzdu_small = Vec2f{pxyzdu.y, pxyzdu.z};<br>  pxyzdv_small = Vec2f{pxyzdv.y, pxyzdv.z};<br>}<br>else if(hit_normal.y &gt;= hit_normal.x &amp;&amp; hit_normal.y &gt;= hit_normal.z) {<br>  // y is the largest<br>  pijdi_small = Vec2f{pijdi.x, pijdi.z};<br>  pijdj_small = Vec2f{pijdj.x, pijdj.z};<br>  pxyzdu_small = Vec2f{pxyzdu.x, pxyzdu.z};<br>  pxyzdv_small = Vec2f{pxyzdv.x, pxyzdv.z};<br>}<br>else {<br>  // z is the largest<br>  pijdi_small = Vec2f{pijdi.x, pijdi.y};<br>  pijdj_small = Vec2f{pijdj.x, pijdj.y};<br>  pxyzdu_small = Vec2f{pxyzdu.x, pxyzdu.y};<br>  pxyzdv_small = Vec2f{pxyzdv.x, pxyzdv.y};<br>}<br>small_matrix = Mat2x2f{{{pxyzdu_small.x, pxyzdv_small.x},<br>                        {pxyzdu_small.y, pxyzdv_small.y}}};<br>FP_PRECISION det = small_matrix.m[0][0] * small_matrix.m[1][1] - small_matrix.m[0][1] * small_matrix.m[1][0];<br>if (std::abs(det) &lt; 1e-10) {<br>  continue;<br>}<br>Mat2x2f inv_small_matrix;<br>inv_small_matrix.m[0][0] = small_matrix.m[1][1] / det;<br>inv_small_matrix.m[0][1] = -small_matrix.m[0][1] / det;<br>inv_small_matrix.m[1][0] = -small_matrix.m[1][0] / det;<br>inv_small_matrix.m[1][1] = small_matrix.m[0][0] / det;<br>result_di = Vec2f{inv_small_matrix.m[0][0] * pijdi_small.x + inv_small_matrix.m[0][1] * pijdi_small.y,<br>                  inv_small_matrix.m[1][0] * pijdi_small.x + inv_small_matrix.m[1][1] * pijdi_small.y};<br>result_dj = Vec2f{inv_small_matrix.m[0][0] * pijdj_small.x + inv_small_matrix.m[0][1] * pijdj_small.y,<br>                        inv_small_matrix.m[1][0] * pijdj_small.x + inv_small_matrix.m[1][1] * pijdj_small.y};<br><br>Vec3f texture_value = texture-&gt;GetColorAt(hit_tex_coords, hit_point, result_di, result_dj);</pre><p>And the final thing about this type of interpolation is interpolating itself.</p><pre>else if (interpolation_mode_ == RawTextureMapInterpolationMode::kTrilinear){<br>  FP_PRECISION normi = norm2(tex_coords_di);<br>  FP_PRECISION normj = norm2(tex_coords_dj);<br>  FP_PRECISION level;<br>  if(normi &gt;= normj) {<br>    Vec2f a2b2{tex_coords_di.x * (image_-&gt;width_), tex_coords_di.y * (image_-&gt;height_)};<br>    level = std::max(log2(norm(a2b2)), 0.0);<br>  } else {<br>    Vec2f a2b2{tex_coords_dj.x * (image_-&gt;width_), tex_coords_dj.y * (image_-&gt;height_)};<br>    level = std::max(log2(norm(a2b2)), 0.0);<br>  }<br><br>  Vec3f level_color;<br>  {<br>    int x0 = static_cast&lt;int&gt;(floor(x)) &gt;&gt; static_cast&lt;int&gt;(floor(level));<br>    int x1 = x0 + 1;<br>    int y0 = static_cast&lt;int&gt;(floor(y)) &gt;&gt; static_cast&lt;int&gt;(floor(level));<br>    int y1 = y0 + 1;<br><br>    FP_PRECISION sx = (x / (1 &lt;&lt; static_cast&lt;int&gt;(floor(level)))) - x0;<br>    FP_PRECISION sy = (y / (1 &lt;&lt; static_cast&lt;int&gt;(floor(level)))) - y0;<br><br>    Vec3f c00 = (*image_)(x0, y0, floor(level)) / normalizer_;<br>    Vec3f c10 = (*image_)(x1, y0, floor(level)) / normalizer_;<br>    Vec3f c01 = (*image_)(x0, y1, floor(level)) / normalizer_;<br>    Vec3f c11 = (*image_)(x1, y1, floor(level)) / normalizer_;<br><br>    Vec3f c0 = (1 - sx) * c00 + sx * c10;<br>    Vec3f c1 = (1 - sx) * c01 + sx * c11;<br>    level_color = (1 - sy) * c0 + sy * c1;<br>  }<br>  Vec3f next_level_color;<br>  {<br>    int x0 = static_cast&lt;int&gt;(floor(x)) &gt;&gt; static_cast&lt;int&gt;(floor(level) + 1);<br>    int x1 = x0 + 1;<br>    int y0 = static_cast&lt;int&gt;(floor(y)) &gt;&gt; static_cast&lt;int&gt;(floor(level) + 1);<br>    int y1 = y0 + 1;<br><br>    FP_PRECISION sx = (x / (1 &lt;&lt; static_cast&lt;int&gt;(floor(level) + 1))) - x0;<br>    FP_PRECISION sy = (y / (1 &lt;&lt; static_cast&lt;int&gt;(floor(level) + 1))) - y0;<br><br>    Vec3f c00 = (*image_)(x0, y0, floor(level) + 1) / normalizer_;<br>    Vec3f c10 = (*image_)(x1, y0, floor(level) + 1) / normalizer_;<br>    Vec3f c01 = (*image_)(x0, y1, floor(level) + 1) / normalizer_;<br>    Vec3f c11 = (*image_)(x1, y1, floor(level) + 1) / normalizer_;<br><br>    Vec3f c0 = (1 - sx) * c00 + sx * c10;<br>    Vec3f c1 = (1 - sx) * c01 + sx * c11;<br>    next_level_color = (1 - sy) * c0 + sy * c1;<br>  }<br>  level -= floor(level);<br>  return level_color * (1-level) + next_level_color * level;<br>}</pre><p>Here are the comparisons with bilinear interpolation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*onoXH92gDO_NhNkXAffQuA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*9L7zqPE37SEopTdM_cOMwQ.png" /><figcaption>Left Bilinear — Right Trilinear</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*ldt4I5BANzn5efNjWzY5Kg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*0nc1OUzhaIdX1tsEnhBXIw.png" /><figcaption>Left Nearest &amp; Bilinear — Right Nearest &amp; Trilinear</figcaption></figure><p>Actually this interpolation made me understood better about sampling and aliasing. But there is always more…</p><h3>Bump Mapping</h3><p>I made a large title because I believe this is the thing that taught me the most.</p><p>Let’s say that f(x,y,z) our surface function and n(x,y,z) our normal at point (x,y,z). And we want to <strong>bump </strong>(let’s say d)this surface with a function defined in all (x,y,z) space <strong>in</strong> <strong>theory</strong>. Bumping the surface means that, we move out surface point along the normal with the magnitude of multiplication of a factor and the value of bump at that point (x,y,z). So, our representation becomes f’(x,y,z) = f(x,y,z) + k * d(x,y,z) * n(x,y,z).</p><p>This is so normal! But the difficulty occurs at calculating the new surface normal. Initial normal is the normal of the surface plane which is calculated with f(x,y,z) values. However, out new normal is the normal of the new surface plane with is calculated with f’(x,y,z) values.</p><p>I wished again to code continuous universe, not the discrete one! Because discretion lose so much things with sampling, and d(x,y,z) values depend on the image texture coordinates, we must be careful about the vector magnitudes, differential magnitudes.</p><p>If we have infinite small nearest values of f’(x,y,z), that would be too easy. However, how much our step should small? For too small steps, there are certain no difference in d(x,y,z) because the image plane is not continuous also. Even if the image plane have high resolution, our ray represents an area from the surface, not the point itself. That causes to very small changes in f’(x,y,z) points but the results won’t be affected with this small differences.</p><p>Still I couldn’t figure out what should I do exactly, probably I should write and derive equations with pen &amp; paper. But I feel failing this will be a milestone of my science knowledge because this problem consist most of the concepts (derivation, sampling, frame transforms etc).</p><p>This is definitely not a point of return, this is the point I must walk further. (And slowly I figure out that graphics uses all the science :) )</p><p>Thanks for reading!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1a1306884fe0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Advanced Ray Tracing Part 3–2025F]]></title>
            <link>https://ahmetksasmaz.medium.com/advanced-ray-tracing-part-3-2025f-ae4364358cbc?source=rss-b8f6732d47a4------2</link>
            <guid isPermaLink="false">https://medium.com/p/ae4364358cbc</guid>
            <dc:creator><![CDATA[Ahmet Kürşad Şaşmaz]]></dc:creator>
            <pubDate>Wed, 26 Nov 2025 08:10:36 GMT</pubDate>
            <atom:updated>2025-11-26T08:10:36.444Z</atom:updated>
            <content:encoded><![CDATA[<p>Hello everyone.</p><p>Replaced the course from 2024F. Here is the link of the <a href="https://ahmetksasmaz.medium.com/advanced-ray-tracing-part-3-4207868e3791">2024F-Part3</a>.</p><p>Different from previous year, I fixed shading errors of motion blurred objects.</p><p>I noticed that motion blurred objects are darker with respect to the correct ones. The error occurs due to not inverse-translating the ray with respect to motion blur translation. Because local frame ray is correct, intersection test does not cause a problem. However, when returning the global frame, I forgot to undo motion blur translation in addition to inverse transformation matrix. And that causes shading problem just for this scene. Thankfully the material was not dielectric or mirror. It would cause corruption in reflected and refracted rays also.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*5TOQGNE8u2OZ4EmPqfpcxA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*owxzCbixjjBpbIjY3j8p1Q.png" /><figcaption>Left : Without Inverse Motion Blur Translation | Right : With Inverse Motion Blur Translation</figcaption></figure><h3>My Scenes</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*_CiTloHV7p04gePXqrV8-g.png" /><figcaption>For Simulating Color Mixing, Three Area Lights (RGB) and Two Obstacles</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*a8LX2v4NSqrXSW6P5hDExg.png" /><figcaption>Render Time : 25.82 HOURS!</figcaption></figure><h3>All Exports</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*eiKxQKYHCHP06vr6p-e7-w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*8BRlevqVPxbcXQEqh9apEw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*rrBtvDqZlH9ipbokrQ62iA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*Ad2ixuP7sec1qxfYTz23YQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/750/1*ewkp-5Tcxi4d1bor9W8Q5Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*kM8mpPwC_twqe91s382qFQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*o5LT83m6ijZ21-z28mEq4w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*owxzCbixjjBpbIjY3j8p1Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0n_pa5nt_kn7dYUqQSCWxA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*NxwitRHBBJXZWwwut3EB6Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*rqt_ren99GGbLkqNpDUiNg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*lpEcZ-gClZh_Y8JIBeC6tA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/512/1*ZF9AoY0z1zxwubMSTAqgVQ.gif" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*0P9-Atq--GqfNJYb9h171A.gif" /><figcaption>Left (2024F) : Single Precision | Right (2025F) : Double Precision (There may be GIF compression artifacts on both)</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ae4364358cbc" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Advanced Ray Tracing Part 2–2025F]]></title>
            <link>https://ahmetksasmaz.medium.com/advanced-ray-tracing-part-2-2025f-adcfaebe9902?source=rss-b8f6732d47a4------2</link>
            <guid isPermaLink="false">https://medium.com/p/adcfaebe9902</guid>
            <dc:creator><![CDATA[Ahmet Kürşad Şaşmaz]]></dc:creator>
            <pubDate>Fri, 14 Nov 2025 11:53:16 GMT</pubDate>
            <atom:updated>2025-11-14T11:53:16.294Z</atom:updated>
            <content:encoded><![CDATA[<p>Hello everyone.</p><p>Replaced the course from 2024F. Here is the link of the <a href="https://ahmetksasmaz.medium.com/advanced-ray-tracing-part-2-b2a4d3e4fe29">2024F-Part2.</a></p><p>Different from previous year, I added transformations to lights and cameras. Also there are sometimes black-white dots on high-poly meshes.</p><p>I noticed that these black-white dots occur mostly near the edges of triangles and creates some strange aliasing patterns. Just turning floating point primitive from float to double solved all of the dots.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hf3BSPRFvNTgEyg-mufMEg.png" /><figcaption>Floating Point Primitive : Float</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*w2yix5ffVWVHJCQaM60Ylg.png" /><figcaption>Floating Point Primitive : Double</figcaption></figure><p>Adding transformations to lights and cameras has enabled us to create interesting sequences. There may be artifacts due to lossy compression to fit Medium maximum file size. However, grain effect as a side effect of lossy compression makes it visually better.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*6HvrccsaDgUop05Dscl3eA.gif" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*TiGEs2tOdRqi3zX9BCUZ2w.gif" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*uPqJ1Fr0lsdoa8YLIhVFWA.gif" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/1*zIS4KlnZxKdxlcn3l9yqZw.gif" /><figcaption>Resized 1/2</figcaption></figure><h3>All Exports</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*1nfvw8EAfj7IHk8EFRiyng.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*Evuil5uxnQfPP1ZfKzli0Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*Q5vx_rRgfNJoV9-nAGybvw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*t3CeEt1z_ZcuPWOsy_lCdA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*MuDrkYywUsnx_T0LfXk61Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*NZt7ioMJiHYVyoJpQ8h2qQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*z0LjREsea6nag_vwcV3KQw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*JwWDpVLl219SFNhpGnJA7Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*f8udjAo4U9tG-xZ6h0_oqg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7lU2ePClHQTBNanh4bUqZQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*w2yix5ffVWVHJCQaM60Ylg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/768/1*0i2Mj3XovJNPX8hN7E8o8A.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5vl8-GOxI7cix8bxlYSfKg.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=adcfaebe9902" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Advanced Ray Tracing Part 1–2025F]]></title>
            <link>https://ahmetksasmaz.medium.com/advanced-ray-tracing-part-1-2025f-cc3713835e10?source=rss-b8f6732d47a4------2</link>
            <guid isPermaLink="false">https://medium.com/p/cc3713835e10</guid>
            <category><![CDATA[ray-tracing]]></category>
            <dc:creator><![CDATA[Ahmet Kürşad Şaşmaz]]></dc:creator>
            <pubDate>Sun, 26 Oct 2025 22:26:10 GMT</pubDate>
            <atom:updated>2025-10-26T22:26:10.496Z</atom:updated>
            <content:encoded><![CDATA[<p>Hello everyone.</p><p>Replaced the course from 2024F. Here is the link of the <a href="https://ahmetksasmaz.medium.com/advanced-ray-tracing-part-1-27da96c3aaa0">2024F-Part1</a>.</p><p>Different from previous year, our scene parser is changed from xml to json format, and a new primitive “Plane” is introduced.</p><p>Because my whole codebase is based on BVH, and naturally, a plane has no bounding volume; I had to exclude planes from BVH construction.</p><p>No crucial difference from the homework of the previous year. However, to be studied on something, I had conduct an analyze about scheduling strategies. Rendered images of this semester’s first homework will be added to the bottom.</p><h3>Single-Threaded Scheduling</h3><p>We have single core, so we have single worker. All work will be done by this worker. Meaning that;</p><blockquote>Total Time = Summation of Ray Tracing Workload For All Pixels / 1</blockquote><p>It does not matter how the objects are located in the scene; total workload, and total time, wouldn’t change.</p><h3>Multi-Threaded Grid Divide Scheduling</h3><p>We have multiple core, say N, so we have N workers. All work will be divided into rectangular regions and every worker will be assigned to specific region and don’t help others or don’t wait support from others.</p><p>As a result, if one worker finishes its job, it just waits. Our bottleneck will be the one with the most workload. Meaning that;</p><blockquote>Total Time = Maximum of Summation of Ray Tracing Workload For A Region / 1</blockquote><p>Assuming that the regions are divided as equal areas, meaning that there are regions number of workers. If workload deviation between regions are low, that means every worker works almost same and total time becomes;</p><blockquote>Total Time ~ Summation of Ray Tracing Workload For A Region ~ Summation of Ray Tracing Workload For All Pixels / N</blockquote><p>However, if the whole workload is focused on a single region, that means we are negligibly better than single-threaded strategy. Because;</p><blockquote>Maximum of Summation of Ray Tracing Workload For A Region ~ Summation of Ray Tracing Workload For All Pixels</blockquote><h3>Multi-Threaded Sliding Scheduling</h3><p>We have multiple core, say N, so we have N workers. All workers will focus on a single pixel. When everybody finishes, workers will focus on the new N pixels. If a worker finishes earlier, then it waits. But it won’t wait so long because the others have just workload of single pixel, not a region. To maximize utilization, we expect that no worker waits. So that, if deviation of workload of N consecutive pixels is low, that means workers wait less.</p><blockquote>Total Time = Summation of Maximum of Ray Tracing Workload For Every N Pixel Group</blockquote><p>Theoretical analysis should be focus on the conditions that increases deviation. However, the complexity of this analysis increases with respect to material and scene composition. Even flat surfaces of those pixels that intersect first may have high deviation due to reflection and refraction.</p><h3>Multi-Threaded Queue Scheduling</h3><p>We have multiple core, say N, so we have N workers. All workers will focus on a single pixel. When a worker finishes its job, its pops the next pixel from the queue. Meaning that no worker waits, therefore we achieve maximum utilization with respect to scheduling. (Assuming memory/cache operations are negligible regarding to scheduling waits.) Because every worker will be worked without any wait when the whole workload is finished, we can say all workers shared exactly equal the whole workload.</p><blockquote>Total Time = Summation of Ray Tracing Workload For All Pixels / N</blockquote><p>The good thing is it does not depend on the deviation or scene composition. Also it enables us to simplify analyze the rendering time with respect to other parameters. (Triangle count, for example)</p><h3>Distributed Scheduling</h3><p>We have multiple computers, and they have multiple cores. Meaning that our workers are multiplied by the number of computers. However, we have handicaps like parsing and constructing the scene, also preprocessing for the hierarchy should be handled for all computers. If the strategy is determined as every computer will construct its scene, it adds preload work. However, there are mechanisms that single construction and sharing with other computers through IPCs.</p><p>There is also memory and storage requirement for every computer. And finally, the rendering results should be merged somehow.</p><h3>Practical Results For Different Schedulings</h3><h4>Lobster 512–1024–2048</h4><p>Thread Queue <strong>959ms</strong> — <strong>3457ms</strong> — <strong>12901ms</strong><br>Block Divide <strong>1530ms</strong> — <strong>5509ms</strong> — <strong>18875ms</strong><br>Sliding <strong>1007ms</strong> — <strong>3593ms</strong> — <strong>13859ms</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/512/1*_cGOpp0WfckrZcLshEyXZw.png" /></figure><h4>Other Dragon 400–800–1600</h4><p>Thread Queue 164<strong>ms</strong> — 618<strong>ms</strong> — 2416<strong>ms</strong><br>Block Divide 393<strong>ms</strong> — 1453<strong>ms</strong> — 5258<strong>ms</strong><br>Sliding 165<strong>ms</strong> — 622<strong>ms</strong> — 2397<strong>ms</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/1*WD4_-tH35uXFuX7vn1ZBQA.png" /></figure><h4>Ton Roosendaal 540–1080 — 2160</h4><p>Thread Queue 203<strong>ms</strong> — 753<strong>ms</strong> — 3036<strong>ms</strong><br>Block Divide 197<strong>ms</strong> — 751<strong>ms</strong> — 3301<strong>ms</strong><br>Sliding 192<strong>ms</strong> — 749<strong>ms</strong> — 3390<strong>ms</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/540/1*CfeqtZAup3OdBa788OKthg.png" /></figure><h4>Windmill 400–800–1600</h4><p>Thread Queue 239<strong>ms</strong> — 1271<strong>ms</strong> — 3905<strong>ms</strong><br>Block Divide 317<strong>ms</strong> — 1044<strong>ms</strong> — 4293<strong>ms</strong><br>Sliding 237<strong>ms</strong> — 944<strong>ms</strong> — 3892<strong>ms</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/1*SWL6UvOCQqJgN9pRED3S3g.png" /></figure><p>As we can see, first two has biased composition. Lobster is located in the upper region of the image and the dragon is located left. These compositions cause deviation in the workload of block dividing strategy. However, others have nearly equal workload due to spreading all image and can be divided into blocks nearly equal mesh includings.</p><h3>All Exports</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/768/1*9EH3wEStyZNolA_T43P7VA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/512/1*U9Sdlfv_CkS4NnOMEr9Yng.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5UKxDb-3dUpRt4geynlM1A.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3T5f5FG9SqgkhNrMlwSaYw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FjkBUJ6gf7_BzbqWQfT-Qw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*OlaFpCzZFrlY8RAW3v3Lsg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*iIChSahZCso-wVUwEx9WBQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*AyfDn-zI79EkrZ0G5bGoUA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*Hemh-qzE-HZtQYs3xLlZeA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZM9tN4NUB58WOU-ZxTxOnQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*x3VLOjurLJQYXRHy2tVZmA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*F4H9UqN4B7aNkciNcGFnKA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4kGwLUkNkyVlfRvJBYAQ6A.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*W_k5eYHn4veNwHYd2afUfg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OZreKlw2UTaF7WIU-UldvA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*PickmCnoXcVUFoLvoOYaUA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*VoOwu0ntu5rJAKZvdtBlCQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*kz5-GDHKr1e58lqjWs245A.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*A1PKUvBza3vm0jCXI47xxQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9D-JJN23AmOxcPrH8Zzjig.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AxOO8wdogUsf7OyWUFhEyg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kE7uF8otwCCG2iwVaLrJZQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*bq79n6SVq1ostuKKejaYlQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*yM6RvMoiHWTQf7KpsHzn6A.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*u0F_L4Z5XPXzeTN_HrPXhw.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cc3713835e10" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Advanced Ray Tracing : Expansion]]></title>
            <link>https://ahmetksasmaz.medium.com/advanced-ray-tracing-expansion-9ce28f51a33c?source=rss-b8f6732d47a4------2</link>
            <guid isPermaLink="false">https://medium.com/p/9ce28f51a33c</guid>
            <category><![CDATA[exposure-triangle]]></category>
            <category><![CDATA[ray-tracing]]></category>
            <category><![CDATA[exposure]]></category>
            <dc:creator><![CDATA[Ahmet Kürşad Şaşmaz]]></dc:creator>
            <pubDate>Thu, 23 Jan 2025 22:51:36 GMT</pubDate>
            <atom:updated>2025-01-23T22:53:50.762Z</atom:updated>
            <content:encoded><![CDATA[<h3>Advanced Ray Tracing : Expansion</h3><p>Hello everyone! Here is the final part of the Advanced Ray Tracing series : Expansion. There are missing parts until this step. I would like to remind that a quote about destiny from the game Crysis 2, said by Prophet.</p><p>No music for this chapter, but proving the African proverb in an opposite way:</p><blockquote>If you think you are too small to make a difference, you haven’t spent the night with a mosquito.</blockquote><p>In 2011, a Battlefield 3 player performed a glorious kill: the player jumped from the jet, explode enemy jet with an RPG and then jumped again in the jet.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FFOaGhE_sejI%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DFOaGhE_sejI&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FFOaGhE_sejI%2Fhqdefault.jpg&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/43d61e793c66936c1352a73f58a171b1/href">https://medium.com/media/43d61e793c66936c1352a73f58a171b1/href</a></iframe><p>The company awarded the player’s success by adding it to the next Battlefield trailer.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FWS9aGypJPJ4%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DWS9aGypJPJ4&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FWS9aGypJPJ4%2Fhqdefault.jpg&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/a72433ffa68e88314d321144f4e542e0/href">https://medium.com/media/a72433ffa68e88314d321144f4e542e0/href</a></iframe><p><strong>Here we go!</strong></p><p>My purpose was simply modeling real life cameras and sensors that may have very distinct parameters that can be customizable or not.</p><p>A real life photography camera has 5 controllable parameters:</p><ol><li>Exposure time : controlling the duration of the shutter how much it will stay open (artistically it controls the motion blur effect)</li><li>Aperture : controlling the physical light enters through the lens (artistically it controls the bokeh effect)</li><li>ISO : controlling the light value multiplier to see even darkest scenes (artistically they always say the more ISO the more noise)</li><li>Focal length : controlling the zoom, if the lens enables us to configure zoom (artistically it is chosen for category of subject)</li><li>Focus ring : controlling the focus, generally done by auto focus algorithms (no one even cares, especially the ones who use glasses)</li></ol><p>However, diving into the science of creation, transmission and measuring the light energy makes bored a regular photographer. This expansion is for the curious ones.</p><p><strong>Some Photonics</strong></p><p>Some chemical reaction or movement in a material causes to create or absorb energy. All the calculations will be about energy transferring and turning the energy into another type.</p><p>Some things happen in a material (it is heated, go through a chemical reaction, electrons flow inside or surface) and the released energy packets are distributed to the world as photons. The energy of a photon is measured with its frequency. Yes, we have just explored the electromagnetic spectrum. They are just symbolizing the energy of a wave.</p><p>Many many photons are emitted with different energy levels (different wavelengths). While some of the emitted ones loitering around into the space, the other ones met with another material. Some of them is absorbed and caused another some chemical or physical thing. Some of them is turned back in different way. And the rest of them runaway between the atoms without being absorbed. First one is absorption, the second one is reflection and the last one is refraction.</p><p>We are interested in reflectance until the photon arrives our sensor. Huge number of photon is created and emitted by an “illuminant”. Only some proportion is reflected. Only some of the reflected ones are reflected again. This goes until a few photon arrives our sensor.</p><p>The reflectance proportion of a photon per specific wavelength with respect to a specific material is represented as spectral reflectance map of a material.</p><p><strong>The Trichromatic Theory (Red, Green, Blue)</strong></p><p>Some person/people said that “I can represent any color that I see with 3 primary colors by adjusting their weights.” Some experiments has done (human visual perception, SML cones …)</p><p>It is found that high coverage of visible colors can be represented by only 3 primary colors.</p><p><strong>Sensor Designs</strong></p><p>So that, we have designed our “visible spectrum” sensors according to these 3 primary colors. Some has designed different patterns (BGGR, BGRE etc.) Some has designed different layered structures.</p><p>After that, all the collected photons inside a small area (which is pixel) is filtered according to the pattern or layered architecture (notice that we have used refraction concept of the photon movement)</p><p>In the end, our collected and filtered photons went into chemical of physical interaction with a material. That material has emitted electrons after the interaction (notice that we have used absorption concept of the photon movement) Like how any material reflects different wavelengths of photons with different proportion, our material absorbs different wavelengths of photons with different proportion and creates emittance of electrons. This is called as quantum efficiency.</p><p><strong>Where The Electronics Begin</strong></p><p>Previous end is for photonics. This is where the electronics begin. We can’t measure the total energy of photons but total collected charge in capacitors. The circuit that reads the capacitor storage level is named as read out integrated circuit (ROIC). Then the analog signal is created and amplified if needed. Finally it is quantized and presented as n-bits image!</p><p><strong>My Design</strong></p><p>As you can guess, not anything is in RGB triplets anymore, but a spectral map. A ray has a spectral map with power (multiplied by coefficients like spectral reflectance coefficient of a material for that specific wavelength) as a return value rather than final RGB values. All the return values of samples are multiplied by exposure time (Implementing a poisson distribution based noise works better, but takes too much execution time! (due to both event counting and accumulating very small precision floating point numbers (which gives the same result again and again (infinite loop)))) Then summed up, if it exceeds the full well capacity (which is the maximum capacity of a capacitor), the value is clamped. Final value is amplified by gain factor, and then quantized.</p><p>PS : In order to model depth of field, sample size is calculated according to aperture size. Also, in order to model pixel size (the size of the bucket that collects photons) sample size is calculated according to aperture size.</p><p>I couldn’t believe but<strong> magically I saw that I have implemented “crop factor”</strong> concept without any modification. Changing the sensor size while keeping focal length constant changes field of view. <strong>This is a proof that my design is “consistent”!</strong></p><p><strong>My Results</strong></p><p>It can be seen that my design can model spectral mapping, color filtering arrays, spectral sensors, exposure time &amp; iso &amp; aperture &amp; focal length relations and side effects also.</p><p>I have tried to construct Cornell Box with spectral maps. Colors are changing by hue and saturation.</p><p>Seeing <strong>the same effects</strong> with different parameters while I was taking photos of a room with some objects made me proud of myself!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/528/1*PCF_TB7IxnmusKPyiYg18w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/528/1*_nPJ3eRswasV-7W_cHbaqQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/528/1*7X6Xkhb1SIJ1b6IsvCJCJA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/528/1*brS8yOXQik-YceTvBtvtJw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/528/1*QL-xg5x3BYceMdQ2jMJWzQ.png" /><figcaption>F/11 — ISO100–[1sec, 1/2sec, 1/4sec, 1/8sec, 1/15sec]</figcaption></figure><p>Here we can see the exposure time effect. At every stop, the measured number of photons divided or multiplied by two. Notice that depth of field and noise level stays the same, which is the expected one!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/528/1*b4gJUtjaXfBgE77TDwjs4A.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/528/1*_ZwBsrAAgzumv-jwGUTrkA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/528/1*TjR3hANMPagEwUj9fym4LA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/528/1*DKeTeo1Dcqri3DrbhD3H8g.png" /><figcaption>F/22–1sec — [ISO100, ISO200, ISO400, ISO800]</figcaption></figure><p>Here we can see the ISO effect. At every stop, the multiplier of the measurement is divided or multiplied by two. Notice that depth of field stays the same. However, we can’t tell the difference of exposure time by our eyes because there is no motion in the scene.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/528/1*7X6Xkhb1SIJ1b6IsvCJCJA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/528/1*pIoTLxF2bdeiFrLMBOZhaQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/528/1*RzVy4knRp2bpdmYrElJnQQ.png" /><figcaption>1/4sec — ISO100 — [F/11, F/16, F/22]</figcaption></figure><p>Here we can see the aperture effect. At every stop, the area of the aperture is multiplied or divided by two. So the sample number. Because accumulation is applied to the samples, the more samples the more brightness. Also, we can notice the depth of field effect.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/528/1*CBZiCzHYexp5gxlofP7iUg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/528/1*5jSUZmsN4issUJMTGyQ0Wg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/528/1*jqSi9MI8vOijQ-twAiqR-A.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/528/1*jqSi9MI8vOijQ-twAiqR-A.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/528/1*GIC0ysMKQPXJMgipTrskQg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/528/1*0N-VNbUQpFeascn4BNMWaw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/528/1*Vj1ksRdBLYaK9PXi0HUTiA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/528/1*2PXLC3ZPYjE5LzwZkHkpWA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/528/1*7X6Xkhb1SIJ1b6IsvCJCJA.png" /><figcaption>F/22–1/2sec — ISO200, F/22–1/4sec — ISO400, F/22–1/8sec — ISO800, F/16–1/2sec — ISO100, F/16–1/4sec — ISO200, F/16–1/8sec — ISO400, F/16–1/15sec — ISO800, F/11–1/4sec — ISO100, F/11–1/8sec — ISO200, F/11–1/15sec — ISO400</figcaption></figure><p>The most crucial part is here. We can validate that the exposure level stays the same while the three components of the exposure triangle changes. This is another proof of constancy. If we can go somewhere in the exposure triangle, we can compansate the exposure level by going the opposite way in the another component.</p><p>Thanks for reading.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9ce28f51a33c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Advanced Ray Tracing : Part 3]]></title>
            <link>https://ahmetksasmaz.medium.com/advanced-ray-tracing-part-3-4207868e3791?source=rss-b8f6732d47a4------2</link>
            <guid isPermaLink="false">https://medium.com/p/4207868e3791</guid>
            <category><![CDATA[ray-tracing]]></category>
            <category><![CDATA[shading]]></category>
            <category><![CDATA[rtx]]></category>
            <category><![CDATA[motion-blur]]></category>
            <category><![CDATA[light]]></category>
            <dc:creator><![CDATA[Ahmet Kürşad Şaşmaz]]></dc:creator>
            <pubDate>Thu, 28 Nov 2024 12:23:54 GMT</pubDate>
            <atom:updated>2024-11-28T12:23:54.622Z</atom:updated>
            <content:encoded><![CDATA[<p>Hello everyone!</p><p>You are reading the third part of the Advanced Ray Tracing Series. In this part, we will model some real life camera and scene concepts (motion blur, area light, aperture) with some tricks.</p><p>You decide to leave from a boring party and suddenly DJ drops this : <a href="https://www.youtube.com/watch?v=y9Kqb2z9Lzs">Edward Maya — Stereo Love</a></p><p>But, as a Turkish person, it rings a bell : <a href="https://www.youtube.com/watch?v=j_mf0y0YFLQ">Sezen Aksu — Zalim</a></p><p>You search for the root and then find the masterpiece : <a href="https://www.youtube.com/watch?v=fSuRaYaaUR8">Eldar Mansurov — Bayatılar</a></p><p>In this part of the project, proper parser extensions for focus distance, aperture size, motion blur and area light were added. There is a new class implementation for area light as : <strong>AreaLightSource [position, radiance, normal, size] : BaseLightSource. </strong>Every object type has a parameter for motion blur. <strong>Ray</strong> class now have two dimentional differential vector for image plane displacement and time value for time sampling.</p><p><strong>Filtering Algorithms</strong></p><ol><li><strong>Averaging Filter</strong> : Just averages the sample rays inside related pixel.</li><li><strong>Gaussian Filter</strong> : Just uses distance from pixel center as Gaussian distribution for weight of the pixel value inside related pixel.</li><li><strong>Extended Gaussian Filter</strong> : The same as with Gaussian Filter but now the weights are calculated considering the sample rays in neighbor pixels.</li></ol><p><strong>Ray Tracing Algorithm</strong></p><ol><li><strong>Area Light Sampling</strong> : While calculating the pixel value, area light calculations with random sampling was added.</li></ol><p><strong>Scheduling Algorithm</strong></p><ol><li><strong>Ray List</strong> : <strong>BaseCamera </strong>class generates only a single ray considering the image plane pixel center before. Now, it creates a sampled ray list for both pixel, aperture and time sampled. Jittered method was used for time sampling. Pixel and aperture sampling were calculated with Hammersley algorithm. After any sampling a list of numbers, they were shuffled.</li></ol><p><strong>Bounding Volume Calculation</strong></p><ol><li>Due to motion blur, bounding volume calculation is done by finding minimum and maximum axis values with original 6 points and translated 6 points.</li><li>A major bug was solved while constructing BVH that results a time consuming ray tracer. (Glaring Davids went 500ms from 70sec)</li></ol><p>Here comes the results!</p><p>All tests run on Intel i9 13900K 3.0 GHz — 5.4 GHz 24 Core processor.</p><p>For this time, time was measured in detail by <strong>chrono</strong> library. So, it is expected to be real values.</p><p>[Sample Count] Render Time (Filter Time)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/864/1*DQXraL-qV_X5zctO3zuinQ.gif" /></figure><p>[1] : 1028ms(89ms)<br>[4] : 3733ms(324ms)<br>[9] : 7956ms(685ms)<br>[16] : 13483ms(1246ms)<br>[25] : 20031ms(1937ms)<br>[36] : 29833ms(2777ms)<br>[49] : 40738ms(3765ms)<br>[64] : 52189ms(4906ms)<br>[81] : 66171ms(6202ms)<br>[100] : 80865ms(7623ms)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/864/1*CCffcEOh6R4-iwX5N4qJBw.gif" /></figure><p>[1] : 386ms(89ms)<br>[4] : 1381ms(229ms)<br>[9] : 2505ms(261ms)<br>[16] : 4617ms(875ms)<br>[25] : 6663ms(1364ms)<br>[36] : 9569ms(1761ms)<br>[49] : 11353ms(1269ms)<br>[64] : 17266ms(3452ms)<br>[81] : 21197ms(4360ms)<br>[100] : 26488ms(5362ms)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/864/1*oHn-Vz4TpR2A8hCTgJHhBA.gif" /></figure><p>[1] : 624ms(95ms)<br>[4] : 1948ms(205ms)<br>[9] : 4191ms(719ms)<br>[16] : 6801ms(1243ms)<br>[25] : 10637ms(1940ms)<br>[36] : 14783ms(2777ms)<br>[49] : 19752ms(3765ms)<br>[64] : 25793ms(4905ms)<br>[81] : 33104ms(6200ms)<br>[100] : 39864ms(7623ms)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/864/1*yqs20_0G7BzW4sFbK27NhA.gif" /></figure><p>[1] : 2247ms(297ms)<br>[4] : 7860ms(1037ms)<br>[9] : 16110ms(2277ms)<br>[16] : 25006ms(4032ms)<br>[25] : 38720ms(6288ms)<br>[36] : 54871ms(9008ms)<br>[49] : 72297ms(12219ms)<br>[64] : 90602ms(15895ms)<br>[81] : 117470ms(20079ms)<br>[100] : 148774ms(21100ms)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/864/1*coSqzRNTI-Ku-15kgWvSOA.gif" /></figure><p>[1] : 1320ms(93ms)<br>[4] : 4828ms(303ms)<br>[9] : 10454ms(645ms)<br>[16] : 18151ms(1245ms)<br>[25] : 28420ms(1939ms)<br>[36] : 41055ms(2640ms)<br>[49] : 55707ms(3770ms)<br>[64] : 72289ms(4902ms)<br>[81] : 93034ms(6184ms)<br>[100] : 111977ms(7642ms)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/864/1*z0t-mtLcoOQ0DAKa4P4A-g.gif" /></figure><p>[1] : 674ms(93ms)<br>[4] : 2306ms(326ms)<br>[9] : 4773ms(711ms)<br>[16] : 7649ms(1245ms)<br>[25] : 10583ms(896ms)<br>[36] : 16600ms(2802ms)<br>[49] : 21406ms(3385ms)<br>[64] : 28543ms(4902ms)<br>[81] : 35858ms(6171ms)<br>[100] : 43055ms(7632ms)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/512/1*ZF9AoY0z1zxwubMSTAqgVQ.gif" /><figcaption>512x512 64 Samples — 14Sec Avg Render Time — 1800ms Avg Filtering Time</figcaption></figure><p><strong>Comments</strong></p><ol><li>There are sometimes white dots in specific regions with different sample number. It may be due to some bug in filtering phase because corrupted region size matches with Gaussian kernel size.</li><li>If we are sampling while the ray we traced is inside the scene, not the camera, more sampling looks better. However, if we only sample the ray in the camera sampling does not visually differ after certain point.</li><li>It can be seen that for the same resolution and sample size, filtering time is almost equal. In general, filtering time is proportional to width, height, sample size and kernel size.</li><li>Also the rendering time is proportional to sample size.</li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4207868e3791" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>