<?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 Bharathsaireddy on Medium]]></title>
        <description><![CDATA[Stories by Bharathsaireddy on Medium]]></description>
        <link>https://medium.com/@bharathsaireddy7161?source=rss-390601cd7ad6------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*GEkI033qh2kHLhgDroIUlA.png</url>
            <title>Stories by Bharathsaireddy on Medium</title>
            <link>https://medium.com/@bharathsaireddy7161?source=rss-390601cd7ad6------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 06:14:44 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@bharathsaireddy7161/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[NeRF: Rendering Reality with Just Two MLPs]]></title>
            <link>https://medium.com/@bharathsaireddy7161/nerf-rendering-reality-with-just-two-mlps-f25919f09e2d?source=rss-390601cd7ad6------2</link>
            <guid isPermaLink="false">https://medium.com/p/f25919f09e2d</guid>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[3d-rendering]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[computer-vision]]></category>
            <category><![CDATA[3d-reconstruction]]></category>
            <dc:creator><![CDATA[Bharathsaireddy]]></dc:creator>
            <pubDate>Wed, 08 Oct 2025 15:15:54 GMT</pubDate>
            <atom:updated>2025-10-08T15:15:54.110Z</atom:updated>
            <content:encoded><![CDATA[<p>How do you reconstruct a 3D scene from a handful of 2D images without using convolutions, GANs, Diffusion models or Transformers?<br>Surprisingly, <strong>Neural Radiance Fields (NeRF)</strong> do it with just <strong>Multi-Layer Perceptrons (MLPs) </strong>and some clever sampling math.</p><p>At its core, NeRF learns a continuous 3D representation of a scene by answering one fundamental question:</p><blockquote>“At this 3D point, when viewed from this direction, what color would a camera see?”</blockquote><p>And it answers this with a simple function:</p><p>F(x, y, z, θ, ϕ) → (r, g, b, σ)</p><p>Where:</p><ul><li><strong>(x, y, z)</strong> is the position in 3D space</li><li><strong>(θ, ϕ)</strong> is the direction the camera is looking from</li><li><strong>(r, g, b)</strong> is the RGB color seen from that point</li><li><strong>σ</strong> is the volume density — how likely a ray terminates at that location</li></ul><p>The rest of this post explores how NeRF with just MLPs and some positional encoding reconstructs realistic 3d scenes with impressive accuracy.</p><h3>The Core of NeRF</h3><p>NeRF can be thought of as learning a single function:</p><p><strong>( x, y, z, θ, ϕ) ⟶ F ⟶( r, g, b, σ)</strong></p><p>At first glance, this equation looks simple. But it raises as few essential questions:</p><ol><li>What are <strong>θ</strong> and<strong> ϕ</strong>?</li><li>What exactly is <strong>F</strong>?</li><li>Where does<strong> σ</strong> come from, and how do we supervise it?</li></ol><p>Let’s begin with input.</p><h3>What are θ and ϕ?</h3><p>These two angles describe the <strong>viewing direction</strong>, that is, the direction from which the camera is looking at a 3D point.</p><ul><li><strong>θ</strong>: elevation angle from z-axis</li><li><strong>ϕ</strong>: azimuth angle from the x-axis</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/483/1*aRucgOvogZVFd_pu-FtUgA.jpeg" /></figure><p>They describe a<strong> ray direction</strong> in spherical coordinates. But MLPs don’t like the angle inputs, so we convert them to a <strong>Cartesian unit vector d.</strong></p><blockquote><strong>dₓ = sin(θ) · cos(ϕ) <br>dᵧ = cos(θ) <br>d𝓏 = sin(θ) · sin(ϕ)</strong></blockquote><blockquote><strong>The viewing direction becomes: <br>d = (dₓ, dᵧ, d𝓏)</strong></blockquote><h4>Why Not Feed Raw Angles?</h4><p>If we feed raw angles like degrees or radians directly into an MLP, we run into a core problem:</p><blockquote>Angles are periodic — but MLPs don’t know that.</blockquote><p>For example:</p><ul><li>0 and 2π represent the same direction in space.</li><li>But to the MLP, they look <strong>numerically very different</strong></li></ul><p>Even worse, a small change like:</p><ul><li>0.05 vs (2π- 0.05) radians looks like a <strong>huge numerical jump, </strong>when in reality, those directions are <strong>very close</strong> on the unit sphere.</li></ul><blockquote>This<strong> confuses the MLP</strong> — it tries to learn a function with discontinuities, even though none exist in the real world.</blockquote><p>By converting to a <strong>Cartesian unit vector, </strong>the direction input becomes <strong>smooth, continuous, and MLP-friendly,</strong> making it perfect for learning.</p><h3>What is F?</h3><p>Now that we’ve seen what goes <em>into</em> the function, let’s look at what <strong>F</strong> actually <em>is</em>.</p><p><strong>F</strong> is the function NeRF learns, it is just a Multi-Layer Perceptron — a stack of fully connected layers with <strong>ReLU </strong>activation</p><blockquote>Why ReLU?<br>Because without it, the MLP becomes just a stack of <strong>linear transformations</strong>, which <strong>cannot model non-linearity</strong> — meaning it wouldn’t be able to learn complex 3D structures.</blockquote><h4>Architectural Insight</h4><p>To encourage<strong> multiview consistency</strong>, NeRF splits the prediction task inside the MLP</p><ul><li><strong>Density</strong> <strong>σ </strong>is predicted from <strong>position</strong> (x, y, z) only</li><li><strong>Color (r, g, b)</strong> is predicted from both<strong> position </strong>(x, y, z) and <strong>viewing</strong> <strong>direction</strong> d.</li></ul><p>Here’s how it works:</p><ul><li>The MLP first processes the input position through <strong>8 fully connected layers</strong> (ReLU activation, 256 channels per layer)</li><li>This produces both the predicted density <strong>σ </strong>and a <strong>256-dimensional feature vector</strong></li></ul><p>That feature vector is then <strong>concatenated with the direction vector d</strong> and then passed through <strong>one additional fully connected layer </strong>(ReLU, 128 channels) to produce the <strong>RGB </strong>color.</p><h4>Intuition</h4><p><strong>Density</strong> = “What is there?”</p><ul><li>Independent of camera view</li><li>A tree is still a tree, no matter where you look from</li></ul><p><strong>Color = </strong>“How does it look?”</p><ul><li>Depends on the viewing angle</li><li>A shiny metal ball looks different from different angles</li></ul><h4>The Problem of Detail — Why Positional Encoding Matters</h4><p>So far, this setup works — but only up to a point.</p><p>If the scene contains finer structure, like sharp edges, thin wires, intricate textures, or rapidly changing colors, the MLP struggles. Why?</p><p>Because the <strong>input (x, y, z, d) </strong>is just a handful of floating-point numbers. That’s a <strong>low-dimensional input space</strong> trying to represent<strong> high-frequency variation </strong>across a scene.</p><blockquote>An MLP, especially a small one, just doesn’t have enough capacity to “resolve” fine-grained details from low-frequency inputs alone.</blockquote><p>You might think:</p><p><em>“But MLPs are universal approximators, right? Shouldn’t they be able to learn anything?”</em></p><p>Yes, in theory. But in practice, without help, they are biased towards learning smooth functions, not sharp transitions or tiny variations.</p><h4>Positional Encoding</h4><p>To help the MLP model those high-frequency details, NeRF uses a technique called <strong>positional encoding.</strong></p><blockquote>So we change the input dimensions using positional encoding , a trick that helps the MLP “see” both low-frequency and high-frequency patterns.</blockquote><p><strong>How?</strong></p><p>Instead of feeding raw (x, y, z) and (dx, dy, dz) directly, we transform them using sinusoidal functions of multiple frequencies:</p><blockquote><strong>γ(p)= [ sin(2⁰πp), cos(2⁰πp), sin(2¹πp), cos(2¹πp), …, sin(2ᴸ⁻¹πp),cos(2ᴸ⁻¹πp)]</strong></blockquote><p>The function γ(.) is applied separately to each of the three coordinates in x (which are normalized to lie in [-1, 1]) and to the three components of the Cartesian viewing direction unit vector <strong>d</strong> (which by construction lie in [-1, 1])</p><p>In the NeRF original paper, they have used</p><ul><li>L = 10 for γ(x) positional coodinates</li><li>L = 4 for γ(d) for viewing direction components.</li></ul><p>This means:</p><ul><li>Position gets mapped to a <strong>60D vector</strong> (20 features x 3 coords)</li><li>Direction gets mapped to a 24D vector (8 feature x 3 coords)</li></ul><p><strong>Intuition:</strong></p><p>Think of positional encoding like <strong>zooming in and out</strong> of the same signal.</p><ul><li>Low-frequency features help you learn the broad shape of the scene</li><li>High-frequency terms let you “focus” on fine-grained textures and edges.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/782/1*fN4SCZOlVSW9jjAfFncqBQ.png" /><figcaption>You can see what’s missing without positional encoding<br> <em>(Image credit:</em><a href="https://arxiv.org/abs/2003.08934"><em> NeRF original paper)</em></a></figcaption></figure><h3>Supervision, but Where Does σ Come From?</h3><p>Now that we know:</p><ul><li>What the inputs to NeRF are (position and direction),</li><li>How they are encoded (via positional encoding),</li><li>And how they are processed (through the MLP),</li></ul><p>.. it’s time to ask a much deeper question:</p><p>We get the RGB values from ground truth images, and we can compare those with rendered images and train the model.</p><p>But what about <strong>σ</strong>, the <strong>volume density</strong>?</p><ul><li>Where does this value come from?</li><li>Is it supervised directly?</li><li>Or is it somehow inferred?</li></ul><p>To answer that, we need to look beyond MLP and dive into classical volume rendering</p><h4>Volume Rendering with Radiance Fields</h4><p>NeRF doesn’t directly predict images. Instead, it simulates how light interacts with a 3D scene, using the concept of volume rendering.</p><p>Here’s the basic idea:</p><ul><li>For each image, cast a <strong>ray</strong> from the camera through every pixel.</li><li>This ray is defined as <em>r(t)</em><strong>=o+</strong><em>t</em><strong>d</strong></li></ul><p>where:</p><ul><li>o is the ray origin (camera position)</li><li>d is the ray direction (unit vector)</li><li>t is a scalar parameter that moves along the ray</li></ul><h4>Sampling Along the Ray</h4><p>To understand what the ray “sees,” we sample N points along it, between a near bound tn and a far bound tf. These bounds define the region of interest, essentially, where we expect the 3D scene to lie.</p><p>Each sampled point is r(tᵢ), for i = 1 to N</p><p>This is passed through the MLP <strong>F </strong>to obtain</p><ul><li>Volume density σᵢ: How likely the ray would “terminate” or hit matter at that location.</li><li>Color cᵢ ∈ ℝ³: The RGB value seen from the current direction.</li></ul><h4>Blending It All Together: The Volume Rendering Equation</h4><p>We want to combine all these sampled points to compute the final color C(r) of the pixel corresponding to the ray.</p><p>NeRF does this using the volume rendering equation:</p><blockquote><strong>C(r) = ∑ᵢ₌₁ⁿ Tᵢ · αᵢ · cᵢ</strong></blockquote><p>where</p><blockquote><strong>αᵢ = 1 − exp(−σᵢ · δᵢ)</strong></blockquote><blockquote>probability that the ray terminates at sample i.</blockquote><blockquote><strong>Tᵢ = ∏ⱼ₌₁ⁱ⁻¹ (1 − αⱼ)</strong></blockquote><blockquote>Accumulated transmittance, how much light reaches point i without being blocked by earlier samples.</blockquote><blockquote><strong>δᵢ = tᵢ₊₁ − tᵢ</strong></blockquote><blockquote>Distance between adjacent samples</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PVzlCZVfx70udnt0sJKckA.jpeg" /><figcaption>I have used only one MLP for simplicity I will update this next</figcaption></figure><p><strong>But wait, isn’t sampling non-differentiable?</strong></p><p>Sampling in NeRF isn’t part of the computational graph. It is just a mechanism to choose inputs (sample points) to feed into the MLP.</p><p>So even if the sampling step is not differentiable, it doesn’t matter, because:</p><ul><li>The sampled 3D coordinates are treated as inputs</li><li>The MLP is differentiable, so gradients flow through it.</li><li>Volume rendering is differentiable with respect to the outputs of the MLP (color and density)</li><li>Backpropagation never needs to “go through” the sampling logic itself.</li></ul><p><strong>This raises a deeper question…</strong></p><p><strong>If only N distinct points are sampled, how is NeRF learning to model a continuous 3D scene?</strong></p><p>The answer to this is that NeRF uses stratified sampling</p><h4>Stratified sampling</h4><p>Instead of sampling at fixed intervals, NeRF splits the ray range [tn​,tf​] into equal bins and picks <strong>one random point per bin</strong>.</p><p>This:</p><ul><li>Encourages the network to model a <strong>smooth, continuous 3D scene</strong>.</li><li>Prevents it from overfitting to fixed sample locations.</li><li>Helps the MLP generalize better by seeing slightly different positions each time.</li></ul><blockquote>Over time, this randomness ensures dense and even coverage of space, which leads to better reconstructions.</blockquote><p>So, while <strong>σ</strong> is not directly supervised, it plays a critical role in producing the final color of each pixel.</p><p>Through the volume rendering equation, <strong>σ </strong>influences how much each point contributes to the final image.</p><p>And since we compare these predicted colors with the ground truth images, the network learns to adjust both σ and RGB values indirectly, but effectively.</p><h4>We’ve uncovered how NeRF uses <strong>one MLP</strong> to map 3D positions and viewing directions into colors and densities, powered by positional encoding, stratified sampling, and volume rendering math.</h4><p>But the title says two MLPs:</p><blockquote><strong><em>“Rendering Reality with Just Two MLPs.”</em></strong></blockquote><p>So… what does the <strong>second MLP</strong> do?</p><p>In NeRF, the<strong> first MLP</strong> acts as a coarse network. It gives a rough idea of where objects might exist — like a low-resolution sketch of the scene.<br>The <strong>second MLP</strong> then takes that sketch and <strong>learns where to focus</strong>.<br> It performs hierarchical volume sampling: refining the sampling density along rays in regions where the coarse network predicts high variation — edges, reflections, fine textures, or uncertain boundaries.<br>Essentially, the second MLP “zooms in,” allocating more computation to interesting parts of the scene — much like a camera that automatically adjusts focus where detail matters most.<br> And it does all this using nothing but gradients and learned sampling probabilities — no convolutions, no attention maps.</p><p>And what about camera positions — where do they come from?</p><blockquote>That’s where <strong>COLMAP</strong>, <strong>Structure-from-Motion</strong>, and a new preprocessing pipeline step in — the unsung foundation that makes NeRF’s magic possible.</blockquote><p><strong>Part 2 drops soon: “Zooming In with Two MLPs — How NeRF Learns to Focus”</strong></p><h4>References</h4><ol><li><strong>“NeRF: Representing Scenes as Neural Radiance Fields for View Synthesis.</strong>” <em>ECCV 2020</em>. <a href="https://arxiv.org/abs/2003.08934">paper link</a></li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f25919f09e2d" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>