<div dir="ltr"><h1><span class="gmail-mw-headline" id="gmail-Week_11">Week 11</span></h1><p>Hi everyone! This is my report for the present week.
</p>
<h2><span class="gmail-mw-headline" id="gmail-Objectives">Objectives</span></h2><p>Brecht
 requested that I profile the shader to see if there were any possible 
optimizations. Also, if I could find out and fix why the shader was 
noisy in certain areas.
</p>
<h2><span class="gmail-mw-headline" id="gmail-What.27s_been_done">What's been done</span></h2><ul><li> Brecht uploaded the missing regression tests (<a rel="nofollow" class="external gmail-text" href="http://developer.blender.org/rBL62073">rBL62073</a>).</li>
<li> Apply Filter Glossy to the Roughness value (as detailed in the 
Blender manual), rather than the corresponding logistic's variance (<a rel="nofollow" class="external gmail-text" href="http://developer.blender.org/rB52a0e67fe0050683a888d6643ec2035bd2b3ea1c">rB52a0e67fe0050683a888d6643ec2035bd2b3ea1c</a>).</li>
<li> Enable mode weights. This lets you select which light mode will be 
present in the render. Not exactly useful for physically-based renders, 
but for debugging issues like noise. (<a rel="nofollow" class="external gmail-text" href="http://developer.blender.org/rB2ab98cca19cb3acd3da61b5f71a61a1139f1713e">rB2ab98cca19cb3acd3da61b5f71a61a1139f1713e</a>, <a rel="nofollow" class="external gmail-text" href="http://developer.blender.org/rB21aefa098f4935597a759e199153e9b55279ff8a">rB21aefa098f4935597a759e199153e9b55279ff8a</a>)</li></ul>
<p>I profiled the shader using nirved's Hair Curls (4 curls, 1000 hairs 
per curl, black background, lighted by a HDR sphere) and Xcode's 
Instruments. The only edit was to make <i>all</i> functions in <code>bsdf_hair_principled.h</code> <code>ccl_device</code> (ie. not inlined).
</p><p>Top ten of functions (full stacktrace as an addendum to the previous week's report in soc-2018-dev):
</p>
<pre>9.11 min   32.6%    9.11 min         ccl::QBVH_bvh_intersect_shadow_all_hair(ccl::KernelGlobals*, ccl::Ray const*, ccl::Intersection*, unsigned int, unsigned int, unsigned int*)
6.28 min   22.5%    6.28 min         ccl::QBVH_bvh_intersect_hair(ccl::KernelGlobals*, ccl::Ray const*, ccl::Intersection*, unsigned int, unsigned int*, float, float)
56.99 s    3.4% 56.99 s      ccl::BVHObjectBinning::BVHObjectBinning(ccl::BVHRange const&, ccl::BVHReference*, ccl::BVHUnaligned const*, ccl::Transform const*)
48.82 s    2.9% 48.82 s      ccl::kernel_branched_path_trace(ccl::KernelGlobals*, float*, int, int, int, int, int)
36.48 s    2.1% 36.48 s      ccl::camera_sample_perspective(ccl::KernelGlobals*, float, float, float, float, ccl::Ray*)
29.71 s    1.7% 29.71 s      ccl::kernel_branched_path_integrate(ccl::KernelGlobals*, unsigned int, int, ccl::Ray, float*, ccl::PathRadiance*)
29.22 s    1.7% 29.22 s      ccl::bsdf_principled_hair_eval(ccl::KernelGlobals*, ccl::ShaderData const*, ccl::ShaderClosure const*, ccl::float3, float*)
21.94 s    1.3% 21.94 s      ccl::kernel_tex_image_interp(ccl::KernelGlobals*, int, float, float)
21.39 s    1.2% 21.39 s      ccl::svm_eval_nodes(ccl::KernelGlobals*, ccl::ShaderData*, ccl::PathState*, ccl::ShaderType, int)
20.40 s    1.2% 20.40 s      ccl::svm_node_mapping(ccl::KernelGlobals*, ccl::ShaderData*, float*, unsigned int, unsigned int, int*)
</pre>
<p>Even though <code>bsdf_principled_hair_eval</code> appears (as 
expected, since it's pretty heavy in calculations), the overwhelming 
majority of CPU time goes to the BVH intersection calculation for hair, 
so I deemed this to be sufficiently optimized.
</p><p>As regards noise, I could only find out where it happens and in 
which illumination conditions, not the actual source (code) of the 
noise.
</p>
<div class="gmail-center"><div class="gmail-thumb gmail-tnone"><div class="gmail-thumbinner" style="width:502px"><a href="https://wiki.blender.org/wiki/File:Hair-Curls-noise.png" class="gmail-image"><img alt="" src="https://wiki.blender.org/w/images/thumb/8/8c/Hair-Curls-noise.png/500px-Hair-Curls-noise.png" class="gmail-thumbimage" width="500" height="92"></a>  <div class="gmail-thumbcaption"><div class="gmail-magnify"></div></div></div></div></div><div class="gmail-center"><div class="gmail-thumb gmail-tnone"><div class="gmail-thumbinner" style="width:502px"><div class="gmail-thumbcaption">Transparent
 render of nirved's Hair Curls. From left to right: full render, only 
primary specular (R), only transmission (TT), only secondary specular 
(TRT), only residual (TRRT+). Noise is most prevalent at the extrema of 
the curl (which is away from the light).</div></div></div></div>
<ul><li> Noise is most visible in the penumbra of the hair (places away 
from the glint), but separating the light passes (below) shows it 
affects the whole length of the hair.</li>
<li> It arises in the Gloss Ind (i.e. indirect glossy) pass of the renderer, which AFAIK points to light reflection between hairs.</li></ul>
<div class="gmail-center"><div class="gmail-thumb gmail-tnone"><div class="gmail-thumbinner" style="width:502px"><a href="https://wiki.blender.org/wiki/File:Hair-Curls-noise.glossind.png" class="gmail-image"><img alt="" src="https://wiki.blender.org/w/images/thumb/d/d9/Hair-Curls-noise.glossind.png/500px-Hair-Curls-noise.glossind.png" class="gmail-thumbimage" width="500" height="92"></a>  <div class="gmail-thumbcaption"><div class="gmail-magnify"></div></div></div></div></div><div class="gmail-center"><div class="gmail-thumb gmail-tnone"><div class="gmail-thumbinner" style="width:502px"><div class="gmail-thumbcaption">Indirect Glossy pass of nirved's Hair Curls. Noise is present throughout the hair length.</div></div></div></div>
<ul><li> It only affects the TT mode, which is consistent with the 
observations since it alters the coloring of the render. Rendering 
separate layers for each mode shows the rest are unaffected.</li></ul>
<h2><span class="gmail-mw-headline" id="gmail-Next_up">Next up</span></h2><ul><li> Nothing yet, I'll wait to hear back from Lukas/Brecht to see if they have any more ideas/advice for debugging the noise issue.</li></ul>
<h2><span class="gmail-mw-headline" id="gmail-Questions">Questions</span></h2>None this time.
<br><br>-- <br>Lic. Leonardo E. Segovia<br>Departamento de Ciencias e Ingeniería de la Computación<br>Universidad Nacional del Sur<br>San Andrés 800 - Campus Palihue, B8000 Bahía Blanca, Argentina</div>